From 220843fb6a0c3f9523b1f20a2b30ea104dba55ad Mon Sep 17 00:00:00 2001 From: detworam Date: Wed, 24 May 2017 13:09:37 -0400 Subject: [PATCH] add ability to set block size --- buse.c | 15 +++++++++++++-- buse.h | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/buse.c b/buse.c index 5fada2e..4d52fe3 100644 --- a/buse.c +++ b/buse.c @@ -103,8 +103,19 @@ int buse_main(const char* dev_file, const struct buse_operations *aop, void *use return 1; } - err = ioctl(nbd, NBD_SET_SIZE, aop->size); - assert(err != -1); + if (aop->blksize) { + err = ioctl(nbd, NBD_SET_BLKSIZE, aop->blksize); + assert(err != -1); + } + if (aop->size) { + err = ioctl(nbd, NBD_SET_SIZE, aop->size); + assert(err != -1); + } + if (aop->size_blocks) { + err = ioctl(nbd, NBD_SET_SIZE_BLOCKS, aop->size_blocks); + assert(err != -1); + } + err = ioctl(nbd, NBD_CLEAR_SOCK); assert(err != -1); diff --git a/buse.h b/buse.h index 4cedf1b..c3d379c 100644 --- a/buse.h +++ b/buse.h @@ -17,7 +17,10 @@ extern "C" { int (*flush)(void *userdata); int (*trim)(u_int64_t from, u_int32_t len, void *userdata); + // either set size, OR set both blksize and size_blocks u_int64_t size; + u_int32_t blksize; + u_int64_t size_blocks; }; int buse_main(const char* dev_file, const struct buse_operations *bop, void *userdata);