source: MondoRescue/branches/2.2.9/mindi-busybox/util-linux/losetup.c@ 2861

Last change on this file since 2861 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 1.7 KB
RevLine 
[1765]1/* vi: set sw=4 ts=4: */
[821]2/*
3 * Mini losetup implementation for busybox
4 *
5 * Copyright (C) 2002 Matt Kraai.
6 *
[2725]7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]8 */
9
[1765]10#include "libbb.h"
[821]11
[2725]12int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
13int losetup_main(int argc UNUSED_PARAM, char **argv)
[821]14{
[1765]15 unsigned opt;
[2725]16 int n;
[1765]17 char *opt_o;
18 unsigned long long offset = 0;
[2725]19 enum {
20 OPT_d = (1 << 0),
21 OPT_o = (1 << 1),
22 OPT_f = (1 << 2),
23 };
[821]24
[2725]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);
[1765]28 argv += optind;
[821]29
[2725]30 if (opt == OPT_o)
31 offset = xatoull(opt_o);
[1765]32
[2725]33 if (opt == OPT_d) {
34 /* -d BLOCKDEV */
35 if (!argv[0] || argv[1])
[1765]36 bb_show_usage();
[2725]37 if (del_loop(argv[0]))
38 bb_simple_perror_msg_and_die(argv[0]);
39 return EXIT_SUCCESS;
[1765]40 }
41
[2725]42 if (argv[0]) {
43 char *s;
[1765]44
[2725]45 if (opt == OPT_f) /* -f should not have arguments */
46 bb_show_usage();
[1765]47
[2725]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]);
[1765]56 if (!s)
[2725]57 bb_simple_perror_msg_and_die(argv[0]);
[1765]58 printf("%s: %s\n", argv[0], s);
59 if (ENABLE_FEATURE_CLEAN_UP)
60 free(s);
[2725]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)
[1765]82 printf("%s: %s\n", dev, s);
[2725]83 if (ENABLE_FEATURE_CLEAN_UP)
84 free(s);
[1765]85 }
86 }
[821]87 return EXIT_SUCCESS;
88}
Note: See TracBrowser for help on using the repository browser.