diff --git a/.gitignore b/.gitignore index 37c4bdd..8a11972 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.swp *.o -*.so +*.a busexmp diff --git a/Makefile b/Makefile index 62fc62e..8eb3ffb 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/buse.c b/buse.c index e647371..f1e4a66 100644 --- a/buse.c +++ b/buse.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -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); diff --git a/buse.h b/buse.h index bcf792e..7c84848 100644 --- a/buse.h +++ b/buse.h @@ -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 */ diff --git a/busexmp.c b/busexmp.c index 3f8f5ef..92b4157 100644 --- a/busexmp.c +++ b/busexmp.c @@ -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[])