summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/loop.c14
1 files changed, 12 insertions, 2 deletions
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
104 104
105 /* Find a loop device. */ 105 /* Find a loop device. */
106 try = *device ? *device : dev; 106 try = *device ? *device : dev;
107 for (i = 0; rc; i++) { 107 for (i = 0; rc && i < 256; i++) {
108 sprintf(dev, LOOP_FORMAT, i); 108 sprintf(dev, LOOP_FORMAT, i);
109 109
110 /* Ran out of block devices, return failure. */ 110 IF_FEATURE_MOUNT_LOOP_CREATE(errno = 0;)
111 if (stat(try, &statbuf) != 0 || !S_ISBLK(statbuf.st_mode)) { 111 if (stat(try, &statbuf) != 0 || !S_ISBLK(statbuf.st_mode)) {
112 if (ENABLE_FEATURE_MOUNT_LOOP_CREATE
113 && errno == ENOENT
114 && try == dev
115 ) {
116 /* Node doesn't exist, try to create it. */
117 if (mknod(dev, S_IFBLK|0644, makedev(7, i)) == 0)
118 goto try_to_open;
119 }
120 /* Ran out of block devices, return failure. */
112 rc = -ENOENT; 121 rc = -ENOENT;
113 break; 122 break;
114 } 123 }
124 try_to_open:
115 /* Open the sucker and check its loopiness. */ 125 /* Open the sucker and check its loopiness. */
116 dfd = open(try, mode); 126 dfd = open(try, mode);
117 if (dfd < 0 && errno == EROFS) { 127 if (dfd < 0 && errno == EROFS) {