diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-01-21 13:44:21 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-01-21 13:44:21 +0100 |
commit | fa6ab56353e84057bf1b2f740bc1e1a99af686ce (patch) | |
tree | a3230ebf679913d457c2b09a1fc1c114124381b3 | |
parent | 3b394781b5b9301fc489d9bfff6fbefb4db190f3 (diff) | |
download | busybox-w32-fa6ab56353e84057bf1b2f740bc1e1a99af686ce.tar.gz busybox-w32-fa6ab56353e84057bf1b2f740bc1e1a99af686ce.tar.bz2 busybox-w32-fa6ab56353e84057bf1b2f740bc1e1a99af686ce.zip |
libbb: if opening /dev/loopN returns ENXIO, don't try N++.
function old new delta
set_loop 639 635 -4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/loop.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libbb/loop.c b/libbb/loop.c index 823fba079..c96c5e070 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
@@ -94,19 +94,19 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
94 | 94 | ||
95 | /* Open the file. Barf if this doesn't work. */ | 95 | /* Open the file. Barf if this doesn't work. */ |
96 | mode = ro ? O_RDONLY : O_RDWR; | 96 | mode = ro ? O_RDONLY : O_RDWR; |
97 | open_ffd: | ||
97 | ffd = open(file, mode); | 98 | ffd = open(file, mode); |
98 | if (ffd < 0) { | 99 | if (ffd < 0) { |
99 | if (mode != O_RDONLY) { | 100 | if (mode != O_RDONLY) { |
100 | mode = O_RDONLY; | 101 | mode = O_RDONLY; |
101 | ffd = open(file, mode); | 102 | goto open_ffd; |
102 | } | 103 | } |
103 | if (ffd < 0) | 104 | return -errno; |
104 | return -errno; | ||
105 | } | 105 | } |
106 | 106 | ||
107 | /* Find a loop device. */ | 107 | /* Find a loop device. */ |
108 | try = *device ? *device : dev; | 108 | try = *device ? *device : dev; |
109 | /* 1048575 is a max possible minor number in Linux circa 2010 */ | 109 | /* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */ |
110 | for (i = 0; rc && i < 1048576; i++) { | 110 | for (i = 0; rc && i < 1048576; i++) { |
111 | sprintf(dev, LOOP_FORMAT, i); | 111 | sprintf(dev, LOOP_FORMAT, i); |
112 | 112 | ||
@@ -121,7 +121,7 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
121 | goto try_to_open; | 121 | goto try_to_open; |
122 | } | 122 | } |
123 | /* Ran out of block devices, return failure. */ | 123 | /* Ran out of block devices, return failure. */ |
124 | rc = -ENOENT; | 124 | rc = -1; |
125 | break; | 125 | break; |
126 | } | 126 | } |
127 | try_to_open: | 127 | try_to_open: |
@@ -131,8 +131,14 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
131 | mode = O_RDONLY; | 131 | mode = O_RDONLY; |
132 | dfd = open(try, mode); | 132 | dfd = open(try, mode); |
133 | } | 133 | } |
134 | if (dfd < 0) | 134 | if (dfd < 0) { |
135 | if (errno == ENXIO) { | ||
136 | /* Happens if loop module is not loaded */ | ||
137 | rc = -1; | ||
138 | break; | ||
139 | } | ||
135 | goto try_again; | 140 | goto try_again; |
141 | } | ||
136 | 142 | ||
137 | rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); | 143 | rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo); |
138 | 144 | ||