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 *.swp
*.o *.o
*.so *.a
busexmp busexmp

View File

@ -1,26 +1,26 @@
TARGET := busexmp TARGET := busexmp
LIBOBJS := buse.o LIBOBJS := buse.o
OBJS := $(TARGET:=.o) $(LIBOBJS) OBJS := $(TARGET:=.o) $(LIBOBJS)
SHAREDLIB := libbuse.so STATIC_LIB := libbuse.a
CC := /usr/bin/gcc CC := /usr/bin/gcc
CFLAGS := -g -pedantic -Wall -Wextra -std=c99 -I$(HOME)/src/nbd CFLAGS := -g -pedantic -Wall -Wextra -std=c99 -I$(HOME)/src/nbd
LDFLAGS := -lbuse -L. LDFLAGS := -L. -lbuse
.PHONY: all clean .PHONY: all clean
all: $(TARGET) all: $(TARGET)
$(TARGET): %: %.o lib $(TARGET): %: %.o $(STATIC_LIB)
$(CC) $(LDFLAGS) -o $@ $< $(CC) -o $@ $< $(LDFLAGS)
$(TARGET:=.o): %.o: %.c buse.h $(TARGET:=.o): %.o: %.c buse.h
$(CC) $(CFLAGS) -o $@ -c $< $(CC) $(CFLAGS) -o $@ -c $<
lib: $(LIBOBJS) $(STATIC_LIB): $(LIBOBJS)
$(CC) -shared -fPIC -o $(SHAREDLIB) $^ ar rcu $(STATIC_LIB) $(LIBOBJS)
$(LIBOBJS): %.o: %.c $(LIBOBJS): %.o: %.c
$(CC) $(CFLAGS) -fPIC -o $@ -c $< $(CC) $(CFLAGS) -o $@ -c $<
clean: 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 <assert.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/types.h> #include <linux/types.h>
#include <nbd.h> #include <nbd.h>
@ -100,17 +101,18 @@ int buse_main(int argc, char *argv[], const struct buse_operations *aop, void *u
* and writes. * and writes.
*/ */
case NBD_CMD_READ: case NBD_CMD_READ:
fprintf(stderr, "Request for read of size %d\n", len);
chunk = malloc(len + sizeof(struct nbd_reply)); chunk = malloc(len + sizeof(struct nbd_reply));
aop->read((char *)chunk + sizeof(struct nbd_reply), len, from); aop->read((char *)chunk + sizeof(struct nbd_reply), len, from);
memcpy(chunk, &reply, sizeof(struct nbd_reply)); memcpy(chunk, &reply, sizeof(struct nbd_reply));
bytes_written = write(sk, chunk, len + sizeof(struct nbd_reply)); bytes_written = write(sk, chunk, len + sizeof(struct nbd_reply));
assert(bytes_written == len + sizeof(struct nbd_reply)); assert(bytes_written == len + sizeof(struct nbd_reply));
fprintf(stderr, "Wrote %d bytes.\n", bytes_written);
free(chunk); free(chunk);
break; break;
case NBD_CMD_WRITE: case NBD_CMD_WRITE:
fprintf(stderr, "Request for write of size %d\n", len);
chunk = malloc(len); chunk = malloc(len);
bytes_read = read(sk, &chunk, len); bytes_read = read(sk, chunk, len);
assert(bytes_read == len); assert(bytes_read == len);
aop->write(chunk, len, from); aop->write(chunk, len, from);
free(chunk); free(chunk);

2
buse.h
View File

@ -13,7 +13,7 @@ struct buse_operations {
u_int64_t size; 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); void *userdata);
#endif /* BUSE_H_INCLUDED */ #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) static int xmp_read(void *buf, u_int32_t len, u_int64_t offset)
{ {
/* memcpy(buf, (char *)data + offset, len); */ memcpy(buf, (char *)data + offset, len);
memset(buf, 0, len);
return 0; 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 = { static struct buse_operations aop = {
.read = xmp_read, .read = xmp_read,
.write = xmp_write, .write = xmp_write,
.size = 128 * 1024 * 1024, .size = 128 * 1024,
}; };
int main(int argc, char *argv[]) int main(int argc, char *argv[])