1 /* vi: set sw=4 ts=4: */
3 * Mini losetup implementation for busybox
5 * Copyright (C) 2002 Matt Kraai.
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
13 int losetup_main(int argc UNUSED_PARAM, char **argv)
18 unsigned long long offset = 0;
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);
31 offset = xatoull(opt_o);
35 if (!argv[0] || argv[1])
37 if (del_loop(argv[0]))
38 bb_simple_perror_msg_and_die(argv[0]);
45 if (opt == OPT_f) /* -f should not have arguments */
49 /* [-o OFS] BLOCKDEV FILE */
50 if (set_loop(&argv[0], argv[1], offset) < 0)
51 bb_simple_perror_msg_and_die(argv[0]);
54 /* [-o OFS] BLOCKDEV */
55 s = query_loop(argv[0]);
57 bb_simple_perror_msg_and_die(argv[0]);
58 printf("%s: %s\n", argv[0], s);
59 if (ENABLE_FEATURE_CLEAN_UP)
64 /* [-o OFS|-f] with no params */
68 char dev[sizeof(LOOP_NAME) + sizeof(int)*3];
70 sprintf(dev, LOOP_NAME"%u", n);
74 if (n > 9 && errno && errno != ENXIO)
82 printf("%s: %s\n", dev, s);
83 if (ENABLE_FEATURE_CLEAN_UP)