Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/miscutils/mt.c


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/miscutils/mt.c

    r1765 r2725  
    11/* vi: set sw=4 ts=4: */
    22/*
    3  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    44 */
    55
     
    77#include <sys/mtio.h>
    88
    9 struct mt_opcodes {
    10     const char *name;
    11     short value;
     9/* missing: eod/seod, stoptions, stwrthreshold, densities */
     10static const short opcode_value[] = {
     11    MTBSF,
     12    MTBSFM,
     13    MTBSR,
     14    MTBSS,
     15    MTCOMPRESSION,
     16    MTEOM,
     17    MTERASE,
     18    MTFSF,
     19    MTFSFM,
     20    MTFSR,
     21    MTFSS,
     22    MTLOAD,
     23    MTLOCK,
     24    MTMKPART,
     25    MTNOP,
     26    MTOFFL,
     27    MTOFFL,
     28    MTRAS1,
     29    MTRAS2,
     30    MTRAS3,
     31    MTRESET,
     32    MTRETEN,
     33    MTREW,
     34    MTSEEK,
     35    MTSETBLK,
     36    MTSETDENSITY,
     37    MTSETDRVBUFFER,
     38    MTSETPART,
     39    MTTELL,
     40    MTWSM,
     41    MTUNLOAD,
     42    MTUNLOCK,
     43    MTWEOF,
     44    MTWEOF
    1245};
    1346
    14 /* missing: eod/seod, stoptions, stwrthreshold, densities */
    15 static const struct mt_opcodes opcodes[] = {
    16     {"bsf", MTBSF},
    17     {"bsfm", MTBSFM},
    18     {"bsr", MTBSR},
    19     {"bss", MTBSS},
    20     {"datacompression", MTCOMPRESSION},
    21     {"eom", MTEOM},
    22     {"erase", MTERASE},
    23     {"fsf", MTFSF},
    24     {"fsfm", MTFSFM},
    25     {"fsr", MTFSR},
    26     {"fss", MTFSS},
    27     {"load", MTLOAD},
    28     {"lock", MTLOCK},
    29     {"mkpart", MTMKPART},
    30     {"nop", MTNOP},
    31     {"offline", MTOFFL},
    32     {"rewoffline", MTOFFL},
    33     {"ras1", MTRAS1},
    34     {"ras2", MTRAS2},
    35     {"ras3", MTRAS3},
    36     {"reset", MTRESET},
    37     {"retension", MTRETEN},
    38     {"rewind", MTREW},
    39     {"seek", MTSEEK},
    40     {"setblk", MTSETBLK},
    41     {"setdensity", MTSETDENSITY},
    42     {"drvbuffer", MTSETDRVBUFFER},
    43     {"setpart", MTSETPART},
    44     {"tell", MTTELL},
    45     {"wset", MTWSM},
    46     {"unload", MTUNLOAD},
    47     {"unlock", MTUNLOCK},
    48     {"eof", MTWEOF},
    49     {"weof", MTWEOF},
    50     {0, 0}
    51 };
     47static const char opcode_name[] ALIGN1 =
     48    "bsf"             "\0"
     49    "bsfm"            "\0"
     50    "bsr"             "\0"
     51    "bss"             "\0"
     52    "datacompression" "\0"
     53    "eom"             "\0"
     54    "erase"           "\0"
     55    "fsf"             "\0"
     56    "fsfm"            "\0"
     57    "fsr"             "\0"
     58    "fss"             "\0"
     59    "load"            "\0"
     60    "lock"            "\0"
     61    "mkpart"          "\0"
     62    "nop"             "\0"
     63    "offline"         "\0"
     64    "rewoffline"      "\0"
     65    "ras1"            "\0"
     66    "ras2"            "\0"
     67    "ras3"            "\0"
     68    "reset"           "\0"
     69    "retension"       "\0"
     70    "rewind"          "\0"
     71    "seek"            "\0"
     72    "setblk"          "\0"
     73    "setdensity"      "\0"
     74    "drvbuffer"       "\0"
     75    "setpart"         "\0"
     76    "tell"            "\0"
     77    "wset"            "\0"
     78    "unload"          "\0"
     79    "unlock"          "\0"
     80    "eof"             "\0"
     81    "weof"            "\0";
    5282
    53 int mt_main(int argc, char **argv);
    54 int mt_main(int argc, char **argv)
     83int mt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     84int mt_main(int argc UNUSED_PARAM, char **argv)
    5585{
    5686    const char *file = "/dev/tape";
    57     const struct mt_opcodes *code = opcodes;
    5887    struct mtop op;
    5988    struct mtpos position;
    60     int fd, mode;
     89    int fd, mode, idx;
    6190
    62     if (argc < 2) {
     91    if (!argv[1]) {
    6392        bb_show_usage();
    6493    }
    6594
    6695    if (strcmp(argv[1], "-f") == 0) {
    67         if (argc < 4) {
     96        if (!argv[2] || !argv[3])
    6897            bb_show_usage();
    69         }
    7098        file = argv[2];
    7199        argv += 2;
    72         argc -= 2;
    73100    }
    74101
    75     while (code->name != 0) {
    76         if (strcmp(code->name, argv[1]) == 0)
    77             break;
    78         code++;
    79     }
     102    idx = index_in_strings(opcode_name, argv[1]);
    80103
    81     if (code->name == 0) {
    82         bb_error_msg("unrecognized opcode %s", argv[1]);
    83         return EXIT_FAILURE;
    84     }
     104    if (idx < 0)
     105        bb_error_msg_and_die("unrecognized opcode %s", argv[1]);
    85106
    86     op.mt_op = code->value;
    87     if (argc >= 3)
    88         op.mt_count = xatoi_u(argv[2]);
     107    op.mt_op = opcode_value[idx];
     108    if (argv[2])
     109        op.mt_count = xatoi_positive(argv[2]);
    89110    else
    90         op.mt_count = 1;        /* One, not zero, right? */
     111        op.mt_count = 1;  /* One, not zero, right? */
    91112
    92     switch (code->value) {
     113    switch (opcode_value[idx]) {
    93114        case MTWEOF:
    94115        case MTERASE:
     
    105126    fd = xopen(file, mode);
    106127
    107     switch (code->value) {
     128    switch (opcode_value[idx]) {
    108129        case MTTELL:
    109130            ioctl_or_perror_and_die(fd, MTIOCPOS, &position, "%s", file);
    110             printf("At block %d.\n", (int) position.mt_blkno);
     131            printf("At block %d\n", (int) position.mt_blkno);
    111132            break;
    112133
Note: See TracChangeset for help on using the changeset viewer.