Various changes:

* Changed the Makefile to do static linking instead of dynamic.
 * Fixed a bug in buse.c where I was passing &chunk instead of just chunk.
 * Changed busexmp.c to correctly act as an in-memory disk instead of just
   returning zeros.
 * Other miscellaneous stuff
This commit is contained in:
Adam Cozzette 2011-11-15 14:44:38 -08:00
parent 3426987066
commit 28eb460f25
5 changed files with 16 additions and 16 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
*.swp
*.o
*.so
*.a
busexmp

View File

@ -1,26 +1,26 @@
TARGET := busexmp
LIBOBJS := buse.o
OBJS := $(TARGET:=.o) $(LIBOBJS)
SHAREDLIB := libbuse.so
STATIC_LIB := libbuse.a
CC := /usr/bin/gcc
CFLAGS := -g -pedantic -Wall -Wextra -std=c99 -I$(HOME)/src/nbd
LDFLAGS := -lbuse -L.
LDFLAGS := -L. -lbuse
.PHONY: all clean
all: $(TARGET)
$(TARGET): %: %.o lib
$(CC) $(LDFLAGS) -o $@ $<
$(TARGET): %: %.o $(STATIC_LIB)
$(CC) -o $@ $< $(LDFLAGS)
$(TARGET:=.o): %.o: %.c buse.h
$(CC) $(CFLAGS) -o $@ -c $<
lib: $(LIBOBJS)
$(CC) -shared -fPIC -o $(SHAREDLIB) $^
$(STATIC_LIB): $(LIBOBJS)
ar rcu $(STATIC_LIB) $(LIBOBJS)
$(LIBOBJS): %.o: %.c
$(CC) $(CFLAGS) -fPIC -o $@ -c $<
$(CC) $(CFLAGS) -o $@ -c $<
clean:
rm -f $(TARGET) $(OBJS) $(SHAREDLIB)
rm -f $(TARGET) $(OBJS) $(STATIC_LIB)

6
buse.c
View File

@ -1,4 +1,5 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/types.h>
#include <nbd.h>
@ -100,17 +101,18 @@ int buse_main(int argc, char *argv[], const struct buse_operations *aop, void *u
* and writes.
*/
case NBD_CMD_READ:
fprintf(stderr, "Request for read of size %d\n", len);
chunk = malloc(len + sizeof(struct nbd_reply));
aop->read((char *)chunk + sizeof(struct nbd_reply), len, from);
memcpy(chunk, &reply, sizeof(struct nbd_reply));
bytes_written = write(sk, chunk, len + sizeof(struct nbd_reply));
assert(bytes_written == len + sizeof(struct nbd_reply));
fprintf(stderr, "Wrote %d bytes.\n", bytes_written);
free(chunk);
break;
case NBD_CMD_WRITE:
fprintf(stderr, "Request for write of size %d\n", len);
chunk = malloc(len);
bytes_read = read(sk, &chunk, len);
bytes_read = read(sk, chunk, len);
assert(bytes_read == len);
aop->write(chunk, len, from);
free(chunk);

2
buse.h
View File

@ -13,7 +13,7 @@ struct buse_operations {
u_int64_t size;
};
int buse_main(int argc, char *argv[], const struct buse_operations *aop,
int buse_main(int argc, char *argv[], const struct buse_operations *bop,
void *userdata);
#endif /* BUSE_H_INCLUDED */

View File

@ -7,9 +7,7 @@ static void *data;
static int xmp_read(void *buf, u_int32_t len, u_int64_t offset)
{
/* memcpy(buf, (char *)data + offset, len); */
memset(buf, 0, len);
memcpy(buf, (char *)data + offset, len);
return 0;
}
@ -22,7 +20,7 @@ static int xmp_write(const void *buf, u_int32_t len, u_int64_t offset)
static struct buse_operations aop = {
.read = xmp_read,
.write = xmp_write,
.size = 128 * 1024 * 1024,
.size = 128 * 1024,
};
int main(int argc, char *argv[])