From 375a8ef5ea38ea10134c125c75a12bbf9d5ba7bd Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Wed, 14 Apr 2010 12:31:26 -0700 Subject: mount: add an optional capability to create new /dev/loopN as needed Signed-off-by: Lauri Kasanen Signed-off-by: Denys Vlasenko --- libbb/loop.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'libbb/loop.c') diff --git a/libbb/loop.c b/libbb/loop.c index abf05dc4f..204fcc982 100644 --- a/libbb/loop.c +++ b/libbb/loop.c @@ -104,14 +104,24 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse /* Find a loop device. */ try = *device ? *device : dev; - for (i = 0; rc; i++) { + for (i = 0; rc && i < 256; i++) { sprintf(dev, LOOP_FORMAT, i); - /* Ran out of block devices, return failure. */ + IF_FEATURE_MOUNT_LOOP_CREATE(errno = 0;) if (stat(try, &statbuf) != 0 || !S_ISBLK(statbuf.st_mode)) { + if (ENABLE_FEATURE_MOUNT_LOOP_CREATE + && errno == ENOENT + && try == dev + ) { + /* Node doesn't exist, try to create it. */ + if (mknod(dev, S_IFBLK|0644, makedev(7, i)) == 0) + goto try_to_open; + } + /* Ran out of block devices, return failure. */ rc = -ENOENT; break; } + try_to_open: /* Open the sucker and check its loopiness. */ dfd = open(try, mode); if (dfd < 0 && errno == EROFS) { -- cgit v1.2.3