Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • 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:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/util-linux/losetup.c

    r1765 r2725  
    55 * Copyright (C) 2002  Matt Kraai.
    66 *
    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.
    88 */
    9 
    10 #include <getopt.h>
    119
    1210#include "libbb.h"
    1311
    14 int losetup_main(int argc, char **argv);
    15 int losetup_main(int argc, char **argv)
     12int losetup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     13int losetup_main(int argc UNUSED_PARAM, char **argv)
    1614{
    1715    unsigned opt;
     16    int n;
    1817    char *opt_o;
    1918    unsigned long long offset = 0;
     19    enum {
     20        OPT_d = (1 << 0),
     21        OPT_o = (1 << 1),
     22        OPT_f = (1 << 2),
     23    };
    2024
    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);
    2328    argv += optind;
    2429
    25     if (opt == 0x3) // -d + -o (illegal)
    26         bb_show_usage();
     30    if (opt == OPT_o)
     31        offset = xatoull(opt_o);
    2732
    28     if (opt == 0x1) { // -d
    29         /* detach takes exactly one argument */
    30         if (argc != 1)
     33    if (opt == OPT_d) {
     34        /* -d BLOCKDEV */
     35        if (!argv[0] || argv[1])
    3136            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;
    3540    }
    3641
    37     if (opt == 0x2) // -o
    38         offset = xatoull(opt_o);
     42    if (argv[0]) {
     43        char *s;
    3944
    40     /* -o or no option */
     45        if (opt == OPT_f) /* -f should not have arguments */
     46            bb_show_usage();
    4147
    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]);
    4756        if (!s)
    48             bb_perror_nomsg_and_die();
     57            bb_simple_perror_msg_and_die(argv[0]);
    4958        printf("%s: %s\n", argv[0], s);
    5059        if (ENABLE_FEATURE_CLEAN_UP)
    5160            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)
    6082                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);
    6485        }
    6586    }
Note: See TracChangeset for help on using the changeset viewer.