From 0b2d3e5052b74d55a09a133e960d2730ed488e1b Mon Sep 17 00:00:00 2001 From: Vladimir Rutsky Date: Mon, 1 Feb 2016 00:08:43 +0300 Subject: [PATCH 1/2] handle typical permission denied error in user friendly way This is the first (and the only) error that will occur if user will try to access /dev/nbd0 without proper permissions. --- buse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/buse.c b/buse.c index 69039b7..24c8916 100644 --- a/buse.c +++ b/buse.c @@ -94,7 +94,13 @@ int buse_main(const char* dev_file, const struct buse_operations *aop, void *use assert(!socketpair(AF_UNIX, SOCK_STREAM, 0, sp)); nbd = open(dev_file, O_RDWR); - assert(nbd != -1); + if (nbd == -1) { + fprintf(stderr, + "Failed to open `%s': %s\n" + "Is kernel module `nbd' is loaded and you have permissions " + "to access the device?\n", dev_file, strerror(errno)); + return 1; + } assert(ioctl(nbd, NBD_SET_SIZE, aop->size) != -1); assert(ioctl(nbd, NBD_CLEAR_SOCK) != -1); From 198ffee1cb7670b3d3ef1abde8c17d7968a682a2 Mon Sep 17 00:00:00 2001 From: Vladimir Rutsky Date: Mon, 1 Feb 2016 00:17:11 +0300 Subject: [PATCH 2/2] add help message to busexmp example --- busexmp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/busexmp.c b/busexmp.c index 5464902..d342a6e 100644 --- a/busexmp.c +++ b/busexmp.c @@ -74,7 +74,16 @@ static struct buse_operations aop = { int main(int argc, char *argv[]) { - (void)(argc); + if (argc != 2) + { + fprintf(stderr, + "Usage:\n" + " %s /dev/nbd0\n" + "Don't forget to load nbd kernel module (`modprobe nbd`) and\n" + "run example from root.\n", argv[0]); + return 1; + } + data = malloc(aop.size); return buse_main(argv[1], &aop, (void *)&xmpl_debug);