diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-19 00:39:17 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-19 00:39:17 +0200 |
commit | 92510141e24251a1d72fbdeef4e2ed2b2b25b433 (patch) | |
tree | 16ed5ab37f2bcf1500514ab4e08a4672405c8ce3 /util-linux | |
parent | 42c4b2e3b535314ae8a7b65c3223afb26872d5a2 (diff) | |
download | busybox-w32-92510141e24251a1d72fbdeef4e2ed2b2b25b433.tar.gz busybox-w32-92510141e24251a1d72fbdeef4e2ed2b2b25b433.tar.bz2 busybox-w32-92510141e24251a1d72fbdeef4e2ed2b2b25b433.zip |
losetup: support /dev/loop10 and higher. closes bug 1627
function old new delta
query_loop 91 95 +4
losetup_main 288 285 -3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/losetup.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/util-linux/losetup.c b/util-linux/losetup.c index e224a4d54..e44773a07 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c | |||
@@ -10,44 +10,48 @@ | |||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 12 | int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
13 | int losetup_main(int argc, char **argv) | 13 | int losetup_main(int argc UNUSED_PARAM, char **argv) |
14 | { | 14 | { |
15 | char dev[] = LOOP_NAME"0"; | ||
16 | unsigned opt; | 15 | unsigned opt; |
16 | int n; | ||
17 | char *opt_o; | 17 | char *opt_o; |
18 | char *s; | ||
19 | unsigned long long offset = 0; | 18 | unsigned long long offset = 0; |
19 | enum { | ||
20 | OPT_d = (1 << 0), | ||
21 | OPT_o = (1 << 1), | ||
22 | OPT_f = (1 << 2), | ||
23 | }; | ||
20 | 24 | ||
21 | /* max 2 args, all opts are mutually exclusive */ | 25 | /* max 2 args, all opts are mutually exclusive */ |
22 | opt_complementary = "?2:d--of:o--df:f-do"; | 26 | opt_complementary = "?2:d--of:o--df:f-do"; |
23 | opt = getopt32(argv, "do:f", &opt_o); | 27 | opt = getopt32(argv, "do:f", &opt_o); |
24 | argc -= optind; | ||
25 | argv += optind; | 28 | argv += optind; |
26 | 29 | ||
27 | if (opt == 0x2) // -o | 30 | if (opt == OPT_o) |
28 | offset = xatoull(opt_o); | 31 | offset = xatoull(opt_o); |
29 | 32 | ||
30 | if (opt == 0x4 && argc) // -f does not take any argument | 33 | if (opt == OPT_d) { |
31 | bb_show_usage(); | 34 | /* -d BLOCKDEV */ |
32 | 35 | if (!argv[0] || argv[1]) | |
33 | if (opt == 0x1) { // -d | ||
34 | /* detach takes exactly one argument */ | ||
35 | if (argc != 1) | ||
36 | bb_show_usage(); | 36 | bb_show_usage(); |
37 | if (del_loop(argv[0])) | 37 | if (del_loop(argv[0])) |
38 | bb_simple_perror_msg_and_die(argv[0]); | 38 | bb_simple_perror_msg_and_die(argv[0]); |
39 | return EXIT_SUCCESS; | 39 | return EXIT_SUCCESS; |
40 | } | 40 | } |
41 | 41 | ||
42 | if (argc == 2) { | 42 | if (argv[0]) { |
43 | /* -o or no option */ | 43 | char *s; |
44 | if (set_loop(&argv[0], argv[1], offset) < 0) | 44 | |
45 | bb_simple_perror_msg_and_die(argv[0]); | 45 | if (opt == OPT_f) /* -f should not have arguments */ |
46 | return EXIT_SUCCESS; | 46 | bb_show_usage(); |
47 | } | ||
48 | 47 | ||
49 | if (argc == 1) { | 48 | if (argv[1]) { |
50 | /* -o or no option */ | 49 | /* [-o OFS] BLOCKDEV FILE */ |
50 | if (set_loop(&argv[0], argv[1], offset) < 0) | ||
51 | bb_simple_perror_msg_and_die(argv[0]); | ||
52 | return EXIT_SUCCESS; | ||
53 | } | ||
54 | /* [-o OFS] BLOCKDEV */ | ||
51 | s = query_loop(argv[0]); | 55 | s = query_loop(argv[0]); |
52 | if (!s) | 56 | if (!s) |
53 | bb_simple_perror_msg_and_die(argv[0]); | 57 | bb_simple_perror_msg_and_die(argv[0]); |
@@ -57,23 +61,28 @@ int losetup_main(int argc, char **argv) | |||
57 | return EXIT_SUCCESS; | 61 | return EXIT_SUCCESS; |
58 | } | 62 | } |
59 | 63 | ||
60 | /* -o, -f or no option */ | 64 | /* [-o OFS|-f] with no params */ |
65 | n = 0; | ||
61 | while (1) { | 66 | while (1) { |
67 | char *s; | ||
68 | char dev[sizeof(LOOP_NAME) + sizeof(int)*3]; | ||
69 | |||
70 | sprintf(dev, LOOP_NAME"%u", n); | ||
62 | s = query_loop(dev); | 71 | s = query_loop(dev); |
72 | n++; | ||
63 | if (!s) { | 73 | if (!s) { |
64 | if (opt == 0x4) { | 74 | if (n > 9 && errno && errno != ENXIO) |
75 | return EXIT_SUCCESS; | ||
76 | if (opt == OPT_f) { | ||
65 | puts(dev); | 77 | puts(dev); |
66 | return EXIT_SUCCESS; | 78 | return EXIT_SUCCESS; |
67 | } | 79 | } |
68 | } else { | 80 | } else { |
69 | if (opt != 0x4) | 81 | if (opt != OPT_f) |
70 | printf("%s: %s\n", dev, s); | 82 | printf("%s: %s\n", dev, s); |
71 | if (ENABLE_FEATURE_CLEAN_UP) | 83 | if (ENABLE_FEATURE_CLEAN_UP) |
72 | free(s); | 84 | free(s); |
73 | } | 85 | } |
74 | |||
75 | if (++dev[sizeof(dev) - 2] > '9') | ||
76 | break; | ||
77 | } | 86 | } |
78 | return EXIT_SUCCESS; | 87 | return EXIT_SUCCESS; |
79 | } | 88 | } |