Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/losetup.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/util-linux/losetup.c
r1765 r2725 5 5 * Copyright (C) 2002 Matt Kraai. 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 10 #include <getopt.h>11 9 12 10 #include "libbb.h" 13 11 14 int losetup_main(int argc, char **argv) ;15 int losetup_main(int argc , char **argv)12 int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 13 int losetup_main(int argc UNUSED_PARAM, char **argv) 16 14 { 17 15 unsigned opt; 16 int n; 18 17 char *opt_o; 19 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 opt = getopt32(argv, "do:", &opt_o); 22 argc -= optind; 25 /* max 2 args, all opts are mutually exclusive */ 26 opt_complementary = "?2:d--of:o--df:f--do"; 27 opt = getopt32(argv, "do:f", &opt_o); 23 28 argv += optind; 24 29 25 if (opt == 0x3) // -d + -o (illegal)26 bb_show_usage();30 if (opt == OPT_o) 31 offset = xatoull(opt_o); 27 32 28 if (opt == 0x1) { // -d29 /* detach takes exactly one argument*/30 if ( argc != 1)33 if (opt == OPT_d) { 34 /* -d BLOCKDEV */ 35 if (!argv[0] || argv[1]) 31 36 bb_show_usage(); 32 if ( !del_loop(argv[0]))33 return EXIT_SUCCESS;34 bb_perror_nomsg_and_die();37 if (del_loop(argv[0])) 38 bb_simple_perror_msg_and_die(argv[0]); 39 return EXIT_SUCCESS; 35 40 } 36 41 37 if ( opt == 0x2) // -o38 offset = xatoull(opt_o);42 if (argv[0]) { 43 char *s; 39 44 40 /* -o or no option */ 45 if (opt == OPT_f) /* -f should not have arguments */ 46 bb_show_usage(); 41 47 42 if (argc == 2) { 43 if (set_loop(&argv[0], argv[1], offset) < 0) 44 bb_perror_nomsg_and_die(); 45 } else if (argc == 1) { 46 char *s = query_loop(argv[0]); 48 if (argv[1]) { 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 */ 55 s = query_loop(argv[0]); 47 56 if (!s) 48 bb_ perror_nomsg_and_die();57 bb_simple_perror_msg_and_die(argv[0]); 49 58 printf("%s: %s\n", argv[0], s); 50 59 if (ENABLE_FEATURE_CLEAN_UP) 51 60 free(s); 52 } else { 53 char dev[sizeof(LOOP_NAME"0")] = LOOP_NAME"0"; 54 char c; 55 for (c = '0'; c <= '9'; ++c) { 56 char *s; 57 dev[sizeof(LOOP_NAME"0")-2] = c; 58 s = query_loop(dev); 59 if (s) { 61 return EXIT_SUCCESS; 62 } 63 64 /* [-o OFS|-f] with no params */ 65 n = 0; 66 while (1) { 67 char *s; 68 char dev[LOOP_NAMESIZE]; 69 70 sprintf(dev, LOOP_FORMAT, n); 71 s = query_loop(dev); 72 n++; 73 if (!s) { 74 if (n > 9 && errno && errno != ENXIO) 75 return EXIT_SUCCESS; 76 if (opt == OPT_f) { 77 puts(dev); 78 return EXIT_SUCCESS; 79 } 80 } else { 81 if (opt != OPT_f) 60 82 printf("%s: %s\n", dev, s); 61 if (ENABLE_FEATURE_CLEAN_UP) 62 free(s); 63 } 83 if (ENABLE_FEATURE_CLEAN_UP) 84 free(s); 64 85 } 65 86 }
Note:
See TracChangeset
for help on using the changeset viewer.