mount,losetup: use /dev/loop-control is it exists

function                                             old     new   delta
get_free_loop                                          -      58     +58
set_loop                                             597     649     +52
losetup_main                                         482     476      -6
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 110/-6)            Total: 104 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2019-06-09 23:20:49 +02:00
parent 7b6d4f50c9
commit 3b69ba799f
3 changed files with 47 additions and 10 deletions

View File

@@ -114,8 +114,14 @@ int losetup_main(int argc UNUSED_PARAM, char **argv)
/* contains -f */
if (opt & OPT_f) {
char *s;
int n = 0;
int n;
n = get_free_loop();
if (n == -1)
bb_error_msg_and_die("no free loop devices");
if (n < 0) /* n == -2: no /dev/loop-control, use legacy method */
n = 0;
/* or: n >= 0: the number of next free loopdev, just verify it */
do {
if (n > MAX_LOOP_NUM)
bb_error_msg_and_die("no free loop devices");