mirror of
https://github.com/sheumann/hush.git
synced 2024-12-23 05:29:58 +00:00
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>
This commit is contained in:
parent
3b394781b5
commit
fa6ab56353
18
libbb/loop.c
18
libbb/loop.c
@ -94,19 +94,19 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
|
||||
|
||||
/* Open the file. Barf if this doesn't work. */
|
||||
mode = ro ? O_RDONLY : O_RDWR;
|
||||
open_ffd:
|
||||
ffd = open(file, mode);
|
||||
if (ffd < 0) {
|
||||
if (mode != O_RDONLY) {
|
||||
mode = O_RDONLY;
|
||||
ffd = open(file, mode);
|
||||
goto open_ffd;
|
||||
}
|
||||
if (ffd < 0)
|
||||
return -errno;
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* Find a loop device. */
|
||||
try = *device ? *device : dev;
|
||||
/* 1048575 is a max possible minor number in Linux circa 2010 */
|
||||
/* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */
|
||||
for (i = 0; rc && i < 1048576; i++) {
|
||||
sprintf(dev, LOOP_FORMAT, i);
|
||||
|
||||
@ -121,7 +121,7 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
|
||||
goto try_to_open;
|
||||
}
|
||||
/* Ran out of block devices, return failure. */
|
||||
rc = -ENOENT;
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
try_to_open:
|
||||
@ -131,8 +131,14 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
|
||||
mode = O_RDONLY;
|
||||
dfd = open(try, mode);
|
||||
}
|
||||
if (dfd < 0)
|
||||
if (dfd < 0) {
|
||||
if (errno == ENXIO) {
|
||||
/* Happens if loop module is not loaded */
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
goto try_again;
|
||||
}
|
||||
|
||||
rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user