Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

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

    r821 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 * Mini losetup implementation for busybox
     
    89
    910#include <getopt.h>
    10 #include <stdlib.h>
    1111
    12 #include "busybox.h"
     12#include "libbb.h"
    1313
    14 int losetup_main (int argc, char **argv)
     14int losetup_main(int argc, char **argv);
     15int losetup_main(int argc, char **argv)
    1516{
    16   int offset = 0;
     17    unsigned opt;
     18    char *opt_o;
     19    unsigned long long offset = 0;
    1720
    18   /* This will need a "while(getopt()!=-1)" loop when we can have more than
    19      one option, but for now we can't. */
    20   switch(getopt(argc,argv, "do:")) {
    21     case 'd':
    22       /* detach takes exactly one argument */
    23       if(optind+1!=argc) bb_show_usage();
    24       if(!del_loop(argv[optind])) return EXIT_SUCCESS;
    25 die_failed:
    26       bb_perror_msg_and_die("%s",argv[optind]);
     21    opt = getopt32(argv, "do:", &opt_o);
     22    argc -= optind;
     23    argv += optind;
    2724
    28     case 'o':
    29       offset = bb_xparse_number (optarg, NULL);
    30       /* Fall through to do the losetup */
    31     case -1:
    32       /* losetup takes two argument:, loop_device and file */
    33       if(optind+2==argc) {
    34     if(set_loop(&argv[optind], argv[optind + 1], offset)>=0)
    35       return EXIT_SUCCESS;
    36     else goto die_failed;
    37       }
    38       if(optind+1==argc) {
    39     char *s=query_loop(argv[optind]);
    40     if (!s) goto die_failed;
    41     printf("%s: %s\n",argv[optind],s);
    42     if(ENABLE_FEATURE_CLEAN_UP) free(s);
     25    if (opt == 0x3) // -d + -o (illegal)
     26        bb_show_usage();
     27
     28    if (opt == 0x1) { // -d
     29        /* detach takes exactly one argument */
     30        if (argc != 1)
     31            bb_show_usage();
     32        if (!del_loop(argv[0]))
     33            return EXIT_SUCCESS;
     34        bb_perror_nomsg_and_die();
     35    }
     36
     37    if (opt == 0x2) // -o
     38        offset = xatoull(opt_o);
     39
     40    /* -o or no option */
     41
     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]);
     47        if (!s)
     48            bb_perror_nomsg_and_die();
     49        printf("%s: %s\n", argv[0], s);
     50        if (ENABLE_FEATURE_CLEAN_UP)
     51            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) {
     60                printf("%s: %s\n", dev, s);
     61                if (ENABLE_FEATURE_CLEAN_UP)
     62                    free(s);
     63            }
     64        }
     65    }
    4366    return EXIT_SUCCESS;
    44       }
    45       break;
    46   }
    47   bb_show_usage();
    48   return EXIT_FAILURE;
    4967}
Note: See TracChangeset for help on using the changeset viewer.