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.
15 int losetup_main(int argc, char **argv)
21 opt = bb_getopt_ulflags(argc, argv, "do:", &opt_o);
25 if (opt == 0x3) // -d + -o (illegal)
28 if (opt == 0x1) { // -d
29 /* detach takes exactly one argument */
32 if (!del_loop(argv[0]))
34 bb_perror_nomsg_and_die();
38 offset = bb_xparse_number(opt_o, NULL);
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]);
47 if (!s) bb_perror_nomsg_and_die();
48 printf("%s: %s\n", argv[0], s);
49 if (ENABLE_FEATURE_CLEAN_UP) free(s);
51 char dev[11] = "/dev/loop0";
53 for (c = '0'; c <= '9'; ++c) {
58 printf("%s: %s\n", dev, s);
59 if (ENABLE_FEATURE_CLEAN_UP) free(s);