diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-26 17:54:18 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-26 17:54:18 +0000 |
commit | 7ae209c0190c0c6e6b1c95ee9005edf4729e1ce0 (patch) | |
tree | 39924a81fa6fa6d7ab2ee7246ce24285078e8ae2 /util-linux | |
parent | 137fbe495d3922b71490d01083f04331eb0e6671 (diff) | |
download | busybox-w32-7ae209c0190c0c6e6b1c95ee9005edf4729e1ce0.tar.gz busybox-w32-7ae209c0190c0c6e6b1c95ee9005edf4729e1ce0.tar.bz2 busybox-w32-7ae209c0190c0c6e6b1c95ee9005edf4729e1ce0.zip |
losetup: support -f (Loic Grenie <loic.grenie@gmail.com>)
function old new delta
losetup_main 238 278 +40
packed_usage 23021 23027 +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 46/0) Total: 46 bytes
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/losetup.c | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/util-linux/losetup.c b/util-linux/losetup.c index 9409cdff5..57e8569dc 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c | |||
@@ -14,54 +14,68 @@ | |||
14 | int losetup_main(int argc, char **argv); | 14 | int losetup_main(int argc, char **argv); |
15 | int losetup_main(int argc, char **argv) | 15 | int losetup_main(int argc, char **argv) |
16 | { | 16 | { |
17 | char dev[] = LOOP_NAME"0"; | ||
17 | unsigned opt; | 18 | unsigned opt; |
18 | char *opt_o; | 19 | char *opt_o; |
20 | char *s; | ||
19 | unsigned long long offset = 0; | 21 | unsigned long long offset = 0; |
20 | 22 | ||
21 | opt = getopt32(argv, "do:", &opt_o); | 23 | /* max 2 args, all opts are mutially exclusive */ |
24 | opt_complementary = "?2:d--of:o--df:f-do"; | ||
25 | opt = getopt32(argv, "do:f", &opt_o); | ||
22 | argc -= optind; | 26 | argc -= optind; |
23 | argv += optind; | 27 | argv += optind; |
24 | 28 | ||
25 | if (opt == 0x3) // -d + -o (illegal) | 29 | if (opt == 0x2) // -o |
30 | offset = xatoull(opt_o); | ||
31 | |||
32 | if (opt == 0x4 && argc) // -f does not take any argument | ||
26 | bb_show_usage(); | 33 | bb_show_usage(); |
27 | 34 | ||
28 | if (opt == 0x1) { // -d | 35 | if (opt == 0x1) { // -d |
29 | /* detach takes exactly one argument */ | 36 | /* detach takes exactly one argument */ |
30 | if (argc != 1) | 37 | if (argc != 1) |
31 | bb_show_usage(); | 38 | bb_show_usage(); |
32 | if (!del_loop(argv[0])) | 39 | if (del_loop(argv[0])) |
33 | return EXIT_SUCCESS; | 40 | bb_perror_nomsg_and_die(); |
34 | bb_perror_nomsg_and_die(); | 41 | return EXIT_SUCCESS; |
35 | } | 42 | } |
36 | 43 | ||
37 | if (opt == 0x2) // -o | ||
38 | offset = xatoull(opt_o); | ||
39 | |||
40 | /* -o or no option */ | ||
41 | |||
42 | if (argc == 2) { | 44 | if (argc == 2) { |
45 | /* -o or no option */ | ||
43 | if (set_loop(&argv[0], argv[1], offset) < 0) | 46 | if (set_loop(&argv[0], argv[1], offset) < 0) |
44 | bb_perror_nomsg_and_die(); | 47 | bb_perror_nomsg_and_die(); |
45 | } else if (argc == 1) { | 48 | return EXIT_SUCCESS; |
46 | char *s = query_loop(argv[0]); | 49 | } |
50 | |||
51 | if (argc == 1) { | ||
52 | /* -o or no option */ | ||
53 | s = query_loop(argv[0]); | ||
47 | if (!s) | 54 | if (!s) |
48 | bb_perror_nomsg_and_die(); | 55 | bb_perror_nomsg_and_die(); |
49 | printf("%s: %s\n", argv[0], s); | 56 | printf("%s: %s\n", argv[0], s); |
50 | if (ENABLE_FEATURE_CLEAN_UP) | 57 | if (ENABLE_FEATURE_CLEAN_UP) |
51 | free(s); | 58 | free(s); |
52 | } else { | 59 | return EXIT_SUCCESS; |
53 | char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0"; | 60 | } |
54 | char c; | 61 | |
55 | for (c = '0'; c <= '9'; ++c) { | 62 | /* -o, -f or no option */ |
56 | char *s; | 63 | while (1) { |
57 | dev[sizeof(LOOP_NAME"0")-2] = c; | 64 | s = query_loop(dev); |
58 | s = query_loop(dev); | 65 | if (!s) { |
59 | if (s) { | 66 | if (opt == 0x4) { |
60 | printf("%s: %s\n", dev, s); | 67 | printf("%s\n", dev); |
61 | if (ENABLE_FEATURE_CLEAN_UP) | 68 | return EXIT_SUCCESS; |
62 | free(s); | ||
63 | } | 69 | } |
70 | } else { | ||
71 | if (opt != 0x4) | ||
72 | printf("%s: %s\n", dev, s); | ||
73 | if (ENABLE_FEATURE_CLEAN_UP) | ||
74 | free(s); | ||
64 | } | 75 | } |
76 | |||
77 | if (++dev[sizeof(dev) - 2] > '9') | ||
78 | break; | ||
65 | } | 79 | } |
66 | return EXIT_SUCCESS; | 80 | return EXIT_SUCCESS; |
67 | } | 81 | } |