Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/util-linux


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
Location:
branches/3.2/mindi-busybox/util-linux
Files:
66 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/util-linux/Config.src

    r2725 r3232  
    1111    bool "acpid"
    1212    default y
    13     depends on PLATFORM_LINUX
     13    select PLATFORM_LINUX
    1414    help
    1515      acpid listens to ACPI events coming either in textual form from
     
    3434    bool "blkid"
    3535    default y
    36     depends on PLATFORM_LINUX
     36    select PLATFORM_LINUX
    3737    select VOLUMEID
    3838    help
     
    4141      With all submodules selected, it will add ~8k to busybox.
    4242
     43config FEATURE_BLKID_TYPE
     44    bool "Print filesystem type"
     45    default n
     46    depends on BLKID
     47    help
     48      Show TYPE="filesystem type"
     49
    4350config DMESG
    4451    bool "dmesg"
    4552    default y
    46     depends on PLATFORM_LINUX
     53    select PLATFORM_LINUX
    4754    help
    4855      dmesg is used to examine or control the kernel ring buffer. When the
     
    7885    bool "fbset"
    7986    default y
    80     depends on PLATFORM_LINUX
     87    select PLATFORM_LINUX
    8188    help
    8289      fbset is used to show or change the settings of a Linux frame buffer
     
    107114    bool "fdflush"
    108115    default y
    109     depends on PLATFORM_LINUX
     116    select PLATFORM_LINUX
    110117    help
    111118      fdflush is only needed when changing media on slightly-broken
     
    120127    bool "fdformat"
    121128    default y
    122     depends on PLATFORM_LINUX
     129    select PLATFORM_LINUX
    123130    help
    124131      fdformat is used to low-level format a floppy disk.
     
    127134    bool "fdisk"
    128135    default y
    129     depends on PLATFORM_LINUX
     136    select PLATFORM_LINUX
    130137    help
    131138      The fdisk utility is used to divide hard disks into one or more
     
    138145    default y
    139146    depends on FDISK
     147    depends on !LFS   # with LFS no special code is needed
    140148    help
    141149      Enable this option to support large disks > 4GB.
     
    203211    bool "findfs"
    204212    default y
    205     depends on PLATFORM_LINUX
     213    select PLATFORM_LINUX
    206214    select VOLUMEID
    207215    help
     
    219227    bool "freeramdisk"
    220228    default y
    221     depends on PLATFORM_LINUX
     229    select PLATFORM_LINUX
    222230    help
    223231      Linux allows you to create ramdisks. This utility allows you to
     
    242250    bool "mkfs_ext2"
    243251    default y
    244     depends on PLATFORM_LINUX
     252    select PLATFORM_LINUX
    245253    help
    246254      Utility to create EXT2 filesystems.
     
    249257    bool "mkfs_minix"
    250258    default y
    251     depends on PLATFORM_LINUX
     259    select PLATFORM_LINUX
    252260    help
    253261      The minix filesystem is a nice, small, compact, read-write filesystem
     
    267275    bool "mkfs_reiser"
    268276    default n
    269     depends on PLATFORM_LINUX
     277    select PLATFORM_LINUX
    270278    help
    271279      Utility to create ReiserFS filesystems.
     
    275283    bool "mkfs_vfat"
    276284    default y
    277     depends on PLATFORM_LINUX
     285    select PLATFORM_LINUX
    278286    help
    279287      Utility to create FAT32 filesystems.
     
    324332    bool "hwclock"
    325333    default y
    326     depends on PLATFORM_LINUX
     334    select PLATFORM_LINUX
    327335    help
    328336      The hwclock utility is used to read and set the hardware clock
     
    363371    bool "ipcs"
    364372    default y
    365     depends on PLATFORM_LINUX
     373    select PLATFORM_LINUX
    366374    help
    367375      The ipcs utility is used to provide information on the currently
     
    371379    bool "losetup"
    372380    default y
    373     depends on PLATFORM_LINUX
     381    select PLATFORM_LINUX
    374382    help
    375383      losetup is used to associate or detach a loop device with a regular
     
    380388    bool "lspci"
    381389    default y
    382     #depends on PLATFORM_LINUX
     390    #select PLATFORM_LINUX
    383391    help
    384392      lspci is a utility for displaying information about PCI buses in the
     
    390398    bool "lsusb"
    391399    default y
    392     #depends on PLATFORM_LINUX
     400    #select PLATFORM_LINUX
    393401    help
    394402      lsusb is a utility for displaying information about USB buses in the
     
    396404
    397405      This version uses sysfs (/sys/bus/usb/devices) only.
    398 
    399 config MDEV
    400     bool "mdev"
    401     default y
    402     depends on PLATFORM_LINUX
    403     help
    404       mdev is a mini-udev implementation for dynamically creating device
    405       nodes in the /dev directory.
    406 
    407       For more information, please see docs/mdev.txt
    408 
    409 config FEATURE_MDEV_CONF
    410     bool "Support /etc/mdev.conf"
    411     default y
    412     depends on MDEV
    413     help
    414       Add support for the mdev config file to control ownership and
    415       permissions of the device nodes.
    416 
    417       For more information, please see docs/mdev.txt
    418 
    419 config FEATURE_MDEV_RENAME
    420     bool "Support subdirs/symlinks"
    421     default y
    422     depends on FEATURE_MDEV_CONF
    423     help
    424       Add support for renaming devices and creating symlinks.
    425 
    426       For more information, please see docs/mdev.txt
    427 
    428 config FEATURE_MDEV_RENAME_REGEXP
    429     bool "Support regular expressions substitutions when renaming device"
    430     default y
    431     depends on FEATURE_MDEV_RENAME
    432     help
    433       Add support for regular expressions substitutions when renaming
    434       device.
    435 
    436 config FEATURE_MDEV_EXEC
    437     bool "Support command execution at device addition/removal"
    438     default y
    439     depends on FEATURE_MDEV_CONF
    440     help
    441       This adds support for an optional field to /etc/mdev.conf for
    442       executing commands when devices are created/removed.
    443 
    444       For more information, please see docs/mdev.txt
    445 
    446 config FEATURE_MDEV_LOAD_FIRMWARE
    447     bool "Support loading of firmwares"
    448     default y
    449     depends on MDEV
    450     help
    451       Some devices need to load firmware before they can be usable.
    452 
    453       These devices will request userspace look up the files in
    454       /lib/firmware/ and if it exists, send it to the kernel for
    455       loading into the hardware.
    456406
    457407config MKSWAP
     
    488438    bool "mount"
    489439    default y
    490     depends on PLATFORM_LINUX
     440    select PLATFORM_LINUX
    491441    help
    492442      All files and filesystems in Unix are arranged into one big directory
     
    536486
    537487config FEATURE_MOUNT_NFS
    538     bool "Support mounting NFS file systems"
    539     default y
     488    bool "Support mounting NFS file systems on Linux < 2.6.23"
     489    default n
    540490    depends on MOUNT
    541491    select FEATURE_HAVE_RPC
    542492    select FEATURE_SYSLOG
    543493    help
    544       Enable mounting of NFS file systems.
     494      Enable mounting of NFS file systems on Linux kernels prior
     495      to version 2.6.23. Note that in this case mounting of NFS
     496      over IPv6 will not be possible.
     497
     498      Note that this option links in RPC support from libc,
     499      which is rather large (~10 kbytes on uclibc).
    545500
    546501config FEATURE_MOUNT_CIFS
     
    571526    bool "pivot_root"
    572527    default y
    573     depends on PLATFORM_LINUX
     528    select PLATFORM_LINUX
    574529    help
    575530      The pivot_root utility swaps the mount points for the root filesystem
     
    599554    bool "readprofile"
    600555    default y
    601     #depends on PLATFORM_LINUX
     556    #select PLATFORM_LINUX
    602557    help
    603558      This allows you to parse /proc/profile for basic profiling.
     
    606561    bool "rtcwake"
    607562    default y
    608     depends on PLATFORM_LINUX
     563    select PLATFORM_LINUX
    609564    help
    610565      Enter a system sleep state until specified wakeup time.
     
    626581    bool "setarch"
    627582    default y
    628     depends on PLATFORM_LINUX
     583    select PLATFORM_LINUX
    629584    help
    630585      The linux32 utility is used to create a 32bit environment for the
     
    636591    bool "swaponoff"
    637592    default y
    638     depends on PLATFORM_LINUX
     593    select PLATFORM_LINUX
    639594    help
    640595      This option enables both the 'swapon' and the 'swapoff' utilities.
     
    655610    bool "switch_root"
    656611    default y
    657     depends on PLATFORM_LINUX
     612    select PLATFORM_LINUX
    658613    help
    659614      The switch_root utility is used from initramfs to select a new
     
    675630    bool "umount"
    676631    default y
    677     depends on PLATFORM_LINUX
     632    select PLATFORM_LINUX
    678633    help
    679634      When you want to remove a mounted filesystem from its current mount
     
    780735      TODO
    781736
     737config FEATURE_VOLUMEID_EXFAT
     738    bool "exFAT filesystem"
     739    default y
     740    depends on VOLUMEID
     741    help
     742      exFAT (extended FAT) is a proprietary file system designed especially
     743      for flash drives. It has many features from NTFS, but with less
     744      overhead. exFAT is used on most SDXC cards for consumer electronics.
     745
    782746config FEATURE_VOLUMEID_HFS
    783747    bool "hfs filesystem"
     
    808772      TODO
    809773
     774config FEATURE_VOLUMEID_NILFS
     775    bool "nilfs filesystem"
     776    default y
     777    depends on VOLUMEID
     778    help
     779      TODO
     780
    810781config FEATURE_VOLUMEID_NTFS
    811782    bool "ntfs filesystem"
     
    870841    help
    871842      TODO
     843
     844config FEATURE_VOLUMEID_SQUASHFS
     845    bool "SquashFS filesystem"
     846    default y
     847    depends on VOLUMEID && FEATURE_BLKID_TYPE
     848    help
     849      Squashfs is a compressed read-only filesystem for Linux. Squashfs is
     850      intended for general read-only filesystem use and in constrained block
     851      device/memory systems (e.g. embedded systems) where low overhead is
     852      needed.
    872853
    873854config FEATURE_VOLUMEID_SYSV
  • branches/3.2/mindi-busybox/util-linux/Kbuild.src

    r2725 r3232  
    2727lib-$(CONFIG_LSPCI)             += lspci.o
    2828lib-$(CONFIG_LSUSB)             += lsusb.o
    29 lib-$(CONFIG_MDEV)              += mdev.o
    3029lib-$(CONFIG_MKFS_EXT2)         += mkfs_ext2.o
    3130lib-$(CONFIG_MKFS_MINIX)        += mkfs_minix.o
  • branches/3.2/mindi-busybox/util-linux/acpid.c

    r2725 r3232  
    77 * Licensed under GPLv2, see file LICENSE in this source tree.
    88 */
     9
     10//usage:#define acpid_trivial_usage
     11//usage:       "[-df] [-c CONFDIR] [-l LOGFILE] [-a ACTIONFILE] [-M MAPFILE] [-e PROC_EVENT_FILE] [-p PIDFILE]"
     12//usage:#define acpid_full_usage "\n\n"
     13//usage:       "Listen to ACPI events and spawn specific helpers on event arrival\n"
     14//usage:     "\n    -d  Log to stderr, not log file (implies -f)"
     15//usage:     "\n    -f  Run in foreground"
     16//usage:     "\n    -c DIR  Config directory [/etc/acpi]"
     17//usage:     "\n    -e FILE /proc event file [/proc/acpi/event]"
     18//usage:     "\n    -l FILE Log file [/var/log/acpid.log]"
     19//usage:     "\n    -p FILE Pid file [/var/run/acpid.pid]"
     20//usage:     "\n    -a FILE Action file [/etc/acpid.conf]"
     21//usage:     "\n    -M FILE Map file [/etc/acpi.map]"
     22//usage:    IF_FEATURE_ACPID_COMPAT(
     23//usage:     "\n\nAccept and ignore compatibility options -g -m -s -S -v"
     24//usage:    )
     25//usage:
     26//usage:#define acpid_example_usage
     27//usage:       "Without -e option, acpid uses all /dev/input/event* files\n"
     28//usage:       "# acpid\n"
     29//usage:       "# acpid -l /var/log/my-acpi-log\n"
     30//usage:       "# acpid -e /proc/acpi/event\n"
     31
    932#include "libbb.h"
    1033#include <syslog.h>
    1134#include <linux/input.h>
     35
     36#ifndef EV_SW
     37# define EV_SW         0x05
     38#endif
     39#ifndef EV_KEY
     40# define EV_KEY        0x01
     41#endif
     42#ifndef SW_LID
     43# define SW_LID        0x00
     44#endif
     45#ifndef SW_RFKILL_ALL
     46# define SW_RFKILL_ALL 0x03
     47#endif
     48#ifndef KEY_POWER
     49# define KEY_POWER      116     /* SC System Power Down */
     50#endif
     51#ifndef KEY_SLEEP
     52# define KEY_SLEEP      142     /* SC System Sleep */
     53#endif
    1254
    1355enum {
     
    3476    { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRF 00000080" },
    3577    { "EV_KEY", 0x01, "KEY_POWER", 116, 1, "button/power PWRB 00000080" },
     78    { "EV_SW", 0x05, "SW_LID", 0x00, 1, "button/lid LID0 00000080" },
    3679};
    3780
     
    184227int acpid_main(int argc UNUSED_PARAM, char **argv)
    185228{
    186     struct input_event ev;
    187229    int nfd;
    188230    int opts;
     
    194236    const char *opt_map = "/etc/acpi.map";
    195237#if ENABLE_FEATURE_PIDFILE
    196     const char *opt_pidfile = "/var/run/acpid.pid";
     238    const char *opt_pidfile = CONFIG_PID_FILE_PATH "/acpid.pid";
    197239#endif
    198240
     
    207249
    208250    if (!(opts & OPT_f)) {
     251        /* No -f "Foreground", we go to background */
    209252        bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
    210253    }
    211254
    212255    if (!(opts & OPT_d)) {
     256        /* No -d "Debug", we log to log file.
     257         * This includes any output from children.
     258         */
     259        xmove_fd(xopen(opt_logfile, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
     260        xdup2(STDOUT_FILENO, STDERR_FILENO);
     261        /* Also, acpid's messages (but not children) will go to syslog too */
    213262        openlog(applet_name, LOG_PID, LOG_DAEMON);
    214263        logmode = LOGMODE_SYSLOG | LOGMODE_STDIO;
    215     } else {
    216         xmove_fd(xopen(opt_logfile, O_WRONLY | O_CREAT | O_TRUNC), STDOUT_FILENO);
    217     }
     264    }
     265    /* else: -d "Debug", log is not redirected */
    218266
    219267    parse_conf_file(opt_action);
     
    222270    xchdir(opt_dir);
    223271
     272    /* We spawn children but don't wait for them. Prevent zombies: */
    224273    bb_signals((1 << SIGCHLD), SIG_IGN);
    225     bb_signals(BB_FATAL_SIGS, record_signo);
     274    // If you enable this, (1) explain why, (2)
     275    // make sure while(poll) loop below is still interruptible
     276    // by SIGTERM et al:
     277    //bb_signals(BB_FATAL_SIGS, record_signo);
    226278
    227279    pfd = NULL;
     
    231283        char *dev_event;
    232284
    233         dev_event = xasprintf((option_mask32 & OPT_e) ? "%s" : "%s%u", opt_input, nfd);
     285        dev_event = xasprintf((opts & OPT_e) ? "%s" : "%s%u", opt_input, nfd);
    234286        fd = open(dev_event, O_RDONLY | O_NONBLOCK);
    235287        if (fd < 0) {
     
    238290            break;
    239291        }
     292        free(dev_event);
    240293        pfd = xrealloc_vector(pfd, 1, nfd);
    241294        pfd[nfd].fd = fd;
     
    246299    write_pidfile(opt_pidfile);
    247300
    248     while (poll(pfd, nfd, -1) > 0) {
     301    while (safe_poll(pfd, nfd, -1) > 0) {
    249302        int i;
    250303        for (i = 0; i < nfd; i++) {
    251             const char *event = NULL;
    252 
    253             memset(&ev, 0, sizeof(ev));
    254 
    255             if (!(pfd[i].revents & POLLIN))
    256                 continue;
    257 
     304            const char *event;
     305
     306            if (!(pfd[i].revents & POLLIN)) {
     307                if (pfd[i].revents == 0)
     308                    continue; /* this fd has nothing */
     309
     310                /* Likely POLLERR, POLLHUP, POLLNVAL.
     311                 * Do not listen on this fd anymore.
     312                 */
     313                close(pfd[i].fd);
     314                nfd--;
     315                for (; i < nfd; i++)
     316                    pfd[i].fd = pfd[i + 1].fd;
     317                break; /* do poll() again */
     318            }
     319
     320            event = NULL;
    258321            if (option_mask32 & OPT_e) {
    259322                char *buf;
    260323                int len;
    261324
    262                 buf = xmalloc_reads(pfd[i].fd, NULL, NULL);
     325                buf = xmalloc_reads(pfd[i].fd, NULL);
    263326                /* buf = "button/power PWRB 00000080 00000000" */
    264327                len = strlen(buf) - 9;
     
    266329                    buf[len] = '\0';
    267330                event = find_action(NULL, buf);
     331                free(buf);
    268332            } else {
     333                struct input_event ev;
     334
    269335                if (sizeof(ev) != full_read(pfd[i].fd, &ev, sizeof(ev)))
    270336                    continue;
     
    277343            if (!event)
    278344                continue;
    279             // spawn event handler
     345            /* spawn event handler */
    280346            process_event(event);
    281347        }
     
    283349
    284350    if (ENABLE_FEATURE_CLEAN_UP) {
    285         while (nfd--) {
    286             if (pfd[nfd].fd) {
    287                 close(pfd[nfd].fd);
    288             }
    289         }
     351        while (nfd--)
     352            close(pfd[nfd].fd);
    290353        free(pfd);
    291354    }
  • branches/3.2/mindi-busybox/util-linux/blkid.c

    r2725 r3232  
    88 */
    99
     10//usage:#define blkid_trivial_usage
     11//usage:       "[BLOCKDEV]..."
     12//usage:#define blkid_full_usage "\n\n"
     13//usage:       "Print UUIDs of all filesystems"
     14
    1015#include "libbb.h"
    1116#include "volume_id.h"
    1217
    1318int blkid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    14 int blkid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
     19int blkid_main(int argc UNUSED_PARAM, char **argv)
    1520{
    16     display_uuid_cache();
     21    int scan_devices = 1;
     22
     23    while (*++argv) {
     24        /* Note: bogus device names don't cause any error messages */
     25        add_to_uuid_cache(*argv);
     26        scan_devices = 0;
     27    }
     28
     29    display_uuid_cache(scan_devices);
    1730    return 0;
    1831}
  • branches/3.2/mindi-busybox/util-linux/blockdev.c

    r3085 r3232  
    77 */
    88
    9 //applet:IF_BLOCKDEV(APPLET(blockdev, _BB_DIR_SBIN, _BB_SUID_DROP))
     9//applet:IF_BLOCKDEV(APPLET(blockdev, BB_DIR_SBIN, BB_SUID_DROP))
    1010
    1111//kbuild:lib-$(CONFIG_BLOCKDEV) += blockdev.o
     
    2020//usage:    "OPTION BLOCKDEV"
    2121//usage:#define blockdev_full_usage "\n\n"
    22 //usage:       "Options:"
    23 //usage:     "\n    --setro     Set ro"
     22//usage:       "    --setro     Set ro"
    2423//usage:     "\n    --setrw     Set rw"
    2524//usage:     "\n    --getro     Get ro"
     
    2726//usage:     "\n    --getbsz    Get block size"
    2827//usage:     "\n    --setbsz BYTES  Set block size"
    29 //usage:     "\n    --getsize   Get device size in 512-byte sectors"
     28//usage:     "\n    --getsz     Get device size in 512-byte sectors"
     29/*//usage:     "\n  --getsize   Get device size in sectors (deprecated)"*/
    3030//usage:     "\n    --getsize64 Get device size in bytes"
    3131//usage:     "\n    --flushbufs Flush buffers"
     
    3535#include "libbb.h"
    3636#include <linux/fs.h>
    37 
    38 /*  Patch bco to compile this busybox on rhel3  */
    39 #ifndef BLKGETSIZE64
    40 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
    41 #endif
    4237
    4338enum {
     
    5146    FL_USRARG   = 4, /* argument is provided by user */
    5247    FL_NORESULT = 8,
     48    FL_SCALE512 = 16,
    5349};
    5450
     
    9187        .flags = ARG_INT + FL_NORESULT + FL_USRARG,
    9288        .argval = 0,
     89    },{
     90        .ioc = BLKGETSIZE64,
     91        .name = "getsz",
     92        .flags = ARG_U64 + FL_SCALE512,
     93        .argval = -1,
    9394    },{
    9495        .ioc = BLKGETSIZE,
     
    129130
    130131int blockdev_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    131 int blockdev_main(int argc, char **argv)
     132int blockdev_main(int argc UNUSED_PARAM, char **argv)
    132133{
    133134    const struct bdc *bdcmd;
     
    140141    } ioctl_val_on_stack;
    141142
    142     if ((unsigned)(argc - 3) > 1) /* must have 2 or 3 args */
     143    argv++;
     144    if (!argv[0] || !argv[1]) /* must have at least 2 args */
    143145        bb_show_usage();
    144146
    145     bdcmd = find_cmd(*++argv);
     147    bdcmd = find_cmd(*argv);
    146148
    147149    u64 = (int)bdcmd->argval;
     
    149151        u64 = xatoi_positive(*++argv);
    150152
    151     if (!*++argv || argv[1])
     153    argv++;
     154    if (!argv[0] || argv[1])
    152155        bb_show_usage();
    153     fd = xopen(*argv, O_RDONLY);
     156    fd = xopen(argv[0], O_RDONLY);
    154157
    155158    ioctl_val_on_stack.u64 = u64;
     
    179182    u64 = ioctl_val_on_stack.u64;
    180183
     184    if (bdcmd->flags & FL_SCALE512)
     185        u64 >>= 9;
     186
    181187    /* Zero- or one-extend the value if needed, then print */
    182188    switch (bdcmd->flags & (ARG_MASK+FL_NORESULT)) {
  • branches/3.2/mindi-busybox/util-linux/dmesg.c

    r2725 r3232  
    99 * Licensed under GPLv2, see file LICENSE in this source tree.
    1010 */
     11
     12//usage:#define dmesg_trivial_usage
     13//usage:       "[-c] [-n LEVEL] [-s SIZE]"
     14//usage:#define dmesg_full_usage "\n\n"
     15//usage:       "Print or control the kernel ring buffer\n"
     16//usage:     "\n    -c      Clear ring buffer after printing"
     17//usage:     "\n    -n LEVEL    Set console logging level"
     18//usage:     "\n    -s SIZE     Buffer size"
     19
    1120#include <sys/klog.h>
    1221#include "libbb.h"
     
    5160        int in = 0;
    5261
    53         /* Skip <#> at the start of lines */
     62        /* Skip <[0-9]+> at the start of lines */
    5463        while (1) {
    5564            if (last == '\n' && buf[in] == '<') {
    56                 in += 3;
    57                 if (in >= len)
    58                     break;
     65                while (buf[in++] != '>' && in < len)
     66                    ;
     67            } else {
     68                last = buf[in++];
     69                putchar(last);
    5970            }
    60             last = buf[in];
    61             putchar(last);
    62             in++;
    6371            if (in >= len)
    6472                break;
  • branches/3.2/mindi-busybox/util-linux/fbset.c

    r2725 r3232  
    1212 *     Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
    1313 */
     14
     15//usage:#define fbset_trivial_usage
     16//usage:       "[OPTIONS] [MODE]"
     17//usage:#define fbset_full_usage "\n\n"
     18//usage:       "Show and modify frame buffer settings"
     19//usage:
     20//usage:#define fbset_example_usage
     21//usage:       "$ fbset\n"
     22//usage:       "mode \"1024x768-76\"\n"
     23//usage:       "    # D: 78.653 MHz, H: 59.949 kHz, V: 75.694 Hz\n"
     24//usage:       "    geometry 1024 768 1024 768 16\n"
     25//usage:       "    timings 12714 128 32 16 4 128 4\n"
     26//usage:       "    accel false\n"
     27//usage:       "    rgba 5/11,6/5,5/0,0/0\n"
     28//usage:       "endmode\n"
    1429
    1530#include "libbb.h"
     
    257272        p = token[1];
    258273        i = index_in_strings(
    259             "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0",
     274            "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0rgba\0",
    260275            token[0]);
    261276        switch (i) {
     
    328343//bb_info_msg("EXTSYNC[%s]", p);
    329344            break;
     345        case 8: {
     346            int red_offset, red_length;
     347            int green_offset, green_length;
     348            int blue_offset, blue_length;
     349            int transp_offset, transp_length;
     350
     351            sscanf(p, "%d/%d,%d/%d,%d/%d,%d/%d",
     352                &red_offset, &red_length,
     353                &green_offset, &green_length,
     354                &blue_offset, &blue_length,
     355                &transp_offset, &transp_length);
     356            base->red.offset = red_offset;
     357            base->red.length = red_length;
     358            base->red.msb_right = 0;
     359            base->green.offset = green_offset;
     360            base->green.length = green_length;
     361            base->green.msb_right = 0;
     362            base->blue.offset = blue_offset;
     363            base->blue.length = blue_length;
     364            base->blue.msb_right = 0;
     365            base->transp.offset = transp_offset;
     366            base->transp.length = transp_length;
     367            base->transp.msb_right = 0;
     368        }
    330369        }
    331370    }
     
    371410        OPT_SHOW     = (1 << 1),
    372411        OPT_READMODE = (1 << 2),
    373         OPT_ALL      = (1 << 9),
     412        OPT_ALL      = (1 << 3),
    374413    };
    375414    struct fb_var_screeninfo var_old, var_set;
     
    388427    argc--;
    389428    for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) {
    390         if (thisarg[0] == '-') for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) {
     429        if (thisarg[0] != '-') {
     430            if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1)
     431                bb_show_usage();
     432            mode = thisarg;
     433            options |= OPT_READMODE;
     434            goto contin;
     435        }
     436        for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) {
    391437            if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0)
    392438                continue;
     
    457503            goto contin;
    458504        }
    459         if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1)
    460             bb_show_usage();
    461         mode = *argv;
    462         options |= OPT_READMODE;
     505        bb_show_usage();
    463506 contin: ;
    464507    }
     
    472515            bb_error_msg_and_die("unknown video mode '%s'", mode);
    473516        }
     517        options |= OPT_CHANGE;
    474518#endif
    475519    }
  • branches/3.2/mindi-busybox/util-linux/fdformat.c

    r2725 r3232  
    55 * Licensed under GPLv2, see file LICENSE in this source tree.
    66 */
     7
     8//usage:#define fdformat_trivial_usage
     9//usage:       "[-n] DEVICE"
     10//usage:#define fdformat_full_usage "\n\n"
     11//usage:       "Format floppy disk\n"
     12//usage:     "\n    -n  Don't verify after format"
    713
    814#include "libbb.h"
     
    111117            while (--read_bytes >= 0) {
    112118                if (data[read_bytes] != FD_FILL_BYTE) {
    113                      printf("bad data in cyl %d\nContinuing... ", cyl);
     119                    printf("bad data in cyl %d\nContinuing... ", cyl);
    114120                }
    115121            }
  • branches/3.2/mindi-busybox/util-linux/fdisk.c

    r2725 r3232  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     9
     10/* Looks like someone forgot to add this to config system */
     11//usage:#ifndef ENABLE_FEATURE_FDISK_BLKSIZE
     12//usage:# define ENABLE_FEATURE_FDISK_BLKSIZE 0
     13//usage:# define IF_FEATURE_FDISK_BLKSIZE(a)
     14//usage:#endif
     15//usage:
     16//usage:#define fdisk_trivial_usage
     17//usage:       "[-ul" IF_FEATURE_FDISK_BLKSIZE("s") "] "
     18//usage:       "[-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK"
     19//usage:#define fdisk_full_usage "\n\n"
     20//usage:       "Change partition table\n"
     21//usage:     "\n    -u      Start and End are in sectors (instead of cylinders)"
     22//usage:     "\n    -l      Show partition table for each DISK, then exit"
     23//usage:    IF_FEATURE_FDISK_BLKSIZE(
     24//usage:     "\n    -s      Show partition sizes in kb for each DISK, then exit"
     25//usage:    )
     26//usage:     "\n    -b 2048     (for certain MO disks) use 2048-byte sectors"
     27//usage:     "\n    -C CYLINDERS    Set number of cylinders/heads/sectors"
     28//usage:     "\n    -H HEADS"
     29//usage:     "\n    -S SECTORS"
    930
    1031#ifndef _LARGEFILE64_SOURCE
     
    549570    int sz;
    550571
    551     sz = read_line_input(prompt, line_buffer, sizeof(line_buffer), NULL);
     572    sz = read_line_input(NULL, prompt, line_buffer, sizeof(line_buffer), /*timeout*/ -1);
    552573    if (sz <= 0)
    553574        exit(EXIT_SUCCESS); /* Ctrl-D or Ctrl-C */
     
    25232544
    25242545static void
    2525 write_table(void)
    2526 {
    2527     int i;
    2528 
    2529     if (LABEL_IS_DOS) {
    2530         for (i = 0; i < 3; i++)
    2531             if (ptes[i].changed)
    2532                 ptes[3].changed = 1;
    2533         for (i = 3; i < g_partitions; i++) {
    2534             struct pte *pe = &ptes[i];
    2535 
    2536             if (pe->changed) {
    2537                 write_part_table_flag(pe->sectorbuffer);
    2538                 write_sector(pe->offset_from_dev_start, pe->sectorbuffer);
    2539             }
    2540         }
    2541     }
    2542     else if (LABEL_IS_SGI) {
    2543         /* no test on change? the printf below might be mistaken */
    2544         sgi_write_table();
    2545     }
    2546     else if (LABEL_IS_SUN) {
    2547         int needw = 0;
    2548 
    2549         for (i = 0; i < 8; i++)
    2550             if (ptes[i].changed)
    2551                 needw = 1;
    2552         if (needw)
    2553             sun_write_table();
    2554     }
    2555 
    2556     printf("The partition table has been altered!\n\n");
    2557     reread_partition_table(1);
    2558 }
    2559 
    2560 static void
    25612546reread_partition_table(int leave)
    25622547{
     
    25652550    printf("Calling ioctl() to re-read partition table\n");
    25662551    sync();
    2567     /* sleep(2); Huh? */
     2552    /* Users with slow external USB disks on a 320MHz ARM system (year 2011)
     2553     * report that sleep is needed, otherwise BLKRRPART may fail with -EIO:
     2554     */
     2555    sleep(1);
    25682556    i = ioctl_or_perror(dev_fd, BLKRRPART, NULL,
    25692557            "WARNING: rereading partition table "
     
    25822570        exit(i != 0);
    25832571    }
     2572}
     2573
     2574static void
     2575write_table(void)
     2576{
     2577    int i;
     2578
     2579    if (LABEL_IS_DOS) {
     2580        for (i = 0; i < 3; i++)
     2581            if (ptes[i].changed)
     2582                ptes[3].changed = 1;
     2583        for (i = 3; i < g_partitions; i++) {
     2584            struct pte *pe = &ptes[i];
     2585            if (pe->changed) {
     2586                write_part_table_flag(pe->sectorbuffer);
     2587                write_sector(pe->offset_from_dev_start, pe->sectorbuffer);
     2588            }
     2589        }
     2590    }
     2591    else if (LABEL_IS_SGI) {
     2592        /* no test on change? the printf below might be mistaken */
     2593        sgi_write_table();
     2594    }
     2595    else if (LABEL_IS_SUN) {
     2596        for (i = 0; i < 8; i++) {
     2597            if (ptes[i].changed) {
     2598                sun_write_table();
     2599                break;
     2600            }
     2601        }
     2602    }
     2603
     2604    printf("The partition table has been altered.\n");
     2605    reread_partition_table(1);
    25842606}
    25852607#endif /* FEATURE_FDISK_WRITABLE */
     
    28252847}
    28262848
     2849/* Is it a whole disk? The digit check is still useful
     2850   for Xen devices for example. */
     2851static int is_whole_disk(const char *disk)
     2852{
     2853    unsigned len;
     2854    int fd = open(disk, O_RDONLY);
     2855
     2856    if (fd != -1) {
     2857        struct hd_geometry geometry;
     2858        int err = ioctl(fd, HDIO_GETGEO, &geometry);
     2859        close(fd);
     2860        if (!err)
     2861            return (geometry.start == 0);
     2862    }
     2863
     2864    /* Treat "nameN" as a partition name, not whole disk */
     2865    /* note: mmcblk0 should work from the geometry check above */
     2866    len = strlen(disk);
     2867    if (len != 0 && isdigit(disk[len - 1]))
     2868        return 0;
     2869
     2870    return 1;
     2871}
     2872
    28272873/* for fdisk -l: try all things in /proc/partitions
    28282874   that look like a partition name (do not end in a digit) */
     
    28312877{
    28322878    FILE *procpt;
    2833     char line[100], ptname[100], devname[120], *s;
     2879    char line[100], ptname[100], devname[120];
    28342880    int ma, mi, sz;
    28352881
     
    28402886                &ma, &mi, &sz, ptname) != 4)
    28412887            continue;
    2842         for (s = ptname; *s; s++)
    2843             continue;
    2844         /* note: excluding '0': e.g. mmcblk0 is not a partition name! */
    2845         if (s[-1] >= '1' && s[-1] <= '9')
    2846             continue;
     2888
    28472889        sprintf(devname, "/dev/%s", ptname);
    2848         open_list_and_close(devname, 0);
     2890        if (is_whole_disk(devname))
     2891            open_list_and_close(devname, 0);
    28492892    }
    28502893#if ENABLE_FEATURE_CLEAN_UP
     
    29813024                    sgi_get_bootfile());
    29823025                if (read_maybe_empty("Please enter the name of the "
    2983                            "new boot file: ") == '\n')
     3026                        "new boot file: ") == '\n')
    29843027                    printf("Boot file unchanged\n");
    29853028                else
     
    30593102            break;
    30603103        case 'w':
    3061             write_table();          /* does not return */
     3104            write_table();  /* does not return */
    30623105            break;
    30633106#if ENABLE_FEATURE_FDISK_ADVANCED
  • branches/3.2/mindi-busybox/util-linux/fdisk_osf.c

    r2725 r3232  
    4444#define BSD_LINUX_BOOTDIR "/usr/ucb/mdec"
    4545
    46 #if defined(i386) || defined(__sparc__) || defined(__arm__) \
    47  || defined(__m68k__) || defined(__mips__) || defined(__s390__) \
    48  || defined(__s390__) || defined(__s390x__) \
    49  || defined(__sh__) || defined(__x86_64__) || defined(__avr32__) \
    50  || defined(__nds32__)
    51 # define BSD_LABELSECTOR   1
    52 # define BSD_LABELOFFSET   0
    53 #elif defined(__alpha__) || defined(__powerpc__) || defined(__ia64__) \
     46#if defined(__alpha__) \
     47 || defined(__powerpc__) \
     48 || defined(__ia64__) \
    5449 || defined(__hppa__)
    5550# define BSD_LABELSECTOR   0
    5651# define BSD_LABELOFFSET   64
    5752#else
    58 # error unknown architecture
     53# define BSD_LABELSECTOR   1
     54# define BSD_LABELOFFSET   0
    5955#endif
    6056
     
    903899#else
    904900    d->d_npartitions = 3;
    905     pp = &d->d_partitions[2];             /* Partition C should be
    906                            the whole disk */
     901    pp = &d->d_partitions[2]; /* Partition C should be the whole disk */
    907902    pp->p_offset = 0;
    908903    pp->p_size   = d->d_secperunit;
     
    940935
    941936    memmove(d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
    942            sizeof(struct xbsd_disklabel));
     937            sizeof(struct xbsd_disklabel));
    943938
    944939    if (d->d_magic != BSD_DISKMAGIC || d->d_magic2 != BSD_DISKMAGIC)
  • branches/3.2/mindi-busybox/util-linux/findfs.c

    r2725 r3232  
    88 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
     10
     11//usage:#define findfs_trivial_usage
     12//usage:       "LABEL=label or UUID=uuid"
     13//usage:#define findfs_full_usage "\n\n"
     14//usage:       "Find a filesystem device based on a label or UUID"
     15//usage:
     16//usage:#define findfs_example_usage
     17//usage:       "$ findfs LABEL=MyDevice"
    1018
    1119#include "libbb.h"
  • branches/3.2/mindi-busybox/util-linux/flock.c

    r2725 r3232  
    44 * This is free software, licensed under the GNU General Public License v2.
    55 */
     6
     7//usage:#define flock_trivial_usage
     8//usage:       "[-sxun] FD|{FILE [-c] PROG ARGS}"
     9//usage:#define flock_full_usage "\n\n"
     10//usage:       "[Un]lock file descriptor, or lock FILE, run PROG\n"
     11//usage:     "\n    -s  Shared lock"
     12//usage:     "\n    -x  Exclusive lock (default)"
     13//usage:     "\n    -u  Unlock FD"
     14//usage:     "\n    -n  Fail rather than wait"
     15
    616#include <sys/file.h>
    717#include "libbb.h"
     
    2030
    2131#if ENABLE_LONG_OPTS
    22         static const char getopt_longopts[] ALIGN1 =
     32    static const char getopt_longopts[] ALIGN1 =
    2333        "shared\0"      No_argument       "s"
    2434        "exclusive\0"   No_argument       "x"
     
    3646        fd = open(argv[0], O_RDONLY|O_NOCTTY|O_CREAT, 0666);
    3747        if (fd < 0 && errno == EISDIR)
    38                 fd = open(argv[0], O_RDONLY|O_NOCTTY);
     48            fd = open(argv[0], O_RDONLY|O_NOCTTY);
    3949        if (fd < 0)
    4050            bb_perror_msg_and_die("can't open '%s'", argv[0]);
  • branches/3.2/mindi-busybox/util-linux/freeramdisk.c

    r2725 r3232  
    99 * Licensed under GPLv2, see file LICENSE in this source tree.
    1010 */
     11
     12//usage:#define freeramdisk_trivial_usage
     13//usage:       "DEVICE"
     14//usage:#define freeramdisk_full_usage "\n\n"
     15//usage:       "Free all memory used by the specified ramdisk"
     16//usage:
     17//usage:#define freeramdisk_example_usage
     18//usage:       "$ freeramdisk /dev/ram2\n"
     19//usage:
     20//usage:#define fdflush_trivial_usage
     21//usage:       "DEVICE"
     22//usage:#define fdflush_full_usage "\n\n"
     23//usage:       "Force floppy disk drive to detect disk change"
     24
    1125#include <sys/mount.h>
    1226#include "libbb.h"
  • branches/3.2/mindi-busybox/util-linux/fsck_minix.c

    r2725 r3232  
    1414 *      Sent out to the mailing-list for testing.
    1515 *
    16  * 14.11.91  -  Testing seems to have gone well. Added some
     16 * 14.11.91  -  Testing seems to have gone well. Added some
    1717 *      correction-code, and changed some functions.
    1818 *
     
    2323 *      things seem to work now. Yeah, sure.
    2424 *
    25  *
    26  * 19.04.92  -  Had to start over again from this old version, as a
     25 * 19.04.92  -  Had to start over again from this old version, as a
    2726 *      kernel bug ate my enhanced fsck in february.
    2827 *
    29  * 28.02.93  -  added support for different directory entry sizes..
     28 * 28.02.93  -  added support for different directory entry sizes..
    3029 *
    3130 * Sat Mar  6 18:59:42 1993, faith@cs.unc.edu: Output namelen with
     
    3635 *
    3736 * Mon Jan  3 11:06:52 1994 - Dr. Wettstein (greg%wind.uucp@plains.nodak.edu)
    38  *                Added support for file system valid flag.  Also
    39  *                added program_version variable and output of
    40  *                program name and version number when program
    41  *                is executed.
    42  *
    43  * 30.10.94 - added support for v2 filesystem
    44  *            (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de)
    45  *
    46  * 10.12.94  -  added test to prevent checking of mounted fs adapted
    47  *              from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck
    48  *              program.  (Daniel Quinlan, quinlan@yggdrasil.com)
     37 *                            Added support for file system valid flag.  Also
     38 *                            added program_version variable and output of
     39 *                            program name and version number when program
     40 *                            is executed.
     41 *
     42 * 30.10.94  - added support for v2 filesystem
     43 *             (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de)
     44 *
     45 * 10.12.94  - added test to prevent checking of mounted fs adapted
     46 *             from Theodore Ts'o's (tytso@athena.mit.edu) e2fsck
     47 *             program.  (Daniel Quinlan, quinlan@yggdrasil.com)
    4948 *
    5049 * 01.07.96  - Fixed the v2 fs stuff to use the right #defines and such
    51  *         for modern libcs (janl@math.uio.no, Nicolai Langfeldt)
     50 *             for modern libcs (janl@math.uio.no, Nicolai Langfeldt)
    5251 *
    5352 * 02.07.96  - Added C bit fiddling routines from rmk@ecs.soton.ac.uk
    5453 *             (Russell King).  He made them for ARM.  It would seem
    55  *         that the ARM is powerful enough to do this in C whereas
     54 *             that the ARM is powerful enough to do this in C whereas
    5655 *             i386 and m64k must use assembly to get it fast >:-)
    57  *         This should make minix fsck system-independent.
    58  *         (janl@math.uio.no, Nicolai Langfeldt)
     56 *             This should make minix fsck system-independent.
     57 *             (janl@math.uio.no, Nicolai Langfeldt)
    5958 *
    6059 * 04.11.96  - Added minor fixes from Andreas Schwab to avoid compiler
    6160 *             warnings.  Added mc68k bitops from
    62  *         Joerg Dorchain <dorchain@mpi-sb.mpg.de>.
     61 *             Joerg Dorchain <dorchain@mpi-sb.mpg.de>.
    6362 *
    6463 * 06.11.96  - Added v2 code submitted by Joerg Dorchain, but written by
     
    8786 * enforced (but it's not much fun on a character device :-).
    8887 */
     88
     89//usage:#define fsck_minix_trivial_usage
     90//usage:       "[-larvsmf] BLOCKDEV"
     91//usage:#define fsck_minix_full_usage "\n\n"
     92//usage:       "Check MINIX filesystem\n"
     93//usage:     "\n    -l  List all filenames"
     94//usage:     "\n    -r  Perform interactive repairs"
     95//usage:     "\n    -a  Perform automatic repairs"
     96//usage:     "\n    -v  Verbose"
     97//usage:     "\n    -s  Output superblock information"
     98//usage:     "\n    -m  Show \"mode not cleared\" warnings"
     99//usage:     "\n    -f  Force file system check"
    89100
    90101#include <mntent.h>
     
    11201131        }
    11211132        printf("Zone %d: %sin use, counted=%d\n",
    1122                i, zone_in_use(i) ? "" : "not ", zone_count[i]);
     1133            i, zone_in_use(i) ? "" : "not ", zone_count[i]);
    11231134    }
    11241135}
     
    11721183        }
    11731184        printf("Zone %d: %sin use, counted=%d\n",
    1174                i, zone_in_use(i) ? "" : "not ", zone_count[i]);
     1185            i, zone_in_use(i) ? "" : "not ", zone_count[i]);
    11751186    }
    11761187}
     
    12421253    else if (OPT_repair)
    12431254        printf("Filesystem on %s is dirty, needs checking\n",
    1244                device_name);
     1255            device_name);
    12451256
    12461257    read_tables();
     
    12691280                free_cnt++;
    12701281        printf("\n%6u inodes used (%u%%)\n", (INODES - free_cnt),
    1271                100 * (INODES - free_cnt) / INODES);
     1282            100 * (INODES - free_cnt) / INODES);
    12721283        for (i = FIRSTZONE, free_cnt = 0; i < ZONES; i++)
    12731284            if (!zone_in_use(i))
    12741285                free_cnt++;
    12751286        printf("%6u zones used (%u%%)\n\n"
    1276                "%6u regular files\n"
    1277                "%6u directories\n"
    1278                "%6u character device files\n"
    1279                "%6u block device files\n"
    1280                "%6u links\n"
    1281                "%6u symbolic links\n"
    1282                "------\n"
    1283                "%6u files\n",
    1284                (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES,
    1285                regular, directory, chardev, blockdev,
    1286                links - 2 * directory + 1, symlinks,
    1287                total - 2 * directory + 1);
     1287            "%6u regular files\n"
     1288            "%6u directories\n"
     1289            "%6u character device files\n"
     1290            "%6u block device files\n"
     1291            "%6u links\n"
     1292            "%6u symbolic links\n"
     1293            "------\n"
     1294            "%6u files\n",
     1295            (ZONES - free_cnt), 100 * (ZONES - free_cnt) / ZONES,
     1296            regular, directory, chardev, blockdev,
     1297            links - 2 * directory + 1, symlinks,
     1298            total - 2 * directory + 1);
    12881299    }
    12891300    if (changed) {
  • branches/3.2/mindi-busybox/util-linux/getopt.c

    r2725 r3232  
    2626 *     <misiek@misiek.eu.org>)
    2727 * Ported to Busybox - Alfred M. Szmidt <ams@trillian.itslinux.org>
    28  *  Removed --version/-V and --help/-h in
     28 *  Removed --version/-V and --help/-h
    2929 *  Removed parse_error(), using bb_error_msg() from Busybox instead
    3030 *  Replaced our_malloc with xmalloc and our_realloc with xrealloc
     
    3232 */
    3333
    34 #include <getopt.h>
     34//usage:#define getopt_trivial_usage
     35//usage:       "[OPTIONS] [--] OPTSTRING PARAMS"
     36//usage:#define getopt_full_usage "\n\n"
     37//usage:    IF_LONG_OPTS(
     38//usage:       "    -a,--alternative        Allow long options starting with single -"
     39//usage:     "\n    -l,--longoptions=LOPT[,...] Long options to be recognized"
     40//usage:     "\n    -n,--name=PROGNAME      The name under which errors are reported"
     41//usage:     "\n    -o,--options=OPTSTRING      Short options to be recognized"
     42//usage:     "\n    -q,--quiet          Disable error reporting by getopt(3)"
     43//usage:     "\n    -Q,--quiet-output       No normal output"
     44//usage:     "\n    -s,--shell=SHELL        Set shell quoting conventions"
     45//usage:     "\n    -T,--test           Test for getopt(1) version"
     46//usage:     "\n    -u,--unquoted           Don't quote the output"
     47//usage:    )
     48//usage:    IF_NOT_LONG_OPTS(
     49//usage:       "    -a      Allow long options starting with single -"
     50//usage:     "\n    -l LOPT[,...]   Long options to be recognized"
     51//usage:     "\n    -n PROGNAME The name under which errors are reported"
     52//usage:     "\n    -o OPTSTRING    Short options to be recognized"
     53//usage:     "\n    -q      Disable error reporting by getopt(3)"
     54//usage:     "\n    -Q      No normal output"
     55//usage:     "\n    -s SHELL    Set shell quoting conventions"
     56//usage:     "\n    -T      Test for getopt(1) version"
     57//usage:     "\n    -u      Don't quote the output"
     58//usage:    )
     59//usage:     "\n"
     60//usage:     "\nExample:"
     61//usage:     "\n"
     62//usage:     "\nO=`getopt -l bb: -- ab:c:: \"$@\"` || exit 1"
     63//usage:     "\neval set -- \"$O\""
     64//usage:     "\nwhile true; do"
     65//usage:     "\n    case \"$1\" in"
     66//usage:     "\n    -a) echo A; shift;;"
     67//usage:     "\n    -b|--bb) echo \"B:'$2'\"; shift 2;;"
     68//usage:     "\n    -c) case \"$2\" in"
     69//usage:     "\n        \"\")   echo C; shift 2;;"
     70//usage:     "\n        *)  echo \"C:'$2'\"; shift 2;;"
     71//usage:     "\n        esac;;"
     72//usage:     "\n    --) shift; break;;"
     73//usage:     "\n    *)  echo Error; exit 1;;"
     74//usage:     "\n    esac"
     75//usage:     "\ndone"
     76//usage:
     77//usage:#define getopt_example_usage
     78//usage:       "$ cat getopt.test\n"
     79//usage:       "#!/bin/sh\n"
     80//usage:       "GETOPT=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \\\n"
     81//usage:       "       -n 'example.busybox' -- \"$@\"`\n"
     82//usage:       "if [ $? != 0 ]; then exit 1; fi\n"
     83//usage:       "eval set -- \"$GETOPT\"\n"
     84//usage:       "while true; do\n"
     85//usage:       " case $1 in\n"
     86//usage:       "   -a|--a-long) echo \"Option a\"; shift;;\n"
     87//usage:       "   -b|--b-long) echo \"Option b, argument '$2'\"; shift 2;;\n"
     88//usage:       "   -c|--c-long)\n"
     89//usage:       "     case \"$2\" in\n"
     90//usage:       "       \"\") echo \"Option c, no argument\"; shift 2;;\n"
     91//usage:       "       *)  echo \"Option c, argument '$2'\"; shift 2;;\n"
     92//usage:       "     esac;;\n"
     93//usage:       "   --) shift; break;;\n"
     94//usage:       "   *) echo \"Internal error!\"; exit 1;;\n"
     95//usage:       " esac\n"
     96//usage:       "done\n"
     97
     98#if ENABLE_FEATURE_GETOPT_LONG
     99# include <getopt.h>
     100#endif
    35101#include "libbb.h"
    36102
     
    291357int getopt_main(int argc, char **argv)
    292358{
     359    int n;
    293360    char *optstr = NULL;
    294361    char *name = NULL;
     
    303370    compatible = getenv("GETOPT_COMPATIBLE"); /* used as yes/no flag */
    304371
    305     if (argc == 1) {
     372    if (!argv[1]) {
    306373        if (compatible) {
    307374            /* For some reason, the original getopt gave no error
    308                when there were no arguments. */
     375             * when there were no arguments. */
    309376            printf(" --\n");
    310377            return 0;
     
    314381
    315382    if (argv[1][0] != '-' || compatible) {
    316         char *s;
     383        char *s = argv[1];
    317384
    318385        option_mask32 |= OPT_u; /* quoting off */
    319         s = xstrdup(argv[1] + strspn(argv[1], "-+"));
     386        s = xstrdup(s + strspn(s, "-+"));
    320387        argv[1] = argv[0];
    321388        return generate_output(argv+1, argc-1, s, long_options);
     
    344411
    345412    /* All options controlling the applet have now been parsed */
     413    n = optind - 1;
    346414    if (!optstr) {
    347         if (optind >= argc)
     415        optstr = argv[++n];
     416        if (!optstr)
    348417            bb_error_msg_and_die("missing optstring argument");
    349         optstr = argv[optind++];
    350     }
    351 
    352     argv[optind-1] = name ? name : argv[0];
    353     return generate_output(argv+optind-1, argc-optind+1, optstr, long_options);
     418    }
     419
     420    argv[n] = name ? name : argv[0];
     421    return generate_output(argv + n, argc - n, optstr, long_options);
    354422}
  • branches/3.2/mindi-busybox/util-linux/hexdump.c

    r2725 r3232  
    99 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1010 */
     11
     12//usage:#define hexdump_trivial_usage
     13//usage:       "[-bcCdefnosvx" IF_FEATURE_HEXDUMP_REVERSE("R") "] [FILE]..."
     14//usage:#define hexdump_full_usage "\n\n"
     15//usage:       "Display FILEs (or stdin) in a user specified format\n"
     16//usage:     "\n    -b      One-byte octal display"
     17//usage:     "\n    -c      One-byte character display"
     18//usage:     "\n    -C      Canonical hex+ASCII, 16 bytes per line"
     19//usage:     "\n    -d      Two-byte decimal display"
     20//usage:     "\n    -e FORMAT_STRING"
     21//usage:     "\n    -f FORMAT_FILE"
     22//usage:     "\n    -n LENGTH   Interpret only LENGTH bytes of input"
     23//usage:     "\n    -o      Two-byte octal display"
     24//usage:     "\n    -s OFFSET   Skip OFFSET bytes"
     25//usage:     "\n    -v      Display all input data"
     26//usage:     "\n    -x      Two-byte hexadecimal display"
     27//usage:    IF_FEATURE_HEXDUMP_REVERSE(
     28//usage:     "\n    -R      Reverse of 'hexdump -Cv'")
     29//usage:
     30//usage:#define hd_trivial_usage
     31//usage:       "FILE..."
     32//usage:#define hd_full_usage "\n\n"
     33//usage:       "hd is an alias for hexdump -C"
    1134
    1235#include "libbb.h"
  • branches/3.2/mindi-busybox/util-linux/hwclock.c

    r2725 r3232  
    4444            rtc_read_tm(&tm_time, fd);
    4545            gettimeofday(sys_tv, NULL);
    46             if (before != tm_time.tm_sec)
     46            if (before != (int)tm_time.tm_sec)
    4747                break;
    4848        }
     
    6161    struct timeval sys_tv;
    6262#endif
    63     time_t t;
    64     char *cp;
    65 
    66     t = read_rtc(pp_rtcname, &sys_tv, utc);
    67     cp = ctime(&t);
     63    time_t t = read_rtc(pp_rtcname, &sys_tv, utc);
     64
     65#if ENABLE_LOCALE_SUPPORT
     66    /* Standard hwclock uses locale-specific output format */
     67    char cp[64];
     68    struct tm *ptm = localtime(&t);
     69    strftime(cp, sizeof(cp), "%c", ptm);
     70#else
     71    char *cp = ctime(&t);
    6872    strchrnul(cp, '\n')[0] = '\0';
     73#endif
     74
    6975#if !SHOW_HWCLOCK_DIFF
    7076    printf("%s  0.000000 seconds\n", cp);
     
    7379        long diff = sys_tv.tv_sec - t;
    7480        if (diff < 0 /*&& tv.tv_usec != 0*/) {
    75             /* Why? */
    76             /* diff >= 0 is ok:   diff < 0, can't just use tv.tv_usec: */
    77             /*   45.520820          43.520820 */
    78             /* - 44.000000        - 45.000000 */
    79             /* =  1.520820        = -1.479180, not -2.520820! */
     81            /* Why we need diff++? */
     82            /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */
     83            /*   45.520820      |   43.520820 */
     84            /* - 44.000000      | - 45.000000 */
     85            /* =  1.520820      | = -1.479180, not -2.520820! */
    8086            diff++;
    81             /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
     87            /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */
    8288            sys_tv.tv_usec = 999999 - sys_tv.tv_usec;
    8389        }
     
    224230}
    225231
     232/*
     233 * At system boot, kernel may set system time from RTC,
     234 * but it knows nothing about timezones. If RTC is in local time,
     235 * then system time is wrong - it is offset by timezone.
     236 * This option corrects system time if RTC is in local time,
     237 * and (always) sets in-kernel timezone.
     238 *
     239 * This is an alternate option to --hctosys that does not read the
     240 * hardware clock.
     241 */
     242static void set_system_clock_timezone(int utc)
     243{
     244    struct timeval tv;
     245    struct tm *broken;
     246    struct timezone tz;
     247
     248    gettimeofday(&tv, NULL);
     249    broken = localtime(&tv.tv_sec);
     250    tz.tz_minuteswest = timezone / 60;
     251    if (broken->tm_isdst)
     252        tz.tz_minuteswest -= 60;
     253    tz.tz_dsttime = 0;
     254    gettimeofday(&tv, NULL);
     255    if (!utc)
     256        tv.tv_sec += tz.tz_minuteswest * 60;
     257    if (settimeofday(&tv, &tz))
     258        bb_perror_msg_and_die("settimeofday");
     259}
     260
     261//usage:#define hwclock_trivial_usage
     262//usage:    IF_FEATURE_HWCLOCK_LONG_OPTIONS(
     263//usage:       "[-r|--show] [-s|--hctosys] [-w|--systohc] [-t|--systz]"
     264//usage:       " [-l|--localtime] [-u|--utc]"
     265//usage:       " [-f|--rtc FILE]"
     266//usage:    )
     267//usage:    IF_NOT_FEATURE_HWCLOCK_LONG_OPTIONS(
     268//usage:       "[-r] [-s] [-w] [-t] [-l] [-u] [-f FILE]"
     269//usage:    )
     270//usage:#define hwclock_full_usage "\n\n"
     271//usage:       "Query and set hardware clock (RTC)\n"
     272//usage:     "\n    -r  Show hardware clock time"
     273//usage:     "\n    -s  Set system time from hardware clock"
     274//usage:     "\n    -w  Set hardware clock from system time"
     275//usage:     "\n    -t  Set in-kernel timezone, correct system time"
     276//usage:     "\n        if hardware clock is in local time"
     277//usage:     "\n    -u  Assume hardware clock is kept in UTC"
     278//usage:     "\n    -l  Assume hardware clock is kept in local time"
     279//usage:     "\n    -f FILE Use specified device (e.g. /dev/rtc2)"
     280
    226281#define HWCLOCK_OPT_LOCALTIME   0x01
    227282#define HWCLOCK_OPT_UTC         0x02
     
    229284#define HWCLOCK_OPT_HCTOSYS     0x08
    230285#define HWCLOCK_OPT_SYSTOHC     0x10
    231 #define HWCLOCK_OPT_RTCFILE     0x20
     286#define HWCLOCK_OPT_SYSTZ       0x20
     287#define HWCLOCK_OPT_RTCFILE     0x40
    232288
    233289int hwclock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    240296#if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS
    241297    static const char hwclock_longopts[] ALIGN1 =
    242         "localtime\0" No_argument "l"
     298        "localtime\0" No_argument "l" /* short opt is non-standard */
    243299        "utc\0"       No_argument "u"
    244300        "show\0"      No_argument "r"
    245301        "hctosys\0"   No_argument "s"
    246302        "systohc\0"   No_argument "w"
    247         "file\0"      Required_argument "f"
     303        "systz\0"     No_argument "t" /* short opt is non-standard */
     304        "rtc\0"       Required_argument "f"
    248305        ;
    249306    applet_long_options = hwclock_longopts;
    250307#endif
    251     opt_complementary = "r--ws:w--rs:s--wr:l--u:u--l";
    252     opt = getopt32(argv, "lurswf:", &rtcname);
     308    opt_complementary = "r--wst:w--rst:s--wrt:t--rsw:l--u:u--l";
     309    opt = getopt32(argv, "lurswtf:", &rtcname);
    253310
    254311    /* If -u or -l wasn't given check if we are using utc */
     
    262319    else if (opt & HWCLOCK_OPT_SYSTOHC)
    263320        from_sys_clock(&rtcname, utc);
     321    else if (opt & HWCLOCK_OPT_SYSTZ)
     322        set_system_clock_timezone(utc);
    264323    else
    265324        /* default HWCLOCK_OPT_SHOW */
  • branches/3.2/mindi-busybox/util-linux/ipcrm.c

    r2725 r3232  
    88 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 */
     10
     11//usage:#define ipcrm_trivial_usage
     12//usage:       "[-MQS key] [-mqs id]"
     13//usage:#define ipcrm_full_usage "\n\n"
     14//usage:       "Upper-case options MQS remove an object by shmkey value.\n"
     15//usage:       "Lower-case options remove an object by shmid value.\n"
     16//usage:     "\n    -mM Remove memory segment after last detach"
     17//usage:     "\n    -qQ Remove message queue"
     18//usage:     "\n    -sS Remove semaphore"
    1019
    1120#include "libbb.h"
     
    152161            /* convert key to id */
    153162            id = ((c == 'q') ? msgget(key, 0) :
    154                   (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0));
     163                (c == 'm') ? shmget(key, 0, 0) : semget(key, 0, 0));
    155164
    156165            if (id < 0) {
     
    181190
    182191        result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) :
    183                   (c == 'm') ? shmctl(id, IPC_RMID, NULL) :
    184                   semctl(id, 0, IPC_RMID, arg));
     192                (c == 'm') ? shmctl(id, IPC_RMID, NULL) :
     193                semctl(id, 0, IPC_RMID, arg));
    185194
    186195        if (result) {
  • branches/3.2/mindi-busybox/util-linux/ipcs.c

    r2725 r3232  
    99 */
    1010
     11//usage:#define ipcs_trivial_usage
     12//usage:       "[[-smq] -i shmid] | [[-asmq] [-tcplu]]"
     13//usage:#define ipcs_full_usage "\n\n"
     14//usage:       "    -i  Show specific resource"
     15//usage:     "\nResource specification:"
     16//usage:     "\n    -m  Shared memory segments"
     17//usage:     "\n    -q  Message queues"
     18//usage:     "\n    -s  Semaphore arrays"
     19//usage:     "\n    -a  All (default)"
     20//usage:     "\nOutput format:"
     21//usage:     "\n    -t  Time"
     22//usage:     "\n    -c  Creator"
     23//usage:     "\n    -p  Pid"
     24//usage:     "\n    -l  Limits"
     25//usage:     "\n    -u  Summary"
     26
    1127/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
    1228/* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
     
    4056struct shm_info {
    4157    int used_ids;
    42     ulong shm_tot;      /* total allocated shm */
    43     ulong shm_rss;      /* total resident shm */
    44     ulong shm_swp;      /* total swapped shm */
    45     ulong swap_attempts;
    46     ulong swap_successes;
     58    unsigned long shm_tot;      /* total allocated shm */
     59    unsigned long shm_rss;      /* total resident shm */
     60    unsigned long shm_swp;      /* total swapped shm */
     61    unsigned long swap_attempts;
     62    unsigned long swap_successes;
    4763};
    4864#endif
     
    137153            return;
    138154        /* glibc 2.1.3 and all earlier libc's have ints as fields
    139            of struct shminfo; glibc 2.1.91 has unsigned long; ach */
     155         * of struct shminfo; glibc 2.1.91 has unsigned long; ach */
    140156        printf("max number of segments = %lu\n"
    141                   "max seg size (kbytes) = %lu\n"
    142                   "max total shared memory (pages) = %lu\n"
    143                   "min seg size (bytes) = %lu\n",
    144                   (unsigned long) shminfo.shmmni,
    145                   (unsigned long) (shminfo.shmmax >> 10),
    146                   (unsigned long) shminfo.shmall,
    147                   (unsigned long) shminfo.shmmin);
     157                "max seg size (kbytes) = %lu\n"
     158                "max total shared memory (pages) = %lu\n"
     159                "min seg size (bytes) = %lu\n",
     160                (unsigned long) shminfo.shmmni,
     161                (unsigned long) (shminfo.shmmax >> 10),
     162                (unsigned long) shminfo.shmall,
     163                (unsigned long) shminfo.shmmin);
    148164        return;
    149165
    150166    case STATUS:
    151167        printf("------ Shared Memory %s --------\n", "Status");
    152         printf(   "segments allocated %d\n"
    153                   "pages allocated %ld\n"
    154                   "pages resident  %ld\n"
    155                   "pages swapped   %ld\n"
    156                   "Swap performance: %ld attempts\t%ld successes\n",
    157                   shm_info.used_ids,
    158                   shm_info.shm_tot,
    159                   shm_info.shm_rss,
    160                   shm_info.shm_swp,
    161                   shm_info.swap_attempts, shm_info.swap_successes);
     168        printf("segments allocated %d\n"
     169                "pages allocated %ld\n"
     170                "pages resident  %ld\n"
     171                "pages swapped   %ld\n"
     172                "Swap performance: %ld attempts\t%ld successes\n",
     173                shm_info.used_ids,
     174                shm_info.shm_tot,
     175                shm_info.shm_rss,
     176                shm_info.shm_swp,
     177                shm_info.swap_attempts, shm_info.swap_successes);
    162178        return;
    163179
    164180    case CREATOR:
    165181        printf("------ Shared Memory %s --------\n", "Segment Creators/Owners");
    166         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    167                   "shmid", "perms", "cuid", "cgid", "uid", "gid");
     182        printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
     183                "shmid", "perms", "cuid", "cgid", "uid", "gid");
    168184        break;
    169185
    170186    case TIME:
    171187        printf("------ Shared Memory %s --------\n", "Attach/Detach/Change Times");
    172         printf(   "%-10s %-10s %-20s %-20s %-20s\n",
    173                   "shmid", "owner", "attached", "detached", "changed");
     188        printf("%-10s %-10s %-20s %-20s %-20s\n",
     189                "shmid", "owner", "attached", "detached", "changed");
    174190        break;
    175191
    176192    case PID:
    177193        printf("------ Shared Memory %s --------\n", "Creator/Last-op");
    178         printf(   "%-10s %-10s %-10s %-10s\n",
    179                   "shmid", "owner", "cpid", "lpid");
     194        printf("%-10s %-10s %-10s %-10s\n",
     195                "shmid", "owner", "cpid", "lpid");
    180196        break;
    181197
    182198    default:
    183199        printf("------ Shared Memory %s --------\n", "Segments");
    184         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
    185                   "key", "shmid", "owner", "perms", "bytes", "nattch",
    186                   "status");
     200        printf("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
     201                "key", "shmid", "owner", "perms", "bytes", "nattch",
     202                "status");
    187203        break;
    188204    }
     
    205221            /* ctime uses static buffer: use separate calls */
    206222            printf(" %-20.16s", shmseg.shm_atime
    207                       ? ctime(&shmseg.shm_atime) + 4 : "Not set");
     223                    ? ctime(&shmseg.shm_atime) + 4 : "Not set");
    208224            printf(" %-20.16s", shmseg.shm_dtime
    209                       ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
     225                    ? ctime(&shmseg.shm_dtime) + 4 : "Not set");
    210226            printf(" %-20.16s\n", shmseg.shm_ctime
    211                       ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
     227                    ? ctime(&shmseg.shm_ctime) + 4 : "Not set");
    212228            break;
    213229        case PID:
     
    226242                printf("%-10d %-10d", shmid, ipcp->uid);
    227243            printf(" %-10o %-10lu %-10ld %-6s %-6s\n", ipcp->mode & 0777,
    228                       /*
    229                        * earlier: int, Austin has size_t
    230                        */
    231                       (unsigned long) shmseg.shm_segsz,
    232                       /*
    233                        * glibc-2.1.3 and earlier has unsigned short;
    234                        * Austin has shmatt_t
    235                        */
    236                       (long) shmseg.shm_nattch,
    237                       ipcp->mode & SHM_DEST ? "dest" : " ",
    238                       ipcp->mode & SHM_LOCKED ? "locked" : " ");
     244                    /*
     245                     * earlier: int, Austin has size_t
     246                     */
     247                    (unsigned long) shmseg.shm_segsz,
     248                    /*
     249                     * glibc-2.1.3 and earlier has unsigned short;
     250                     * Austin has shmatt_t
     251                     */
     252                    (long) shmseg.shm_nattch,
     253                    ipcp->mode & SHM_DEST ? "dest" : " ",
     254                    ipcp->mode & SHM_LOCKED ? "locked" : " ");
    239255            break;
    240256        }
     
    252268    union semun arg;
    253269
    254     arg.array = (ushort *) (void *) &seminfo;
     270    arg.array = (unsigned short *) (void *) &seminfo;
    255271    maxid = semctl(0, 0, SEM_INFO, arg);
    256272    if (maxid < 0) {
     
    262278    case LIMITS:
    263279        printf("------ Semaphore %s --------\n", "Limits");
    264         arg.array = (ushort *) (void *) &seminfo;   /* damn union */
     280        arg.array = (unsigned short *) (void *) &seminfo;   /* damn union */
    265281        if ((semctl(0, 0, IPC_INFO, arg)) < 0)
    266282            return;
    267283        printf("max number of arrays = %d\n"
    268                   "max semaphores per array = %d\n"
    269                   "max semaphores system wide = %d\n"
    270                   "max ops per semop call = %d\n"
    271                   "semaphore max value = %d\n",
    272                   seminfo.semmni,
    273                   seminfo.semmsl,
    274                   seminfo.semmns, seminfo.semopm, seminfo.semvmx);
     284                "max semaphores per array = %d\n"
     285                "max semaphores system wide = %d\n"
     286                "max ops per semop call = %d\n"
     287                "semaphore max value = %d\n",
     288                seminfo.semmni,
     289                seminfo.semmsl,
     290                seminfo.semmns, seminfo.semopm, seminfo.semvmx);
    275291        return;
    276292
    277293    case STATUS:
    278294        printf("------ Semaphore %s --------\n", "Status");
    279         printf(   "used arrays = %d\n"
    280                   "allocated semaphores = %d\n",
    281                   seminfo.semusz, seminfo.semaem);
     295        printf("used arrays = %d\n"
     296                "allocated semaphores = %d\n",
     297                seminfo.semusz, seminfo.semaem);
    282298        return;
    283299
    284300    case CREATOR:
    285301        printf("------ Semaphore %s --------\n", "Arrays Creators/Owners");
    286         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    287                   "semid", "perms", "cuid", "cgid", "uid", "gid");
     302        printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
     303                "semid", "perms", "cuid", "cgid", "uid", "gid");
    288304        break;
    289305
    290306    case TIME:
    291307        printf("------ Shared Memory %s --------\n", "Operation/Change Times");
    292         printf(   "%-8s %-10s %-26.24s %-26.24s\n",
    293                   "shmid", "owner", "last-op", "last-changed");
     308        printf("%-8s %-10s %-26.24s %-26.24s\n",
     309                "shmid", "owner", "last-op", "last-changed");
    294310        break;
    295311
     
    299315    default:
    300316        printf("------ Semaphore %s --------\n", "Arrays");
    301         printf(   "%-10s %-10s %-10s %-10s %-10s\n",
    302                   "key", "semid", "owner", "perms", "nsems");
     317        printf("%-10s %-10s %-10s %-10s %-10s\n",
     318                "key", "semid", "owner", "perms", "nsems");
    303319        break;
    304320    }
     
    322338            /* ctime uses static buffer: use separate calls */
    323339            printf("  %-26.24s", semary.sem_otime
    324                       ? ctime(&semary.sem_otime) : "Not set");
     340                    ? ctime(&semary.sem_otime) : "Not set");
    325341            printf(" %-26.24s\n", semary.sem_ctime
    326                       ? ctime(&semary.sem_ctime) : "Not set");
     342                    ? ctime(&semary.sem_ctime) : "Not set");
    327343            break;
    328344        case PID:
     
    336352                printf("%-10d %-9d", semid, ipcp->uid);
    337353            printf(" %-10o %-10ld\n", ipcp->mode & 0777,
    338                       /*
    339                        * glibc-2.1.3 and earlier has unsigned short;
    340                        * glibc-2.1.91 has variation between
    341                        * unsigned short and unsigned long
    342                        * Austin prescribes unsigned short.
    343                        */
    344                       (long) semary.sem_nsems);
     354                    /*
     355                     * glibc-2.1.3 and earlier has unsigned short;
     356                     * glibc-2.1.91 has variation between
     357                     * unsigned short and unsigned long
     358                     * Austin prescribes unsigned short.
     359                     */
     360                    (long) semary.sem_nsems);
    345361            break;
    346362        }
     
    368384            return;
    369385        printf("------ Message%s --------\n", "s: Limits");
    370         printf(   "max queues system wide = %d\n"
    371                   "max size of message (bytes) = %d\n"
    372                   "default max size of queue (bytes) = %d\n",
    373                   msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
     386        printf("max queues system wide = %d\n"
     387                "max size of message (bytes) = %d\n"
     388                "default max size of queue (bytes) = %d\n",
     389                msginfo.msgmni, msginfo.msgmax, msginfo.msgmnb);
    374390        return;
    375391
    376392    case STATUS:
    377393        printf("------ Message%s --------\n", "s: Status");
    378         printf(   "allocated queues = %d\n"
    379                   "used headers = %d\n"
    380                   "used space = %d bytes\n",
    381                   msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
     394        printf("allocated queues = %d\n"
     395                "used headers = %d\n"
     396                "used space = %d bytes\n",
     397                msginfo.msgpool, msginfo.msgmap, msginfo.msgtql);
    382398        return;
    383399
    384400    case CREATOR:
    385401        printf("------ Message%s --------\n", " Queues: Creators/Owners");
    386         printf(   "%-10s %-10s %-10s %-10s %-10s %-10s\n",
    387                   "msqid", "perms", "cuid", "cgid", "uid", "gid");
     402        printf("%-10s %-10s %-10s %-10s %-10s %-10s\n",
     403                "msqid", "perms", "cuid", "cgid", "uid", "gid");
    388404        break;
    389405
    390406    case TIME:
    391407        printf("------ Message%s --------\n", " Queues Send/Recv/Change Times");
    392         printf(   "%-8s %-10s %-20s %-20s %-20s\n",
    393                   "msqid", "owner", "send", "recv", "change");
     408        printf("%-8s %-10s %-20s %-20s %-20s\n",
     409                "msqid", "owner", "send", "recv", "change");
    394410        break;
    395411
    396412    case PID:
    397413        printf("------ Message%s --------\n", " Queues PIDs");
    398         printf(   "%-10s %-10s %-10s %-10s\n",
    399                   "msqid", "owner", "lspid", "lrpid");
     414        printf("%-10s %-10s %-10s %-10s\n",
     415                "msqid", "owner", "lspid", "lrpid");
    400416        break;
    401417
    402418    default:
    403419        printf("------ Message%s --------\n", " Queues");
    404         printf(   "%-10s %-10s %-10s %-10s %-12s %-12s\n",
    405                   "key", "msqid", "owner", "perms", "used-bytes", "messages");
     420        printf("%-10s %-10s %-10s %-10s %-12s %-12s\n",
     421                "key", "msqid", "owner", "perms", "used-bytes", "messages");
    406422        break;
    407423    }
     
    423439                printf("%-8d %-10d", msqid, ipcp->uid);
    424440            printf(" %-20.16s", msgque.msg_stime
    425                       ? ctime(&msgque.msg_stime) + 4 : "Not set");
     441                    ? ctime(&msgque.msg_stime) + 4 : "Not set");
    426442            printf(" %-20.16s", msgque.msg_rtime
    427                       ? ctime(&msgque.msg_rtime) + 4 : "Not set");
     443                    ? ctime(&msgque.msg_rtime) + 4 : "Not set");
    428444            printf(" %-20.16s\n", msgque.msg_ctime
    429                       ? ctime(&msgque.msg_ctime) + 4 : "Not set");
     445                    ? ctime(&msgque.msg_ctime) + 4 : "Not set");
    430446            break;
    431447        case PID:
     
    444460                printf("%-10d %-10d", msqid, ipcp->uid);
    445461            printf(" %-10o %-12ld %-12ld\n", ipcp->mode & 0777,
    446                       /*
    447                        * glibc-2.1.3 and earlier has unsigned short;
    448                        * glibc-2.1.91 has variation between
    449                        * unsigned short, unsigned long
    450                        * Austin has msgqnum_t
    451                        */
    452                       (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
     462                    /*
     463                     * glibc-2.1.3 and earlier has unsigned short;
     464                     * glibc-2.1.91 has variation between
     465                     * unsigned short, unsigned long
     466                     * Austin has msgqnum_t
     467                     */
     468                    (long) msgque.msg_cbytes, (long) msgque.msg_qnum);
    453469            break;
    454470        }
     
    468484
    469485    printf("\nShared memory Segment shmid=%d\n"
    470               "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
    471               "mode=%#o\taccess_perms=%#o\n"
    472               "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
    473               shmid,
    474               ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
    475               ipcp->mode, ipcp->mode & 0777,
    476               (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
    477               (long) shmds.shm_nattch);
     486            "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"
     487            "mode=%#o\taccess_perms=%#o\n"
     488            "bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n",
     489            shmid,
     490            ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
     491            ipcp->mode, ipcp->mode & 0777,
     492            (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
     493            (long) shmds.shm_nattch);
    478494    printf("att_time=%-26.24s\n",
    479               shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
     495            shmds.shm_atime ? ctime(&shmds.shm_atime) : "Not set");
    480496    printf("det_time=%-26.24s\n",
    481               shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
     497            shmds.shm_dtime ? ctime(&shmds.shm_dtime) : "Not set");
    482498    printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
    483499}
     
    495511
    496512    printf("\nMessage Queue msqid=%d\n"
    497               "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
    498               "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
    499               msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
    500               /*
    501                * glibc-2.1.3 and earlier has unsigned short;
    502                * glibc-2.1.91 has variation between
    503                * unsigned short, unsigned long
    504                * Austin has msgqnum_t (for msg_qbytes)
    505                */
    506               (long) buf.msg_cbytes, (long) buf.msg_qbytes,
    507               (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
     513            "uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"
     514            "cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n",
     515            msqid, ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode,
     516            /*
     517             * glibc-2.1.3 and earlier has unsigned short;
     518             * glibc-2.1.91 has variation between
     519             * unsigned short, unsigned long
     520             * Austin has msgqnum_t (for msg_qbytes)
     521             */
     522            (long) buf.msg_cbytes, (long) buf.msg_qbytes,
     523            (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
    508524
    509525    printf("send_time=%-26.24s\n",
    510               buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
     526            buf.msg_stime ? ctime(&buf.msg_stime) : "Not set");
    511527    printf("rcv_time=%-26.24s\n",
    512               buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
     528            buf.msg_rtime ? ctime(&buf.msg_rtime) : "Not set");
    513529    printf("change_time=%-26.24s\n\n",
    514               buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
     530            buf.msg_ctime ? ctime(&buf.msg_ctime) : "Not set");
    515531}
    516532
     
    529545
    530546    printf("\nSemaphore Array semid=%d\n"
    531               "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
    532               "mode=%#o, access_perms=%#o\n"
    533               "nsems = %ld\n"
    534               "otime = %-26.24s\n",
    535               semid,
    536               ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
    537               ipcp->mode, ipcp->mode & 0777,
    538               (long) semds.sem_nsems,
    539               semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
     547            "uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"
     548            "mode=%#o, access_perms=%#o\n"
     549            "nsems = %ld\n"
     550            "otime = %-26.24s\n",
     551            semid,
     552            ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid,
     553            ipcp->mode, ipcp->mode & 0777,
     554            (long) semds.sem_nsems,
     555            semds.sem_otime ? ctime(&semds.sem_otime) : "Not set");
    540556    printf("ctime = %-26.24s\n"
    541               "%-10s %-10s %-10s %-10s %-10s\n",
    542               ctime(&semds.sem_ctime),
    543               "semnum", "value", "ncount", "zcount", "pid");
     557            "%-10s %-10s %-10s %-10s %-10s\n",
     558            ctime(&semds.sem_ctime),
     559            "semnum", "value", "ncount", "zcount", "pid");
    544560
    545561    arg.val = 0;
  • branches/3.2/mindi-busybox/util-linux/losetup.c

    r2725 r3232  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     9
     10//usage:#define losetup_trivial_usage
     11//usage:       "[-r] [-o OFS] LOOPDEV FILE - associate loop devices\n"
     12//usage:       "    losetup -d LOOPDEV - disassociate\n"
     13//usage:       "    losetup [-f] - show"
     14//usage:#define losetup_full_usage "\n\n"
     15//usage:       "    -o OFS  Start OFS bytes into FILE"
     16//usage:     "\n    -r  Read-only"
     17//usage:     "\n    -f  Show first free loop device"
     18//usage:
     19//usage:#define losetup_notes_usage
     20//usage:       "No arguments will display all current associations.\n"
     21//usage:       "One argument (losetup /dev/loop1) will display the current association\n"
     22//usage:       "(if any), or disassociate it (with -d). The display shows the offset\n"
     23//usage:       "and filename of the file the loop device is currently bound to.\n\n"
     24//usage:       "Two arguments (losetup /dev/loop1 file.img) create a new association,\n"
     25//usage:       "with an optional offset (-o 12345). Encryption is not yet supported.\n"
     26//usage:       "losetup -f will show the first loop free loop device\n\n"
    927
    1028#include "libbb.h"
     
    2139        OPT_o = (1 << 1),
    2240        OPT_f = (1 << 2),
     41        OPT_r = (1 << 3), /* must be last */
    2342    };
    2443
    25     /* max 2 args, all opts are mutually exclusive */
     44    /* max 2 args, -d,-o,-f opts are mutually exclusive */
    2645    opt_complementary = "?2:d--of:o--df:f--do";
    27     opt = getopt32(argv, "do:f", &opt_o);
     46    opt = getopt32(argv, "do:fr", &opt_o);
    2847    argv += optind;
    2948
     
    4766
    4867        if (argv[1]) {
    49             /* [-o OFS] BLOCKDEV FILE */
    50             if (set_loop(&argv[0], argv[1], offset) < 0)
     68            /* [-r] [-o OFS] BLOCKDEV FILE */
     69            if (set_loop(&argv[0], argv[1], offset, (opt / OPT_r)) < 0)
    5170                bb_simple_perror_msg_and_die(argv[0]);
    5271            return EXIT_SUCCESS;
    5372        }
    54         /* [-o OFS] BLOCKDEV */
     73        /* [-r] [-o OFS] BLOCKDEV */
    5574        s = query_loop(argv[0]);
    5675        if (!s)
     
    6281    }
    6382
    64     /* [-o OFS|-f] with no params */
     83    /* [-r] [-o OFS|-f] with no params */
    6584    n = 0;
    6685    while (1) {
  • branches/3.2/mindi-busybox/util-linux/lspci.c

    r2725 r3232  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     9
     10//usage:#define lspci_trivial_usage
     11//usage:       "[-mk]"
     12//usage:#define lspci_full_usage "\n\n"
     13//usage:       "List all PCI devices"
     14//usage:     "\n"
     15//usage:     "\n    -m  Parsable output"
     16//usage:     "\n    -k  Show driver"
     17
    918#include "libbb.h"
    1019
     
    6675    if (option_mask32 & OPT_m) {
    6776        printf("%s \"Class %04x\" \"%04x\" \"%04x\" \"%04x\" \"%04x\"",
    68                pci_slot_name, pci_class, pci_vid, pci_did,
    69                pci_subsys_vid, pci_subsys_did);
     77            pci_slot_name, pci_class, pci_vid, pci_did,
     78            pci_subsys_vid, pci_subsys_did);
    7079    } else {
    7180        printf("%s Class %04x: %04x:%04x",
    72                pci_slot_name, pci_class, pci_vid, pci_did);
     81            pci_slot_name, pci_class, pci_vid, pci_did);
    7382    }
    7483
  • branches/3.2/mindi-busybox/util-linux/lsusb.c

    r2725 r3232  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     9
     10//usage:#define lsusb_trivial_usage NOUSAGE_STR
     11//usage:#define lsusb_full_usage ""
     12
    913#include "libbb.h"
    1014
  • branches/3.2/mindi-busybox/util-linux/mdev.c

    r2725 r3232  
    88 * Licensed under GPLv2, see file LICENSE in this source tree.
    99 */
     10
     11//config:config MDEV
     12//config:   bool "mdev"
     13//config:   default y
     14//config:   select PLATFORM_LINUX
     15//config:   help
     16//config:     mdev is a mini-udev implementation for dynamically creating device
     17//config:     nodes in the /dev directory.
     18//config:
     19//config:     For more information, please see docs/mdev.txt
     20//config:
     21//config:config FEATURE_MDEV_CONF
     22//config:   bool "Support /etc/mdev.conf"
     23//config:   default y
     24//config:   depends on MDEV
     25//config:   help
     26//config:     Add support for the mdev config file to control ownership and
     27//config:     permissions of the device nodes.
     28//config:
     29//config:     For more information, please see docs/mdev.txt
     30//config:
     31//config:config FEATURE_MDEV_RENAME
     32//config:   bool "Support subdirs/symlinks"
     33//config:   default y
     34//config:   depends on FEATURE_MDEV_CONF
     35//config:   help
     36//config:     Add support for renaming devices and creating symlinks.
     37//config:
     38//config:     For more information, please see docs/mdev.txt
     39//config:
     40//config:config FEATURE_MDEV_RENAME_REGEXP
     41//config:   bool "Support regular expressions substitutions when renaming device"
     42//config:   default y
     43//config:   depends on FEATURE_MDEV_RENAME
     44//config:   help
     45//config:     Add support for regular expressions substitutions when renaming
     46//config:     device.
     47//config:
     48//config:config FEATURE_MDEV_EXEC
     49//config:   bool "Support command execution at device addition/removal"
     50//config:   default y
     51//config:   depends on FEATURE_MDEV_CONF
     52//config:   help
     53//config:     This adds support for an optional field to /etc/mdev.conf for
     54//config:     executing commands when devices are created/removed.
     55//config:
     56//config:     For more information, please see docs/mdev.txt
     57//config:
     58//config:config FEATURE_MDEV_LOAD_FIRMWARE
     59//config:   bool "Support loading of firmwares"
     60//config:   default y
     61//config:   depends on MDEV
     62//config:   help
     63//config:     Some devices need to load firmware before they can be usable.
     64//config:
     65//config:     These devices will request userspace look up the files in
     66//config:     /lib/firmware/ and if it exists, send it to the kernel for
     67//config:     loading into the hardware.
     68
     69//applet:IF_MDEV(APPLET(mdev, BB_DIR_SBIN, BB_SUID_DROP))
     70
     71//kbuild:lib-$(CONFIG_MDEV) += mdev.o
     72
     73//usage:#define mdev_trivial_usage
     74//usage:       "[-s]"
     75//usage:#define mdev_full_usage "\n\n"
     76//usage:       "mdev -s is to be run during boot to scan /sys and populate /dev.\n"
     77//usage:       "\n"
     78//usage:       "Bare mdev is a kernel hotplug helper. To activate it:\n"
     79//usage:       "    echo /sbin/mdev >/proc/sys/kernel/hotplug\n"
     80//usage:    IF_FEATURE_MDEV_CONF(
     81//usage:       "\n"
     82//usage:       "It uses /etc/mdev.conf with lines\n"
     83//usage:       "    [-][ENV=regex;]...DEVNAME UID:GID PERM"
     84//usage:            IF_FEATURE_MDEV_RENAME(" [>|=PATH]|[!]")
     85//usage:            IF_FEATURE_MDEV_EXEC(" [@|$|*PROG]")
     86//usage:       "\n"
     87//usage:       "where DEVNAME is device name regex, @major,minor[-minor2], or\n"
     88//usage:       "environment variable regex. A common use of the latter is\n"
     89//usage:       "to load modules for hotplugged devices:\n"
     90//usage:       "    $MODALIAS=.* 0:0 660 @modprobe \"$MODALIAS\"\n"
     91//usage:    )
     92//usage:       "\n"
     93//usage:       "If /dev/mdev.seq file exists, mdev will wait for its value\n"
     94//usage:       "to match $SEQNUM variable. This prevents plug/unplug races.\n"
     95//usage:       "To activate this feature, create empty /dev/mdev.seq at boot.\n"
     96//usage:       "\n"
     97//usage:       "If /dev/mdev.log file exists, debug log will be appended to it."
     98
    1099#include "libbb.h"
    11100#include "xregex.h"
     
    28117 *
    29118 * If /etc/mdev.conf exists, it may modify /dev/device_name's properties.
    30  * /etc/mdev.conf file format:
    31  *
    32  * [-][subsystem/]device  user:grp  mode  [>|=path] [@|$|*command args...]
    33  * [-]@maj,min[-min2]     user:grp  mode  [>|=path] [@|$|*command args...]
    34  * [-]$envvar=val         user:grp  mode  [>|=path] [@|$|*command args...]
    35119 *
    36120 * Leading minus in 1st field means "don't stop on this line", otherwise
    37121 * search is stopped after the matching line is encountered.
    38122 *
    39  * The device name or "subsystem/device" combo is matched against 1st field
    40  * (which is a regex), or maj,min is matched against 1st field,
    41  * or specified environment variable (as regex) is matched against 1st field.
    42  *
    43  * $envvar=val format is useful for loading modules for hot-plugged devices
     123 * $envvar=regex format is useful for loading modules for hot-plugged devices
    44124 * which do not have driver loaded yet. In this case /sys/class/.../dev
    45125 * does not exist, but $MODALIAS is set to needed module's name
     
    62142 */
    63143
     144/* Kernel's hotplug environment constantly changes.
     145 * Here are new cases I observed on 3.1.0:
     146 *
     147 * Case with $DEVNAME and $DEVICE, not just $DEVPATH:
     148 * ACTION=add
     149 * BUSNUM=001
     150 * DEVICE=/proc/bus/usb/001/003
     151 * DEVNAME=bus/usb/001/003
     152 * DEVNUM=003
     153 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5
     154 * DEVTYPE=usb_device
     155 * MAJOR=189
     156 * MINOR=2
     157 * PRODUCT=18d1/4e12/227
     158 * SUBSYSTEM=usb
     159 * TYPE=0/0/0
     160 *
     161 * Case with $DEVICE, but no $DEVNAME - apparenty, usb iface notification?
     162 * "Please load me a module" thing?
     163 * ACTION=add
     164 * DEVICE=/proc/bus/usb/001/003
     165 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0
     166 * DEVTYPE=usb_interface
     167 * INTERFACE=8/6/80
     168 * MODALIAS=usb:v18D1p4E12d0227dc00dsc00dp00ic08isc06ip50
     169 * PRODUCT=18d1/4e12/227
     170 * SUBSYSTEM=usb
     171 * TYPE=0/0/0
     172 *
     173 * ACTION=add
     174 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5
     175 * DEVTYPE=scsi_host
     176 * SUBSYSTEM=scsi
     177 *
     178 * ACTION=add
     179 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/scsi_host/host5
     180 * SUBSYSTEM=scsi_host
     181 *
     182 * ACTION=add
     183 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0
     184 * DEVTYPE=scsi_target
     185 * SUBSYSTEM=scsi
     186 *
     187 * Case with strange $MODALIAS:
     188 * ACTION=add
     189 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0
     190 * DEVTYPE=scsi_device
     191 * MODALIAS=scsi:t-0x00
     192 * SUBSYSTEM=scsi
     193 *
     194 * ACTION=add
     195 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0
     196 * SUBSYSTEM=scsi_disk
     197 *
     198 * ACTION=add
     199 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/scsi_device/5:0:0:0
     200 * SUBSYSTEM=scsi_device
     201 *
     202 * Case with explicit $MAJOR/$MINOR (no need to read /sys/$DEVPATH/dev?):
     203 * ACTION=add
     204 * DEVNAME=bsg/5:0:0:0
     205 * DEVPATH=/devices/pci0000:00/0000:00:02.1/usb1/1-5/1-5:1.0/host5/target5:0:0/5:0:0:0/bsg/5:0:0:0
     206 * MAJOR=253
     207 * MINOR=1
     208 * SUBSYSTEM=bsg
     209 *
     210 * ACTION=add
     211 * DEVPATH=/devices/virtual/bdi/8:16
     212 * SUBSYSTEM=bdi
     213 *
     214 * ACTION=add
     215 * DEVNAME=sdb
     216 * DEVPATH=/block/sdb
     217 * DEVTYPE=disk
     218 * MAJOR=8
     219 * MINOR=16
     220 * SUBSYSTEM=block
     221 *
     222 * Case with ACTION=change:
     223 * ACTION=change
     224 * DEVNAME=sdb
     225 * DEVPATH=/block/sdb
     226 * DEVTYPE=disk
     227 * DISK_MEDIA_CHANGE=1
     228 * MAJOR=8
     229 * MINOR=16
     230 * SUBSYSTEM=block
     231 */
     232
     233#define DEBUG_LVL 2
     234
     235#if DEBUG_LVL >= 1
     236# define dbg1(...) do { if (G.verbose) bb_error_msg(__VA_ARGS__); } while(0)
     237#else
     238# define dbg1(...) ((void)0)
     239#endif
     240#if DEBUG_LVL >= 2
     241# define dbg2(...) do { if (G.verbose >= 2) bb_error_msg(__VA_ARGS__); } while(0)
     242#else
     243# define dbg2(...) ((void)0)
     244#endif
     245#if DEBUG_LVL >= 3
     246# define dbg3(...) do { if (G.verbose >= 3) bb_error_msg(__VA_ARGS__); } while(0)
     247#else
     248# define dbg3(...) ((void)0)
     249#endif
     250
     251
     252static const char keywords[] ALIGN1 = "add\0remove\0"; // "change\0"
     253enum { OP_add, OP_remove };
     254
     255struct envmatch {
     256    struct envmatch *next;
     257    char *envname;
     258    regex_t match;
     259};
     260
     261struct rule {
     262    bool keep_matching;
     263    bool regex_compiled;
     264    mode_t mode;
     265    int maj, min0, min1;
     266    struct bb_uidgid_t ugid;
     267    char *envvar;
     268    char *ren_mov;
     269    IF_FEATURE_MDEV_EXEC(char *r_cmd;)
     270    regex_t match;
     271    struct envmatch *envmatch;
     272};
     273
    64274struct globals {
    65275    int root_major, root_minor;
     276    smallint verbose;
    66277    char *subsystem;
     278    char *subsys_env; /* for putenv("SUBSYSTEM=subsystem") */
     279#if ENABLE_FEATURE_MDEV_CONF
     280    const char *filename;
     281    parser_t *parser;
     282    struct rule **rule_vec;
     283    unsigned rule_idx;
     284#endif
     285    struct rule cur_rule;
     286    char timestr[sizeof("60.123456")];
    67287} FIX_ALIASING;
    68288#define G (*(struct globals*)&bb_common_bufsiz1)
     289#define INIT_G() do { \
     290    IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \
     291    IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \
     292} while (0)
     293
    69294
    70295/* Prevent infinite loops in /sys symlinks */
    71296#define MAX_SYSFS_DEPTH 3
    72297
    73 /* We use additional 64+ bytes in make_device() */
    74 #define SCRATCH_SIZE 80
     298/* We use additional bytes in make_device() */
     299#define SCRATCH_SIZE 128
     300
     301#if ENABLE_FEATURE_MDEV_CONF
     302
     303static void make_default_cur_rule(void)
     304{
     305    memset(&G.cur_rule, 0, sizeof(G.cur_rule));
     306    G.cur_rule.maj = -1; /* "not a @major,minor rule" */
     307    G.cur_rule.mode = 0660;
     308}
     309
     310static void clean_up_cur_rule(void)
     311{
     312    struct envmatch *e;
     313
     314    free(G.cur_rule.envvar);
     315    free(G.cur_rule.ren_mov);
     316    if (G.cur_rule.regex_compiled)
     317        regfree(&G.cur_rule.match);
     318    IF_FEATURE_MDEV_EXEC(free(G.cur_rule.r_cmd);)
     319    e = G.cur_rule.envmatch;
     320    while (e) {
     321        free(e->envname);
     322        regfree(&e->match);
     323        e = e->next;
     324    }
     325    make_default_cur_rule();
     326}
     327
     328/* In later versions, endofname is in libbb */
     329#define endofname mdev_endofname
     330static
     331const char* FAST_FUNC
     332endofname(const char *name)
     333{
     334#define is_name(c)      ((c) == '_' || isalpha((unsigned char)(c)))
     335#define is_in_name(c)   ((c) == '_' || isalnum((unsigned char)(c)))
     336    if (!is_name(*name))
     337        return name;
     338    while (*++name) {
     339        if (!is_in_name(*name))
     340            break;
     341    }
     342    return name;
     343}
     344
     345static char *parse_envmatch_pfx(char *val)
     346{
     347    struct envmatch **nextp = &G.cur_rule.envmatch;
     348
     349    for (;;) {
     350        struct envmatch *e;
     351        char *semicolon;
     352        char *eq = strchr(val, '=');
     353        if (!eq /* || eq == val? */)
     354            return val;
     355        if (endofname(val) != eq)
     356            return val;
     357        semicolon = strchr(eq, ';');
     358        if (!semicolon)
     359            return val;
     360        /* ENVVAR=regex;... */
     361        *nextp = e = xzalloc(sizeof(*e));
     362        nextp = &e->next;
     363        e->envname = xstrndup(val, eq - val);
     364        *semicolon = '\0';
     365        xregcomp(&e->match, eq + 1, REG_EXTENDED);
     366        *semicolon = ';';
     367        val = semicolon + 1;
     368    }
     369}
     370
     371static void parse_next_rule(void)
     372{
     373    /* Note: on entry, G.cur_rule is set to default */
     374    while (1) {
     375        char *tokens[4];
     376        char *val;
     377
     378        /* No PARSE_EOL_COMMENTS, because command may contain '#' chars */
     379        if (!config_read(G.parser, tokens, 4, 3, "# \t", PARSE_NORMAL & ~PARSE_EOL_COMMENTS))
     380            break;
     381
     382        /* Fields: [-]regex uid:gid mode [alias] [cmd] */
     383        dbg3("token1:'%s'", tokens[1]);
     384
     385        /* 1st field */
     386        val = tokens[0];
     387        G.cur_rule.keep_matching = ('-' == val[0]);
     388        val += G.cur_rule.keep_matching; /* swallow leading dash */
     389        val = parse_envmatch_pfx(val);
     390        if (val[0] == '@') {
     391            /* @major,minor[-minor2] */
     392            /* (useful when name is ambiguous:
     393             * "/sys/class/usb/lp0" and
     394             * "/sys/class/printer/lp0")
     395             */
     396            int sc = sscanf(val, "@%u,%u-%u", &G.cur_rule.maj, &G.cur_rule.min0, &G.cur_rule.min1);
     397            if (sc < 2 || G.cur_rule.maj < 0) {
     398                bb_error_msg("bad @maj,min on line %d", G.parser->lineno);
     399                goto next_rule;
     400            }
     401            if (sc == 2)
     402                G.cur_rule.min1 = G.cur_rule.min0;
     403        } else {
     404            char *eq = strchr(val, '=');
     405            if (val[0] == '$') {
     406                /* $ENVVAR=regex ... */
     407                val++;
     408                if (!eq) {
     409                    bb_error_msg("bad $envvar=regex on line %d", G.parser->lineno);
     410                    goto next_rule;
     411                }
     412                G.cur_rule.envvar = xstrndup(val, eq - val);
     413                val = eq + 1;
     414            }
     415            xregcomp(&G.cur_rule.match, val, REG_EXTENDED);
     416            G.cur_rule.regex_compiled = 1;
     417        }
     418
     419        /* 2nd field: uid:gid - device ownership */
     420        if (get_uidgid(&G.cur_rule.ugid, tokens[1], /*allow_numeric:*/ 1) == 0) {
     421            bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno);
     422            goto next_rule;
     423        }
     424
     425        /* 3rd field: mode - device permissions */
     426        bb_parse_mode(tokens[2], &G.cur_rule.mode);
     427
     428        /* 4th field (opt): ">|=alias" or "!" to not create the node */
     429        val = tokens[3];
     430        if (ENABLE_FEATURE_MDEV_RENAME && val && strchr(">=!", val[0])) {
     431            char *s = skip_non_whitespace(val);
     432            G.cur_rule.ren_mov = xstrndup(val, s - val);
     433            val = skip_whitespace(s);
     434        }
     435
     436        if (ENABLE_FEATURE_MDEV_EXEC && val && val[0]) {
     437            const char *s = "$@*";
     438            const char *s2 = strchr(s, val[0]);
     439            if (!s2) {
     440                bb_error_msg("bad line %u", G.parser->lineno);
     441                goto next_rule;
     442            }
     443            IF_FEATURE_MDEV_EXEC(G.cur_rule.r_cmd = xstrdup(val);)
     444        }
     445
     446        return;
     447 next_rule:
     448        clean_up_cur_rule();
     449    } /* while (config_read) */
     450
     451    dbg3("config_close(G.parser)");
     452    config_close(G.parser);
     453    G.parser = NULL;
     454
     455    return;
     456}
     457
     458/* If mdev -s, we remember rules in G.rule_vec[].
     459 * Otherwise, there is no point in doing it, and we just
     460 * save only one parsed rule in G.cur_rule.
     461 */
     462static const struct rule *next_rule(void)
     463{
     464    struct rule *rule;
     465
     466    /* Open conf file if we didn't do it yet */
     467    if (!G.parser && G.filename) {
     468        dbg3("config_open('%s')", G.filename);
     469        G.parser = config_open2(G.filename, fopen_for_read);
     470        G.filename = NULL;
     471    }
     472
     473    if (G.rule_vec) {
     474        /* mdev -s */
     475        /* Do we have rule parsed already? */
     476        if (G.rule_vec[G.rule_idx]) {
     477            dbg3("< G.rule_vec[G.rule_idx:%d]=%p", G.rule_idx, G.rule_vec[G.rule_idx]);
     478            return G.rule_vec[G.rule_idx++];
     479        }
     480        make_default_cur_rule();
     481    } else {
     482        /* not mdev -s */
     483        clean_up_cur_rule();
     484    }
     485
     486    /* Parse one more rule if file isn't fully read */
     487    rule = &G.cur_rule;
     488    if (G.parser) {
     489        parse_next_rule();
     490        if (G.rule_vec) { /* mdev -s */
     491            rule = memcpy(xmalloc(sizeof(G.cur_rule)), &G.cur_rule, sizeof(G.cur_rule));
     492            G.rule_vec = xrealloc_vector(G.rule_vec, 4, G.rule_idx);
     493            G.rule_vec[G.rule_idx++] = rule;
     494            dbg3("> G.rule_vec[G.rule_idx:%d]=%p", G.rule_idx, G.rule_vec[G.rule_idx]);
     495        }
     496    }
     497
     498    return rule;
     499}
     500
     501static int env_matches(struct envmatch *e)
     502{
     503    while (e) {
     504        int r;
     505        char *val = getenv(e->envname);
     506        if (!val)
     507            return 0;
     508        r = regexec(&e->match, val, /*size*/ 0, /*range[]*/ NULL, /*eflags*/ 0);
     509        if (r != 0) /* no match */
     510            return 0;
     511        e = e->next;
     512    }
     513    return 1;
     514}
     515
     516#else
     517
     518# define next_rule() (&G.cur_rule)
     519
     520#endif
     521
     522static void mkdir_recursive(char *name)
     523{
     524    /* if name has many levels ("dir1/dir2"),
     525     * bb_make_directory() will create dir1 according to umask,
     526     * not according to its "mode" parameter.
     527     * Since we run with umask=0, need to temporarily switch it.
     528     */
     529    umask(022); /* "dir1" (if any) will be 0755 too */
     530    bb_make_directory(name, 0755, FILEUTILS_RECUR);
     531    umask(0);
     532}
    75533
    76534/* Builds an alias path.
     
    87545    if (dest) { /* ">bar/[baz]" ? */
    88546        *dest = '\0'; /* mkdir bar */
    89         bb_make_directory(alias, 0755, FILEUTILS_RECUR);
     547        mkdir_recursive(alias);
    90548        *dest = '/';
    91549        if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
     
    101559/* mknod in /dev based on a path like "/sys/block/hda/hda1"
    102560 * NB1: path parameter needs to have SCRATCH_SIZE scratch bytes
    103  * after NUL, but we promise to not mangle (IOW: to restore if needed)
     561 * after NUL, but we promise to not mangle (IOW: to restore NUL if needed)
    104562 * path string.
    105563 * NB2: "mdev -s" may call us many times, do not leak memory/fds!
     564 *
     565 * device_name = $DEVNAME (may be NULL)
     566 * path        = /sys/$DEVPATH
    106567 */
    107 static void make_device(char *path, int delete)
    108 {
    109     char *device_name, *subsystem_slash_devname;
     568static void make_device(char *device_name, char *path, int operation)
     569{
    110570    int major, minor, type, len;
    111     mode_t mode;
    112     parser_t *parser;
     571    char *path_end = path + strlen(path);
    113572
    114573    /* Try to read major/minor string.  Note that the kernel puts \n after
     
    118577     */
    119578    major = -1;
    120     if (!delete) {
    121         char *dev_maj_min = path + strlen(path);
    122 
    123         strcpy(dev_maj_min, "/dev");
    124         len = open_read_close(path, dev_maj_min + 1, 64);
    125         *dev_maj_min = '\0';
     579    if (operation == OP_add) {
     580        strcpy(path_end, "/dev");
     581        len = open_read_close(path, path_end + 1, SCRATCH_SIZE - 1);
     582        *path_end = '\0';
    126583        if (len < 1) {
    127584            if (!ENABLE_FEATURE_MDEV_EXEC)
     
    129586            /* no "dev" file, but we can still run scripts
    130587             * based on device name */
    131         } else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) != 2) {
     588        } else if (sscanf(path_end + 1, "%u:%u", &major, &minor) == 2) {
     589            dbg1("dev %u,%u", major, minor);
     590        } else {
    132591            major = -1;
    133592        }
     
    135594    /* else: for delete, -1 still deletes the node, but < -1 suppresses that */
    136595
    137     /* Determine device name, type, major and minor */
    138     device_name = (char*) bb_basename(path);
    139     /* http://kernel.org/doc/pending/hotplug.txt says that only
     596    /* Determine device name */
     597    if (!device_name) {
     598        /*
     599         * There was no $DEVNAME envvar (for example, mdev -s never has).
     600         * But it is very useful: it contains the *path*, not only basename,
     601         * Thankfully, uevent file has it.
     602         * Example of .../sound/card0/controlC0/uevent file on Linux-3.7.7:
     603         * MAJOR=116
     604         * MINOR=7
     605         * DEVNAME=snd/controlC0
     606         */
     607        strcpy(path_end, "/uevent");
     608        len = open_read_close(path, path_end + 1, SCRATCH_SIZE - 1);
     609        if (len < 0)
     610            len = 0;
     611        *path_end = '\0';
     612        path_end[1 + len] = '\0';
     613        device_name = strstr(path_end + 1, "\nDEVNAME=");
     614        if (device_name) {
     615            device_name += sizeof("\nDEVNAME=")-1;
     616            strchrnul(device_name, '\n')[0] = '\0';
     617        } else {
     618            /* Fall back to just basename */
     619            device_name = (char*) bb_basename(path);
     620        }
     621    }
     622    /* Determine device type */
     623    /*
     624     * http://kernel.org/doc/pending/hotplug.txt says that only
    140625     * "/sys/block/..." is for block devices. "/sys/bus" etc is not.
    141626     * But since 2.6.25 block devices are also in /sys/class/block.
    142      * We use strstr("/block/") to forestall future surprises. */
     627     * We use strstr("/block/") to forestall future surprises.
     628     */
    143629    type = S_IFCHR;
    144630    if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0))
    145631        type = S_IFBLK;
    146632
    147     /* Make path point to "subsystem/device_name" */
    148     subsystem_slash_devname = NULL;
    149     /* Check for coldplug invocations first */
    150     if (strncmp(path, "/sys/block/", 11) == 0) /* legacy case */
    151         path += sizeof("/sys/") - 1;
    152     else if (strncmp(path, "/sys/class/", 11) == 0)
    153         path += sizeof("/sys/class/") - 1;
    154     else {
    155         /* Example of a hotplug invocation:
    156          * SUBSYSTEM="block"
    157          * DEVPATH="/sys" + "/devices/virtual/mtd/mtd3/mtdblock3"
    158          * ("/sys" is added by mdev_main)
    159          * - path does not contain subsystem
     633#if ENABLE_FEATURE_MDEV_CONF
     634    G.rule_idx = 0; /* restart from the beginning (think mdev -s) */
     635#endif
     636    for (;;) {
     637        const char *str_to_match;
     638        regmatch_t off[1 + 9 * ENABLE_FEATURE_MDEV_RENAME_REGEXP];
     639        char *command;
     640        char *alias;
     641        char aliaslink = aliaslink; /* for compiler */
     642        char *node_name;
     643        const struct rule *rule;
     644
     645        str_to_match = device_name;
     646
     647        rule = next_rule();
     648
     649#if ENABLE_FEATURE_MDEV_CONF
     650        if (!env_matches(rule->envmatch))
     651            continue;
     652        if (rule->maj >= 0) {  /* @maj,min rule */
     653            if (major != rule->maj)
     654                continue;
     655            if (minor < rule->min0 || minor > rule->min1)
     656                continue;
     657            memset(off, 0, sizeof(off));
     658            goto rule_matches;
     659        }
     660        if (rule->envvar) { /* $envvar=regex rule */
     661            str_to_match = getenv(rule->envvar);
     662            dbg3("getenv('%s'):'%s'", rule->envvar, str_to_match);
     663            if (!str_to_match)
     664                continue;
     665        }
     666        /* else: str_to_match = device_name */
     667
     668        if (rule->regex_compiled) {
     669            int regex_match = regexec(&rule->match, str_to_match, ARRAY_SIZE(off), off, 0);
     670            dbg3("regex_match for '%s':%d", str_to_match, regex_match);
     671            //bb_error_msg("matches:");
     672            //for (int i = 0; i < ARRAY_SIZE(off); i++) {
     673            //  if (off[i].rm_so < 0) continue;
     674            //  bb_error_msg("match %d: '%.*s'\n", i,
     675            //      (int)(off[i].rm_eo - off[i].rm_so),
     676            //      device_name + off[i].rm_so);
     677            //}
     678
     679            if (regex_match != 0
     680            /* regexec returns whole pattern as "range" 0 */
     681             || off[0].rm_so != 0
     682             || (int)off[0].rm_eo != (int)strlen(str_to_match)
     683            ) {
     684                continue; /* this rule doesn't match */
     685            }
     686        }
     687        /* else: it's final implicit "match-all" rule */
     688 rule_matches:
     689        dbg2("rule matched, line %d", G.parser ? G.parser->lineno : -1);
     690#endif
     691        /* Build alias name */
     692        alias = NULL;
     693        if (ENABLE_FEATURE_MDEV_RENAME && rule->ren_mov) {
     694            aliaslink = rule->ren_mov[0];
     695            if (aliaslink == '!') {
     696                /* "!": suppress node creation/deletion */
     697                major = -2;
     698            }
     699            else if (aliaslink == '>' || aliaslink == '=') {
     700                if (ENABLE_FEATURE_MDEV_RENAME_REGEXP) {
     701                    char *s;
     702                    char *p;
     703                    unsigned n;
     704
     705                    /* substitute %1..9 with off[1..9], if any */
     706                    n = 0;
     707                    s = rule->ren_mov;
     708                    while (*s)
     709                        if (*s++ == '%')
     710                            n++;
     711
     712                    p = alias = xzalloc(strlen(rule->ren_mov) + n * strlen(str_to_match));
     713                    s = rule->ren_mov + 1;
     714                    while (*s) {
     715                        *p = *s;
     716                        if ('%' == *s) {
     717                            unsigned i = (s[1] - '0');
     718                            if (i <= 9 && off[i].rm_so >= 0) {
     719                                n = off[i].rm_eo - off[i].rm_so;
     720                                strncpy(p, str_to_match + off[i].rm_so, n);
     721                                p += n - 1;
     722                                s++;
     723                            }
     724                        }
     725                        p++;
     726                        s++;
     727                    }
     728                } else {
     729                    alias = xstrdup(rule->ren_mov + 1);
     730                }
     731            }
     732        }
     733        dbg3("alias:'%s'", alias);
     734
     735        command = NULL;
     736        IF_FEATURE_MDEV_EXEC(command = rule->r_cmd;)
     737        if (command) {
     738            /* Are we running this command now?
     739             * Run @cmd on create, $cmd on delete, *cmd on any
     740             */
     741            if ((command[0] == '@' && operation == OP_add)
     742             || (command[0] == '$' && operation == OP_remove)
     743             || (command[0] == '*')
     744            ) {
     745                command++;
     746            } else {
     747                command = NULL;
     748            }
     749        }
     750        dbg3("command:'%s'", command);
     751
     752        /* "Execute" the line we found */
     753        node_name = device_name;
     754        if (ENABLE_FEATURE_MDEV_RENAME && alias) {
     755            node_name = alias = build_alias(alias, device_name);
     756            dbg3("alias2:'%s'", alias);
     757        }
     758
     759        if (operation == OP_add && major >= 0) {
     760            char *slash = strrchr(node_name, '/');
     761            if (slash) {
     762                *slash = '\0';
     763                mkdir_recursive(node_name);
     764                *slash = '/';
     765            }
     766            if (ENABLE_FEATURE_MDEV_CONF) {
     767                dbg1("mknod %s (%d,%d) %o"
     768                    " %u:%u",
     769                    node_name, major, minor, rule->mode | type,
     770                    rule->ugid.uid, rule->ugid.gid
     771                );
     772            } else {
     773                dbg1("mknod %s (%d,%d) %o",
     774                    node_name, major, minor, rule->mode | type
     775                );
     776            }
     777            if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST)
     778                bb_perror_msg("can't create '%s'", node_name);
     779            if (ENABLE_FEATURE_MDEV_CONF) {
     780                chmod(node_name, rule->mode);
     781                chown(node_name, rule->ugid.uid, rule->ugid.gid);
     782            }
     783            if (major == G.root_major && minor == G.root_minor)
     784                symlink(node_name, "root");
     785            if (ENABLE_FEATURE_MDEV_RENAME && alias) {
     786                if (aliaslink == '>') {
     787//TODO: on devtmpfs, device_name already exists and symlink() fails.
     788//End result is that instead of symlink, we have two nodes.
     789//What should be done?
     790                    dbg1("symlink: %s", device_name);
     791                    symlink(node_name, device_name);
     792                }
     793            }
     794        }
     795
     796        if (ENABLE_FEATURE_MDEV_EXEC && command) {
     797            /* setenv will leak memory, use putenv/unsetenv/free */
     798            char *s = xasprintf("%s=%s", "MDEV", node_name);
     799            putenv(s);
     800            dbg1("running: %s", command);
     801            if (system(command) == -1)
     802                bb_perror_msg("can't run '%s'", command);
     803            bb_unsetenv_and_free(s);
     804        }
     805
     806        if (operation == OP_remove && major >= -1) {
     807            if (ENABLE_FEATURE_MDEV_RENAME && alias) {
     808                if (aliaslink == '>') {
     809                    dbg1("unlink: %s", device_name);
     810                    unlink(device_name);
     811                }
     812            }
     813            dbg1("unlink: %s", node_name);
     814            unlink(node_name);
     815        }
     816
     817        if (ENABLE_FEATURE_MDEV_RENAME)
     818            free(alias);
     819
     820        /* We found matching line.
     821         * Stop unless it was prefixed with '-'
    160822         */
    161         subsystem_slash_devname = concat_path_file(G.subsystem, device_name);
    162         path = subsystem_slash_devname;
    163     }
    164 
    165     /* If we have config file, look up user settings */
    166     if (ENABLE_FEATURE_MDEV_CONF)
    167         parser = config_open2("/etc/mdev.conf", fopen_for_read);
    168 
    169     do {
    170         int keep_matching;
    171         struct bb_uidgid_t ugid;
    172         char *tokens[4];
    173         char *command = NULL;
    174         char *alias = NULL;
    175         char aliaslink = aliaslink; /* for compiler */
    176 
    177         /* Defaults in case we won't match any line */
    178         ugid.uid = ugid.gid = 0;
    179         keep_matching = 0;
    180         mode = 0660;
    181 
    182         if (ENABLE_FEATURE_MDEV_CONF
    183          && config_read(parser, tokens, 4, 3, "# \t", PARSE_NORMAL)
    184         ) {
    185             char *val;
    186             char *str_to_match;
    187             regmatch_t off[1 + 9 * ENABLE_FEATURE_MDEV_RENAME_REGEXP];
    188 
    189             val = tokens[0];
    190             keep_matching = ('-' == val[0]);
    191             val += keep_matching; /* swallow leading dash */
    192 
    193             /* Match against either "subsystem/device_name"
    194              * or "device_name" alone */
    195             str_to_match = strchr(val, '/') ? path : device_name;
    196 
    197             /* Fields: regex uid:gid mode [alias] [cmd] */
    198 
    199             if (val[0] == '@') {
    200                 /* @major,minor[-minor2] */
    201                 /* (useful when name is ambiguous:
    202                  * "/sys/class/usb/lp0" and
    203                  * "/sys/class/printer/lp0") */
    204                 int cmaj, cmin0, cmin1, sc;
    205                 if (major < 0)
    206                     continue; /* no dev, no match */
    207                 sc = sscanf(val, "@%u,%u-%u", &cmaj, &cmin0, &cmin1);
    208                 if (sc < 1
    209                  || major != cmaj
    210                  || (sc == 2 && minor != cmin0)
    211                  || (sc == 3 && (minor < cmin0 || minor > cmin1))
    212                 ) {
    213                     continue; /* this line doesn't match */
    214                 }
    215                 goto line_matches;
    216             }
    217             if (val[0] == '$') {
    218                 /* regex to match an environment variable */
    219                 char *eq = strchr(++val, '=');
    220                 if (!eq)
    221                     continue;
    222                 *eq = '\0';
    223                 str_to_match = getenv(val);
    224                 if (!str_to_match)
    225                     continue;
    226                 str_to_match -= strlen(val) + 1;
    227                 *eq = '=';
    228             }
    229             /* else: regex to match [subsystem/]device_name */
    230 
    231             {
    232                 regex_t match;
    233                 int result;
    234 
    235                 xregcomp(&match, val, REG_EXTENDED);
    236                 result = regexec(&match, str_to_match, ARRAY_SIZE(off), off, 0);
    237                 regfree(&match);
    238                 //bb_error_msg("matches:");
    239                 //for (int i = 0; i < ARRAY_SIZE(off); i++) {
    240                 //  if (off[i].rm_so < 0) continue;
    241                 //  bb_error_msg("match %d: '%.*s'\n", i,
    242                 //      (int)(off[i].rm_eo - off[i].rm_so),
    243                 //      device_name + off[i].rm_so);
    244                 //}
    245 
    246                 /* If no match, skip rest of line */
    247                 /* (regexec returns whole pattern as "range" 0) */
    248                 if (result
    249                  || off[0].rm_so
    250                  || ((int)off[0].rm_eo != (int)strlen(str_to_match))
    251                 ) {
    252                     continue; /* this line doesn't match */
    253                 }
    254             }
    255  line_matches:
    256             /* This line matches. Stop parsing after parsing
    257              * the rest the line unless keep_matching == 1 */
    258 
    259             /* 2nd field: uid:gid - device ownership */
    260             if (get_uidgid(&ugid, tokens[1], 1) == 0)
    261                 bb_error_msg("unknown user/group %s on line %d", tokens[1], parser->lineno);
    262 
    263             /* 3rd field: mode - device permissions */
    264             bb_parse_mode(tokens[2], &mode);
    265 
    266             val = tokens[3];
    267             /* 4th field (opt): ">|=alias" or "!" to not create the node */
    268 
    269             if (ENABLE_FEATURE_MDEV_RENAME && val) {
    270                 char *a, *s, *st;
    271 
    272                 a = val;
    273                 s = strchrnul(val, ' ');
    274                 st = strchrnul(val, '\t');
    275                 if (st < s)
    276                     s = st;
    277                 st = (s[0] && s[1]) ? s+1 : NULL;
    278 
    279                 aliaslink = a[0];
    280                 if (aliaslink == '!' && s == a+1) {
    281                     val = st;
    282                     /* "!": suppress node creation/deletion */
    283                     major = -2;
    284                 }
    285                 else if (aliaslink == '>' || aliaslink == '=') {
    286                     val = st;
    287                     s[0] = '\0';
    288                     if (ENABLE_FEATURE_MDEV_RENAME_REGEXP) {
    289                         char *p;
    290                         unsigned i, n;
    291 
    292                         /* substitute %1..9 with off[1..9], if any */
    293                         n = 0;
    294                         s = a;
    295                         while (*s)
    296                             if (*s++ == '%')
    297                                 n++;
    298 
    299                         p = alias = xzalloc(strlen(a) + n * strlen(str_to_match));
    300                         s = a + 1;
    301                         while (*s) {
    302                             *p = *s;
    303                             if ('%' == *s) {
    304                                 i = (s[1] - '0');
    305                                 if (i <= 9 && off[i].rm_so >= 0) {
    306                                     n = off[i].rm_eo - off[i].rm_so;
    307                                     strncpy(p, str_to_match + off[i].rm_so, n);
    308                                     p += n - 1;
    309                                     s++;
    310                                 }
    311                             }
    312                             p++;
    313                             s++;
    314                         }
    315                     } else {
    316                         alias = xstrdup(a + 1);
    317                     }
    318                 }
    319             }
    320 
    321             if (ENABLE_FEATURE_MDEV_EXEC && val) {
    322                 const char *s = "$@*";
    323                 const char *s2 = strchr(s, val[0]);
    324 
    325                 if (!s2) {
    326                     bb_error_msg("bad line %u", parser->lineno);
    327                     if (ENABLE_FEATURE_MDEV_RENAME)
    328                         free(alias);
    329                     continue;
    330                 }
    331 
    332                 /* Are we running this command now?
    333                  * Run $cmd on delete, @cmd on create, *cmd on both
    334                  */
    335                 if (s2 - s != delete) {
    336                     /* We are here if: '*',
    337                      * or: '@' and delete = 0,
    338                      * or: '$' and delete = 1
    339                      */
    340                     command = xstrdup(val + 1);
    341                 }
    342             }
    343         }
    344 
    345         /* End of field parsing */
    346 
    347         /* "Execute" the line we found */
    348         {
    349             const char *node_name;
    350 
    351             node_name = device_name;
    352             if (ENABLE_FEATURE_MDEV_RENAME && alias)
    353                 node_name = alias = build_alias(alias, device_name);
    354 
    355             if (!delete && major >= 0) {
    356                 if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST)
    357                     bb_perror_msg("can't create '%s'", node_name);
    358                 if (major == G.root_major && minor == G.root_minor)
    359                     symlink(node_name, "root");
    360                 if (ENABLE_FEATURE_MDEV_CONF) {
    361                     chmod(node_name, mode);
    362                     chown(node_name, ugid.uid, ugid.gid);
    363                 }
    364                 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
    365                     if (aliaslink == '>')
    366                         symlink(node_name, device_name);
    367                 }
    368             }
    369 
    370             if (ENABLE_FEATURE_MDEV_EXEC && command) {
    371                 /* setenv will leak memory, use putenv/unsetenv/free */
    372                 char *s = xasprintf("%s=%s", "MDEV", node_name);
    373                 char *s1 = xasprintf("%s=%s", "SUBSYSTEM", G.subsystem);
    374                 putenv(s);
    375                 putenv(s1);
    376                 if (system(command) == -1)
    377                     bb_perror_msg("can't run '%s'", command);
    378                 bb_unsetenv_and_free(s1);
    379                 bb_unsetenv_and_free(s);
    380                 free(command);
    381             }
    382 
    383             if (delete && major >= -1) {
    384                 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
    385                     if (aliaslink == '>')
    386                         unlink(device_name);
    387                 }
    388                 unlink(node_name);
    389             }
    390 
    391             if (ENABLE_FEATURE_MDEV_RENAME)
    392                 free(alias);
    393         }
    394 
    395         /* We found matching line.
    396          * Stop unless it was prefixed with '-' */
    397         if (ENABLE_FEATURE_MDEV_CONF && !keep_matching)
     823        if (!ENABLE_FEATURE_MDEV_CONF || !rule->keep_matching)
    398824            break;
    399 
    400     /* end of "while line is read from /etc/mdev.conf" */
    401     } while (ENABLE_FEATURE_MDEV_CONF);
    402 
    403     if (ENABLE_FEATURE_MDEV_CONF)
    404         config_close(parser);
    405     free(subsystem_slash_devname);
     825    } /* for (;;) */
    406826}
    407827
     
    421841    strcpy(scratch, fileName);
    422842    scratch[len] = '\0';
    423     make_device(scratch, /*delete:*/ 0);
     843    make_device(/*DEVNAME:*/ NULL, scratch, OP_add);
    424844
    425845    return TRUE;
     
    436856    if (1 == depth) {
    437857        free(G.subsystem);
     858        if (G.subsys_env) {
     859            bb_unsetenv_and_free(G.subsys_env);
     860            G.subsys_env = NULL;
     861        }
    438862        G.subsystem = strrchr(fileName, '/');
    439         if (G.subsystem)
     863        if (G.subsystem) {
    440864            G.subsystem = xstrdup(G.subsystem + 1);
     865            G.subsys_env = xasprintf("%s=%s", "SUBSYSTEM", G.subsystem);
     866            putenv(G.subsys_env);
     867        }
    441868    }
    442869
     
    458885{
    459886    int cnt;
    460     int firmware_fd, loading_fd, data_fd;
     887    int firmware_fd, loading_fd;
    461888
    462889    /* check for /lib/firmware/$FIRMWARE */
    463890    xchdir("/lib/firmware");
    464     firmware_fd = xopen(firmware, O_RDONLY);
    465 
    466     /* in case we goto out ... */
    467     data_fd = -1;
     891    firmware_fd = open(firmware, O_RDONLY); /* can fail */
    468892
    469893    /* check for /sys/$DEVPATH/loading ... give 30 seconds to appear */
     
    471895    for (cnt = 0; cnt < 30; ++cnt) {
    472896        loading_fd = open("loading", O_WRONLY);
    473         if (loading_fd != -1)
     897        if (loading_fd >= 0)
    474898            goto loading;
    475899        sleep(1);
     
    478902
    479903 loading:
    480     /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */
    481     if (full_write(loading_fd, "1", 1) != 1)
    482         goto out;
    483 
    484     /* load firmware into /sys/$DEVPATH/data */
    485     data_fd = open("data", O_WRONLY);
    486     if (data_fd == -1)
    487         goto out;
    488     cnt = bb_copyfd_eof(firmware_fd, data_fd);
    489 
    490     /* tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading" */
     904    cnt = 0;
     905    if (firmware_fd >= 0) {
     906        int data_fd;
     907
     908        /* tell kernel we're loading by "echo 1 > /sys/$DEVPATH/loading" */
     909        if (full_write(loading_fd, "1", 1) != 1)
     910            goto out;
     911
     912        /* load firmware into /sys/$DEVPATH/data */
     913        data_fd = open("data", O_WRONLY);
     914        if (data_fd < 0)
     915            goto out;
     916        cnt = bb_copyfd_eof(firmware_fd, data_fd);
     917        if (ENABLE_FEATURE_CLEAN_UP)
     918            close(data_fd);
     919    }
     920
     921    /* Tell kernel result by "echo [0|-1] > /sys/$DEVPATH/loading"
     922     * Note: we emit -1 also if firmware file wasn't found.
     923     * There are cases when otherwise kernel would wait for minutes
     924     * before timing out.
     925     */
    491926    if (cnt > 0)
    492927        full_write(loading_fd, "0", 1);
     
    495930
    496931 out:
     932    xchdir("/dev");
    497933    if (ENABLE_FEATURE_CLEAN_UP) {
    498934        close(firmware_fd);
    499935        close(loading_fd);
    500         close(data_fd);
     936    }
     937}
     938
     939static char *curtime(void)
     940{
     941    struct timeval tv;
     942    gettimeofday(&tv, NULL);
     943    sprintf(G.timestr, "%u.%06u", (unsigned)tv.tv_sec % 60, (unsigned)tv.tv_usec);
     944    return G.timestr;
     945}
     946
     947static void open_mdev_log(const char *seq, unsigned my_pid)
     948{
     949    int logfd = open("mdev.log", O_WRONLY | O_APPEND);
     950    if (logfd >= 0) {
     951        xmove_fd(logfd, STDERR_FILENO);
     952        G.verbose = 2;
     953        applet_name = xasprintf("%s[%s]", applet_name, seq ? seq : utoa(my_pid));
     954    }
     955}
     956
     957/* If it exists, does /dev/mdev.seq match $SEQNUM?
     958 * If it does not match, earlier mdev is running
     959 * in parallel, and we need to wait.
     960 * Active mdev pokes us with SIGCHLD to check the new file.
     961 */
     962static int
     963wait_for_seqfile(const char *seq)
     964{
     965    /* We time out after 2 sec */
     966    static const struct timespec ts = { 0, 32*1000*1000 };
     967    int timeout = 2000 / 32;
     968    int seq_fd = -1;
     969    int do_once = 1;
     970    sigset_t set_CHLD;
     971
     972    sigemptyset(&set_CHLD);
     973    sigaddset(&set_CHLD, SIGCHLD);
     974    sigprocmask(SIG_BLOCK, &set_CHLD, NULL);
     975
     976    for (;;) {
     977        int seqlen;
     978        char seqbuf[sizeof(int)*3 + 2];
     979
     980        if (seq_fd < 0) {
     981            seq_fd = open("mdev.seq", O_RDWR);
     982            if (seq_fd < 0)
     983                break;
     984        }
     985        seqlen = pread(seq_fd, seqbuf, sizeof(seqbuf) - 1, 0);
     986        if (seqlen < 0) {
     987            close(seq_fd);
     988            seq_fd = -1;
     989            break;
     990        }
     991        seqbuf[seqlen] = '\0';
     992        if (seqbuf[0] == '\n') {
     993            /* seed file: write out seq ASAP */
     994            xwrite_str(seq_fd, seq);
     995            xlseek(seq_fd, 0, SEEK_SET);
     996            dbg2("first seq written");
     997            break;
     998        }
     999        if (strcmp(seq, seqbuf) == 0) {
     1000            /* correct idx */
     1001            break;
     1002        }
     1003        if (do_once) {
     1004            dbg2("%s waiting for '%s'", curtime(), seqbuf);
     1005            do_once = 0;
     1006        }
     1007        if (sigtimedwait(&set_CHLD, NULL, &ts) >= 0) {
     1008            dbg3("woken up");
     1009            continue; /* don't decrement timeout! */
     1010        }
     1011        if (--timeout == 0) {
     1012            dbg1("%s waiting for '%s'", "timed out", seqbuf);
     1013            break;
     1014        }
     1015    }
     1016    sigprocmask(SIG_UNBLOCK, &set_CHLD, NULL);
     1017    return seq_fd;
     1018}
     1019
     1020static void signal_mdevs(unsigned my_pid)
     1021{
     1022    procps_status_t* p = NULL;
     1023    while ((p = procps_scan(p, PSSCAN_ARGV0)) != NULL) {
     1024        if (p->pid != my_pid
     1025         && p->argv0
     1026         && strcmp(bb_basename(p->argv0), "mdev") == 0
     1027        ) {
     1028            kill(p->pid, SIGCHLD);
     1029        }
    5011030    }
    5021031}
     
    5061035{
    5071036    RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
     1037
     1038    INIT_G();
     1039
     1040#if ENABLE_FEATURE_MDEV_CONF
     1041    G.filename = "/etc/mdev.conf";
     1042#endif
    5081043
    5091044    /* We can be called as hotplug helper */
     
    5171052
    5181053    if (argv[1] && strcmp(argv[1], "-s") == 0) {
    519         /* Scan:
    520          * mdev -s
     1054        /*
     1055         * Scan: mdev -s
    5211056         */
    5221057        struct stat st;
    5231058
     1059#if ENABLE_FEATURE_MDEV_CONF
     1060        /* Same as xrealloc_vector(NULL, 4, 0): */
     1061        G.rule_vec = xzalloc((1 << 4) * sizeof(*G.rule_vec));
     1062#endif
    5241063        xstat("/", &st);
    5251064        G.root_major = major(st.st_dev);
    5261065        G.root_minor = minor(st.st_dev);
     1066
     1067        putenv((char*)"ACTION=add");
    5271068
    5281069        /* ACTION_FOLLOWLINKS is needed since in newer kernels
     
    5491090        char *seq;
    5501091        char *action;
    551         char *env_path;
    552         static const char keywords[] ALIGN1 = "remove\0add\0";
    553         enum { OP_remove = 0, OP_add };
     1092        char *env_devname;
     1093        char *env_devpath;
     1094        unsigned my_pid;
     1095        int seq_fd;
    5541096        smalluint op;
    5551097
    5561098        /* Hotplug:
    5571099         * env ACTION=... DEVPATH=... SUBSYSTEM=... [SEQNUM=...] mdev
    558          * ACTION can be "add" or "remove"
     1100         * ACTION can be "add", "remove", "change"
    5591101         * DEVPATH is like "/block/sda" or "/class/input/mice"
    5601102         */
    5611103        action = getenv("ACTION");
    562         env_path = getenv("DEVPATH");
     1104        op = index_in_strings(keywords, action);
     1105        env_devname = getenv("DEVNAME"); /* can be NULL */
     1106        env_devpath = getenv("DEVPATH");
    5631107        G.subsystem = getenv("SUBSYSTEM");
    564         if (!action || !env_path /*|| !G.subsystem*/)
     1108        if (!action || !env_devpath /*|| !G.subsystem*/)
    5651109            bb_show_usage();
    5661110        fw = getenv("FIRMWARE");
    567         op = index_in_strings(keywords, action);
    568         /* If it exists, does /dev/mdev.seq match $SEQNUM?
    569          * If it does not match, earlier mdev is running
    570          * in parallel, and we need to wait */
    5711111        seq = getenv("SEQNUM");
    572         if (seq) {
    573             int timeout = 2000 / 32; /* 2000 msec */
    574             do {
    575                 int seqlen;
    576                 char seqbuf[sizeof(int)*3 + 2];
    577 
    578                 seqlen = open_read_close("mdev.seq", seqbuf, sizeof(seqbuf-1));
    579                 if (seqlen < 0) {
    580                     seq = NULL;
    581                     break;
    582                 }
    583                 seqbuf[seqlen] = '\0';
    584                 if (seqbuf[0] == '\n' /* seed file? */
    585                  || strcmp(seq, seqbuf) == 0 /* correct idx? */
    586                 ) {
    587                     break;
    588                 }
    589                 usleep(32*1000);
    590             } while (--timeout);
    591         }
    592 
    593         snprintf(temp, PATH_MAX, "/sys%s", env_path);
     1112
     1113        my_pid = getpid();
     1114        open_mdev_log(seq, my_pid);
     1115
     1116        seq_fd = seq ? wait_for_seqfile(seq) : -1;
     1117
     1118        dbg1("%s "
     1119            "ACTION:%s SUBSYSTEM:%s DEVNAME:%s DEVPATH:%s"
     1120            "%s%s",
     1121            curtime(),
     1122            action, G.subsystem, env_devname, env_devpath,
     1123            fw ? " FW:" : "", fw ? fw : ""
     1124        );
     1125
     1126        snprintf(temp, PATH_MAX, "/sys%s", env_devpath);
    5941127        if (op == OP_remove) {
    5951128            /* Ignoring "remove firmware". It was reported
     
    5971130             * of device nodes. */
    5981131            if (!fw)
    599                 make_device(temp, /*delete:*/ 1);
    600         }
    601         else if (op == OP_add) {
    602             make_device(temp, /*delete:*/ 0);
     1132                make_device(env_devname, temp, op);
     1133        }
     1134        else {
     1135            make_device(env_devname, temp, op);
    6031136            if (ENABLE_FEATURE_MDEV_LOAD_FIRMWARE) {
    604                 if (fw)
     1137                if (op == OP_add && fw)
    6051138                    load_firmware(fw, temp);
    6061139            }
    6071140        }
    6081141
    609         if (seq) {
    610             xopen_xwrite_close("mdev.seq", utoa(xatou(seq) + 1));
     1142        dbg1("%s exiting", curtime());
     1143        if (seq_fd >= 0) {
     1144            xwrite_str(seq_fd, utoa(xatou(seq) + 1));
     1145            signal_mdevs(my_pid);
    6111146        }
    6121147    }
  • branches/3.2/mindi-busybox/util-linux/mkfs_ext2.c

    r2725 r3232  
    88 * Licensed under GPLv2, see file LICENSE in this source tree.
    99 */
     10
     11//usage:#define mkfs_ext2_trivial_usage
     12//usage:       "[-Fn] "
     13/* //usage:    "[-c|-l filename] " */
     14//usage:       "[-b BLK_SIZE] "
     15/* //usage:    "[-f fragment-size] [-g blocks-per-group] " */
     16//usage:       "[-i INODE_RATIO] [-I INODE_SIZE] "
     17/* //usage:    "[-j] [-J journal-options] [-N number-of-inodes] " */
     18//usage:       "[-m RESERVED_PERCENT] "
     19/* //usage:    "[-o creator-os] [-O feature[,...]] [-q] " */
     20/* //usage:    "[r fs-revision-level] [-E extended-options] [-v] [-F] " */
     21//usage:       "[-L LABEL] "
     22/* //usage:    "[-M last-mounted-directory] [-S] [-T filesystem-type] " */
     23//usage:       "BLOCKDEV [KBYTES]"
     24//usage:#define mkfs_ext2_full_usage "\n\n"
     25//usage:       "    -b BLK_SIZE Block size, bytes"
     26/* //usage:  "\n    -c      Check device for bad blocks" */
     27/* //usage:  "\n    -E opts     Set extended options" */
     28/* //usage:  "\n    -f size     Fragment size in bytes" */
     29//usage:     "\n    -F      Force"
     30/* //usage:  "\n    -g N        Number of blocks in a block group" */
     31//usage:     "\n    -i RATIO    Max number of files is filesystem_size / RATIO"
     32//usage:     "\n    -I BYTES    Inode size (min 128)"
     33/* //usage:  "\n    -j      Create a journal (ext3)" */
     34/* //usage:  "\n    -J opts     Set journal options (size/device)" */
     35/* //usage:  "\n    -l file     Read bad blocks list from file" */
     36//usage:     "\n    -L LBL      Volume label"
     37//usage:     "\n    -m PERCENT  Percent of blocks to reserve for admin"
     38/* //usage:  "\n    -M dir      Set last mounted directory" */
     39//usage:     "\n    -n      Dry run"
     40/* //usage:  "\n    -N N        Number of inodes to create" */
     41/* //usage:  "\n    -o os       Set the 'creator os' field" */
     42/* //usage:  "\n    -O features Dir_index/filetype/has_journal/journal_dev/sparse_super" */
     43/* //usage:  "\n    -q      Quiet" */
     44/* //usage:  "\n    -r rev      Set filesystem revision" */
     45/* //usage:  "\n    -S      Write superblock and group descriptors only" */
     46/* //usage:  "\n    -T fs-type  Set usage type (news/largefile/largefile4)" */
     47/* //usage:  "\n    -v      Verbose" */
     48
    1049#include "libbb.h"
    1150#include <linux/fs.h>
    12 #include <linux/ext2_fs.h>
     51#include "bb_e2fs_defs.h"
    1352
    1453#define ENABLE_FEATURE_MKFS_EXT2_RESERVED_GDT 0
    1554#define ENABLE_FEATURE_MKFS_EXT2_DIR_INDEX    1
    16 
    17 // from e2fsprogs
    18 #define s_reserved_gdt_blocks s_padding1
    19 #define s_mkfs_time           s_reserved[0]
    20 #define s_flags               s_reserved[22]
    2155
    2256#define EXT2_HASH_HALF_MD4       1
     
    444478    STORE_LE(sb->s_inode_size, inodesize);
    445479    // set "Required extra isize" and "Desired extra isize" fields to 28
    446     if (inodesize != sizeof(*inode))
    447         STORE_LE(sb->s_reserved[21], 0x001C001C);
     480    if (inodesize != sizeof(*inode)) {
     481        STORE_LE(sb->s_min_extra_isize, 0x001c);
     482        STORE_LE(sb->s_want_extra_isize, 0x001c);
     483    }
    448484    STORE_LE(sb->s_first_ino, EXT2_GOOD_OLD_FIRST_INO);
    449485    STORE_LE(sb->s_log_block_size, blocksize_log2 - EXT2_MIN_BLOCK_LOG_SIZE);
     
    577613    // zero boot sectors
    578614    memset(buf, 0, blocksize);
    579     PUT(0, buf, 1024); // N.B. 1024 <= blocksize, so buf[0..1023] contains zeros
     615    // Disabled: standard mke2fs doesn't do this, and
     616    // on SPARC this destroys Sun disklabel.
     617    // Users who need/want zeroing can easily do it with dd.
     618    //PUT(0, buf, 1024); // N.B. 1024 <= blocksize, so buf[0..1023] contains zeros
     619
    580620    // zero inode tables
    581621    for (i = 0; i < ngroups; ++i)
  • branches/3.2/mindi-busybox/util-linux/mkfs_minix.c

    r2725 r3232  
    6363 *  removed getopt based parser and added a hand rolled one.
    6464 */
     65
     66//usage:#define mkfs_minix_trivial_usage
     67//usage:       "[-c | -l FILE] [-nXX] [-iXX] BLOCKDEV [KBYTES]"
     68//usage:#define mkfs_minix_full_usage "\n\n"
     69//usage:       "Make a MINIX filesystem\n"
     70//usage:     "\n    -c      Check device for bad blocks"
     71//usage:     "\n    -n [14|30]  Maximum length of filenames"
     72//usage:     "\n    -i INODES   Number of inodes for the filesystem"
     73//usage:     "\n    -l FILE     Read bad blocks list from FILE"
     74//usage:     "\n    -v      Make version 2 filesystem"
    6575
    6676#include "libbb.h"
  • branches/3.2/mindi-busybox/util-linux/mkfs_reiser.c

    r2725 r3232  
    77 * Licensed under GPLv2, see file LICENSE in this source tree.
    88 */
     9
     10//usage:#define mkfs_reiser_trivial_usage
     11//usage:       "[-f] [-l LABEL] BLOCKDEV [4K-BLOCKS]"
     12//usage:#define mkfs_reiser_full_usage "\n\n"
     13//usage:       "Make a ReiserFS V3 filesystem\n"
     14//usage:     "\n    -f  Force"
     15//usage:     "\n    -l LBL  Volume label"
     16
    917#include "libbb.h"
    1018#include <linux/fs.h>
  • branches/3.2/mindi-busybox/util-linux/mkfs_vfat.c

    r2725 r3232  
    88 * Licensed under GPLv2, see file LICENSE in this source tree.
    99 */
     10
     11//usage:#define mkfs_vfat_trivial_usage
     12//usage:       "[-v] [-n LABEL] BLOCKDEV [KBYTES]"
     13/* Accepted but ignored:
     14       "[-c] [-C] [-I] [-l bad-block-file] [-b backup-boot-sector] "
     15       "[-m boot-msg-file] [-i volume-id] "
     16       "[-s sectors-per-cluster] [-S logical-sector-size] [-f number-of-FATs] "
     17       "[-h hidden-sectors] [-F fat-size] [-r root-dir-entries] [-R reserved-sectors] "
     18*/
     19//usage:#define mkfs_vfat_full_usage "\n\n"
     20//usage:       "Make a FAT32 filesystem\n"
     21/* //usage:  "\n    -c  Check device for bad blocks" */
     22//usage:     "\n    -v  Verbose"
     23/* //usage:  "\n    -I  Allow to use entire disk device (e.g. /dev/hda)" */
     24//usage:     "\n    -n LBL  Volume label"
     25
    1026#include "libbb.h"
    1127
  • branches/3.2/mindi-busybox/util-linux/mkswap.c

    r2725 r3232  
    66 * Licensed under GPLv2, see file LICENSE in this source tree.
    77 */
     8
     9//usage:#define mkswap_trivial_usage
     10//usage:       "[-L LBL] BLOCKDEV [KBYTES]"
     11//usage:#define mkswap_full_usage "\n\n"
     12//usage:       "Prepare BLOCKDEV to be used as swap partition\n"
     13//usage:     "\n    -L LBL  Label"
     14
    815#include "libbb.h"
    916
  • branches/3.2/mindi-busybox/util-linux/more.c

    r2725 r3232  
    1414 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1515 */
     16
     17//usage:#define more_trivial_usage
     18//usage:       "[FILE]..."
     19//usage:#define more_full_usage "\n\n"
     20//usage:       "View FILE (or stdin) one screenful at a time"
     21//usage:
     22//usage:#define more_example_usage
     23//usage:       "$ dmesg | more\n"
    1624
    1725#include "libbb.h"
     
    7886        getTermSettings(cin_fileno, &initial_settings);
    7987        new_settings = initial_settings;
    80         new_settings.c_lflag &= ~ICANON;
    81         new_settings.c_lflag &= ~ECHO;
     88        new_settings.c_lflag &= ~(ICANON | ECHO);
    8289        new_settings.c_cc[VMIN] = 1;
    8390        new_settings.c_cc[VTIME] = 0;
     
    114121            if (input != 'r' && please_display_more_prompt) {
    115122                len = printf("--More-- ");
    116                 if (st.st_size > 0) {
     123                if (st.st_size != 0) {
     124                    uoff_t d = (uoff_t)st.st_size / 100;
     125                    if (d == 0)
     126                        d = 1;
    117127                    len += printf("(%u%% of %"OFF_FMT"u bytes)",
    118                         (int) (ftello(file)*100 / st.st_size),
     128                        (int) ((uoff_t)ftello(file) / d),
    119129                        st.st_size);
    120130                }
     
    160170             * a bajillion times easier to deal with. */
    161171            if (c == '\t') {
    162                 spaces = CONVERTED_TAB_SIZE - 1;
     172                spaces = ((unsigned)~len) % CONVERTED_TAB_SIZE;
    163173                c = ' ';
    164174            }
     
    192202            /* My small mind cannot fathom backspaces and UTF-8 */
    193203            putchar(c);
     204            die_if_ferror_stdout(); /* if tty was destroyed (closed xterm, etc) */
    194205        }
    195206        fclose(file);
  • branches/3.2/mindi-busybox/util-linux/mount.c

    r2725 r3232  
    1717// mount_it_now() does the actual mount.
    1818//
     19
     20//usage:#define mount_trivial_usage
     21//usage:       "[OPTIONS] [-o OPTS] DEVICE NODE"
     22//usage:#define mount_full_usage "\n\n"
     23//usage:       "Mount a filesystem. Filesystem autodetection requires /proc.\n"
     24//usage:     "\n    -a      Mount all filesystems in fstab"
     25//usage:    IF_FEATURE_MOUNT_FAKE(
     26//usage:    IF_FEATURE_MTAB_SUPPORT(
     27//usage:     "\n    -f      Update /etc/mtab, but don't mount"
     28//usage:    )
     29//usage:    IF_NOT_FEATURE_MTAB_SUPPORT(
     30//usage:     "\n    -f      Dry run"
     31//usage:    )
     32//usage:    )
     33//usage:    IF_FEATURE_MOUNT_HELPERS(
     34//usage:     "\n    -i      Don't run mount helper"
     35//usage:    )
     36//usage:    IF_FEATURE_MTAB_SUPPORT(
     37//usage:     "\n    -n      Don't update /etc/mtab"
     38//usage:    )
     39//usage:    IF_FEATURE_MOUNT_VERBOSE(
     40//usage:     "\n    -v      Verbose"
     41//usage:    )
     42////usage:   "\n    -s      Sloppy (ignored)"
     43//usage:     "\n    -r      Read-only mount"
     44//usage:     "\n    -w      Read-write mount (default)"
     45//usage:     "\n    -t FSTYPE[,...] Filesystem type(s)"
     46//usage:     "\n    -O OPT      Mount only filesystems with option OPT (-a only)"
     47//usage:     "\n-o OPT:"
     48//usage:    IF_FEATURE_MOUNT_LOOP(
     49//usage:     "\n    loop        Ignored (loop devices are autodetected)"
     50//usage:    )
     51//usage:    IF_FEATURE_MOUNT_FLAGS(
     52//usage:     "\n    [a]sync     Writes are [a]synchronous"
     53//usage:     "\n    [no]atime   Disable/enable updates to inode access times"
     54//usage:     "\n    [no]diratime    Disable/enable atime updates to directories"
     55//usage:     "\n    [no]relatime    Disable/enable atime updates relative to modification time"
     56//usage:     "\n    [no]dev     (Dis)allow use of special device files"
     57//usage:     "\n    [no]exec    (Dis)allow use of executable files"
     58//usage:     "\n    [no]suid    (Dis)allow set-user-id-root programs"
     59//usage:     "\n    [r]shared   Convert [recursively] to a shared subtree"
     60//usage:     "\n    [r]slave    Convert [recursively] to a slave subtree"
     61//usage:     "\n    [r]private  Convert [recursively] to a private subtree"
     62//usage:     "\n    [un]bindable    Make mount point [un]able to be bind mounted"
     63//usage:     "\n    [r]bind     Bind a file or directory [recursively] to another location"
     64//usage:     "\n    move        Relocate an existing mount point"
     65//usage:    )
     66//usage:     "\n    remount     Remount a mounted filesystem, changing flags"
     67//usage:     "\n    ro/rw       Same as -r/-w"
     68//usage:     "\n"
     69//usage:     "\nThere are filesystem-specific -o flags."
     70//usage:
     71//usage:#define mount_example_usage
     72//usage:       "$ mount\n"
     73//usage:       "/dev/hda3 on / type minix (rw)\n"
     74//usage:       "proc on /proc type proc (rw)\n"
     75//usage:       "devpts on /dev/pts type devpts (rw)\n"
     76//usage:       "$ mount /dev/fd0 /mnt -t msdos -o ro\n"
     77//usage:       "$ mount /tmp/diskimage /opt -t ext2 -o loop\n"
     78//usage:       "$ mount cd_image.iso mydir\n"
     79//usage:#define mount_notes_usage
     80//usage:       "Returns 0 for success, number of failed mounts for -a, or errno for one mount."
     81
    1982#include <mntent.h>
    2083#include <syslog.h>
     
    55118# define MS_RELATIME    (1 << 21)
    56119#endif
     120#ifndef MS_STRICTATIME
     121# define MS_STRICTATIME (1 << 24)
     122#endif
     123
     124/* Any ~MS_FOO value has this bit set: */
     125#define BB_MS_INVERTED_VALUE (1u << 31)
    57126
    58127#include "libbb.h"
     
    160229        IF_DESKTOP(/* "users" */ MOUNT_USERS,)
    161230        /* "_netdev" */ 0,
     231        IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */
    162232    )
    163233
     
    181251        /* "relatime"    */ MS_RELATIME,
    182252        /* "norelatime"  */ ~MS_RELATIME,
     253        /* "strictatime" */ MS_STRICTATIME,
    183254        /* "loud"        */ ~MS_SILENT,
     255        /* "rbind"       */ MS_BIND|MS_RECURSIVE,
    184256
    185257        // action flags
     
    193265        /* "rshared"     */ MS_SHARED|MS_RECURSIVE,
    194266        /* "rslave"      */ MS_SLAVE|MS_RECURSIVE,
    195         /* "rprivate"    */ MS_SLAVE|MS_RECURSIVE,
     267        /* "rprivate"    */ MS_PRIVATE|MS_RECURSIVE,
    196268        /* "runbindable" */ MS_UNBINDABLE|MS_RECURSIVE,
    197269    )
     
    216288        IF_DESKTOP("users\0")
    217289        "_netdev\0"
     290        IF_DESKTOP("comment=\0") /* systemd uses this in fstab */
    218291    )
    219292    IF_FEATURE_MOUNT_FLAGS(
     
    236309        "relatime\0"
    237310        "norelatime\0"
     311        "strictatime\0"
    238312        "loud\0"
     313        "rbind\0"
    239314
    240315        // action flags
     
    242317        "bind\0"
    243318        "move\0"
    244         "shared\0"
    245         "slave\0"
    246         "private\0"
    247         "unbindable\0"
    248         "rshared\0"
    249         "rslave\0"
    250         "rprivate\0"
    251         "runbindable\0"
     319        "make-shared\0"
     320        "make-slave\0"
     321        "make-private\0"
     322        "make-unbindable\0"
     323        "make-rshared\0"
     324        "make-rslave\0"
     325        "make-rprivate\0"
     326        "make-runbindable\0"
    252327    )
    253328
     
    279354#define fslist            (G.fslist           )
    280355#define getmntent_buf     (G.getmntent_buf    )
    281 
     356#define INIT_G() do { } while (0)
     357
     358#if ENABLE_FEATURE_MTAB_SUPPORT
     359/*
     360 * update_mtab_entry_on_move() is used to update entry in case of mount --move.
     361 * we are looking for existing entries mnt_dir which is equal to mnt_fsname of
     362 * input mntent and replace it by new one.
     363 */
     364static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp)
     365{
     366    struct mntent *entries, *m;
     367    int i, count;
     368    FILE *mountTable;
     369
     370    mountTable = setmntent(bb_path_mtab_file, "r");
     371    if (!mountTable) {
     372        bb_perror_msg(bb_path_mtab_file);
     373        return;
     374    }
     375
     376    entries = NULL;
     377    count = 0;
     378    while ((m = getmntent(mountTable)) != NULL) {
     379        entries = xrealloc_vector(entries, 3, count);
     380        entries[count].mnt_fsname = xstrdup(m->mnt_fsname);
     381        entries[count].mnt_dir = xstrdup(m->mnt_dir);
     382        entries[count].mnt_type = xstrdup(m->mnt_type);
     383        entries[count].mnt_opts = xstrdup(m->mnt_opts);
     384        entries[count].mnt_freq = m->mnt_freq;
     385        entries[count].mnt_passno = m->mnt_passno;
     386        count++;
     387    }
     388    endmntent(mountTable);
     389
     390    mountTable = setmntent(bb_path_mtab_file, "w");
     391    if (mountTable) {
     392        for (i = 0; i < count; i++) {
     393            if (strcmp(entries[i].mnt_dir, mp->mnt_fsname) != 0)
     394                addmntent(mountTable, &entries[i]);
     395            else
     396                addmntent(mountTable, mp);
     397        }
     398        endmntent(mountTable);
     399    } else if (errno != EROFS)
     400        bb_perror_msg(bb_path_mtab_file);
     401
     402    if (ENABLE_FEATURE_CLEAN_UP) {
     403        for (i = 0; i < count; i++) {
     404            free(entries[i].mnt_fsname);
     405            free(entries[i].mnt_dir);
     406            free(entries[i].mnt_type);
     407            free(entries[i].mnt_opts);
     408        }
     409        free(entries);
     410    }
     411}
     412#endif
    282413
    283414#if ENABLE_FEATURE_MOUNT_VERBOSE
     
    334465// Use the mount_options list to parse options into flags.
    335466// Also update list of unrecognized options if unrecognized != NULL
    336 static long parse_mount_options(char *options, char **unrecognized)
    337 {
    338     long flags = MS_SILENT;
     467static unsigned long parse_mount_options(char *options, char **unrecognized)
     468{
     469    unsigned long flags = MS_SILENT;
    339470
    340471    // Loop through options
     
    349480        // Find this option in mount_options
    350481        for (i = 0; i < ARRAY_SIZE(mount_options); i++) {
    351             if (strcasecmp(option_str, options) == 0) {
    352                 long fl = mount_options[i];
    353                 if (fl < 0)
     482            unsigned opt_len = strlen(option_str);
     483
     484            if (strncasecmp(option_str, options, opt_len) == 0
     485             && (options[opt_len] == '\0'
     486                /* or is it "comment=" thingy in fstab? */
     487                IF_FEATURE_MOUNT_FSTAB(IF_DESKTOP( || option_str[opt_len-1] == '=' ))
     488                )
     489            ) {
     490                unsigned long fl = mount_options[i];
     491                if (fl & BB_MS_INVERTED_VALUE)
    354492                    flags &= fl;
    355493                else
     
    357495                goto found;
    358496            }
    359             option_str += strlen(option_str) + 1;
     497            option_str += opt_len + 1;
    360498        }
    361499        // We did not recognize this option.
     
    406544        while ((buf = xmalloc_fgetline(f)) != NULL) {
    407545            if (strncmp(buf, "nodev", 5) == 0 && isspace(buf[5]))
    408                 continue;
     546                goto next;
    409547            fs = skip_whitespace(buf);
    410548            if (*fs == '#' || *fs == '*' || !*fs)
    411                 continue;
     549                goto next;
    412550
    413551            llist_add_to_end(&list, xstrdup(fs));
     552 next:
    414553            free(buf);
    415554        }
     
    431570// Perform actual mount of specific filesystem at specific location.
    432571// NB: mp->xxx fields may be trashed on exit
    433 static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
     572static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filteropts)
    434573{
    435574    int rc = 0;
     
    497636
    498637        if (!mountTable) {
    499             bb_error_msg("no %s", bb_path_mtab_file);
     638            bb_perror_msg(bb_path_mtab_file);
    500639            goto ret;
    501640        }
    502641
    503642        // Add vfs string flags
    504 
    505643        for (i = 0; mount_options[i] != MS_REMOUNT; i++) {
    506644            if (mount_options[i] > 0 && (mount_options[i] & vfsflags))
     
    510648
    511649        // Remove trailing / (if any) from directory we mounted on
    512 
    513650        i = strlen(mp->mnt_dir) - 1;
    514         if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = '\0';
     651        while (i > 0 && mp->mnt_dir[i] == '/')
     652            mp->mnt_dir[i--] = '\0';
    515653
    516654        // Convert to canonical pathnames as needed
    517 
    518655        mp->mnt_dir = bb_simplify_path(mp->mnt_dir);
    519         fsname = 0;
     656        fsname = NULL;
    520657        if (!mp->mnt_type || !*mp->mnt_type) { // bind mount
    521658            mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname);
     
    524661        mp->mnt_freq = mp->mnt_passno = 0;
    525662
    526         // Write and close.
    527 
    528         addmntent(mountTable, mp);
     663        // Write and close
     664#if ENABLE_FEATURE_MTAB_SUPPORT
     665        if (vfsflags & MS_MOVE)
     666            update_mtab_entry_on_move(mp);
     667        else
     668#endif
     669            addmntent(mountTable, mp);
    529670        endmntent(mountTable);
     671
    530672        if (ENABLE_FEATURE_CLEAN_UP) {
    531673            free(mp->mnt_dir);
     
    700842
    701843struct nfs2_fh {
    702     char                    data[32];
     844    char            data[32];
    703845};
    704846struct nfs3_fh {
    705     unsigned short          size;
    706     unsigned char           data[64];
     847    unsigned short  size;
     848    unsigned char   data[64];
    707849};
    708850
    709851struct nfs_mount_data {
    710     int     version;        /* 1 */
    711     int     fd;         /* 1 */
    712     struct nfs2_fh  old_root;       /* 1 */
    713     int     flags;          /* 1 */
    714     int     rsize;          /* 1 */
    715     int     wsize;          /* 1 */
    716     int     timeo;          /* 1 */
    717     int     retrans;        /* 1 */
    718     int     acregmin;       /* 1 */
    719     int     acregmax;       /* 1 */
    720     int     acdirmin;       /* 1 */
    721     int     acdirmax;       /* 1 */
    722     struct sockaddr_in addr;        /* 1 */
    723     char        hostname[256];      /* 1 */
    724     int     namlen;         /* 2 */
    725     unsigned int    bsize;          /* 3 */
    726     struct nfs3_fh  root;           /* 4 */
     852    int     version;    /* 1 */
     853    int     fd;     /* 1 */
     854    struct nfs2_fh  old_root;   /* 1 */
     855    int     flags;      /* 1 */
     856    int     rsize;      /* 1 */
     857    int     wsize;      /* 1 */
     858    int     timeo;      /* 1 */
     859    int     retrans;    /* 1 */
     860    int     acregmin;   /* 1 */
     861    int     acregmax;   /* 1 */
     862    int     acdirmin;   /* 1 */
     863    int     acdirmax;   /* 1 */
     864    struct sockaddr_in addr;    /* 1 */
     865    char        hostname[256];  /* 1 */
     866    int     namlen;     /* 2 */
     867    unsigned int    bsize;      /* 3 */
     868    struct nfs3_fh  root;       /* 4 */
    727869};
    728870
     
    739881    NFS_MOUNT_KERBEROS = 0x0100,    /* 3 */
    740882    NFS_MOUNT_NONLM = 0x0200,   /* 3 */
     883    NFS_MOUNT_NOACL = 0x0800,   /* 4 */
    741884    NFS_MOUNT_NORDIRPLUS = 0x4000
    742885};
     
    792935{
    793936    if (!xdr_u_int(xdrs, &objp->fhs_status))
    794          return FALSE;
     937        return FALSE;
    795938    if (objp->fhs_status == 0)
    796939        return xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle);
     
    806949{
    807950    return xdr_bytes(xdrs, (char **)&objp->fhandle3_val,
    808                (unsigned int *) &objp->fhandle3_len,
    809                FHSIZE3);
     951            (unsigned int *) &objp->fhandle3_len,
     952            FHSIZE3);
    810953}
    811954
     
    815958        return FALSE;
    816959    return xdr_array(xdrs, &(objp->auth_flavours.auth_flavours_val),
    817                &(objp->auth_flavours.auth_flavours_len),
    818                ~0,
    819                sizeof(int),
    820                (xdrproc_t) xdr_int);
     960            &(objp->auth_flavours.auth_flavours_len),
     961            ~0,
     962            sizeof(int),
     963            (xdrproc_t) xdr_int);
    821964}
    822965
     
    9591102
    9601103/* NB: mp->xxx fields may be trashed on exit */
    961 static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
     1104static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts)
    9621105{
    9631106    CLIENT *mclient;
     
    10031146    int nordirplus;
    10041147    int nolock;
     1148    int noacl;
    10051149
    10061150    find_kernel_nfs_mount_version();
     
    10221166    *s = '\0';
    10231167    /* Ignore all but first hostname in replicated mounts
    1024        until they can be fully supported. (mack@sgi.com) */
     1168     * until they can be fully supported. (mack@sgi.com) */
    10251169    s = strchr(hostname, ',');
    10261170    if (s) {
     
    10751219    noac = 0;
    10761220    nordirplus = 0;
     1221    noacl = 0;
    10771222    retry = 10000;      /* 10000 minutes ~ 1 week */
    1078     tcp = 0;
     1223    tcp = 1;            /* nfs-utils uses tcp per default */
    10791224
    10801225    mountprog = MOUNTPROG;
     
    11301275            case 20: // "addr" - ignore
    11311276                continue;
     1277            case -1: // unknown
     1278                if (vfsflags & MS_REMOUNT)
     1279                    continue;
    11321280            }
    11331281
     
    12101358                "udp\0"
    12111359                "lock\0"
    1212                 "rdirplus\0";
     1360                "rdirplus\0"
     1361                "acl\0";
    12131362            int val = 1;
    12141363            if (!strncmp(opt, "no", 2)) {
     
    12601409                nordirplus = !val;
    12611410                break;
     1411            case 12: // acl
     1412                noacl = !val;
     1413                break;
    12621414            default:
    12631415                bb_error_msg("unknown nfs mount option: %s%s", val ? "" : "no", opt);
     
    12731425        | (nocto ? NFS_MOUNT_NOCTO : 0)
    12741426        | (noac ? NFS_MOUNT_NOAC : 0)
    1275         | (nordirplus ? NFS_MOUNT_NORDIRPLUS : 0);
     1427        | (nordirplus ? NFS_MOUNT_NORDIRPLUS : 0)
     1428        | (noacl ? NFS_MOUNT_NOACL : 0);
    12761429    if (nfs_mount_version >= 2)
    12771430        data.flags |= (tcp ? NFS_MOUNT_TCP : 0);
     
    13771530        case IPPROTO_UDP:
    13781531            mclient = clntudp_create(&mount_server_addr,
    1379                          pm_mnt.pm_prog,
    1380                          pm_mnt.pm_vers,
    1381                          retry_timeout,
    1382                          &msock);
     1532                        pm_mnt.pm_prog,
     1533                        pm_mnt.pm_vers,
     1534                        retry_timeout,
     1535                        &msock);
    13831536            if (mclient)
    13841537                break;
     
    13871540        case IPPROTO_TCP:
    13881541            mclient = clnttcp_create(&mount_server_addr,
    1389                          pm_mnt.pm_prog,
    1390                          pm_mnt.pm_vers,
    1391                          &msock, 0, 0);
     1542                        pm_mnt.pm_prog,
     1543                        pm_mnt.pm_vers,
     1544                        &msock, 0, 0);
    13921545            break;
    13931546        default:
     
    14101563            if (pm_mnt.pm_vers == 3)
    14111564                clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT,
    1412                           (xdrproc_t) xdr_dirpath,
    1413                           (caddr_t) &pathname,
    1414                           (xdrproc_t) xdr_mountres3,
    1415                           (caddr_t) &status,
    1416                           total_timeout);
     1565                        (xdrproc_t) xdr_dirpath,
     1566                        (caddr_t) &pathname,
     1567                        (xdrproc_t) xdr_mountres3,
     1568                        (caddr_t) &status,
     1569                        total_timeout);
    14171570            else
    14181571                clnt_stat = clnt_call(mclient, MOUNTPROC_MNT,
    1419                           (xdrproc_t) xdr_dirpath,
    1420                           (caddr_t) &pathname,
    1421                           (xdrproc_t) xdr_fhstatus,
    1422                           (caddr_t) &status,
    1423                           total_timeout);
     1572                        (xdrproc_t) xdr_dirpath,
     1573                        (caddr_t) &pathname,
     1574                        (xdrproc_t) xdr_fhstatus,
     1575                        (caddr_t) &status,
     1576                        total_timeout);
    14241577
    14251578            if (clnt_stat == RPC_SUCCESS)
     
    15521705    /* Perform actual mount */
    15531706 do_mount:
    1554     mp->mnt_type = (char*)"nfs";
    15551707    retval = mount_it_now(mp, vfsflags, (char*)&data);
    15561708    goto ret;
     
    15771729#else // !ENABLE_FEATURE_MOUNT_NFS
    15781730
    1579 // Never called. Call should be optimized out.
    1580 int nfsmount(struct mntent *mp, long vfsflags, char *filteropts);
     1731/* Linux 2.6.23+ supports nfs mounts with options passed as a string.
     1732 * For older kernels, you must build busybox with ENABLE_FEATURE_MOUNT_NFS.
     1733 * (However, note that then you lose any chances that NFS over IPv6 would work).
     1734 */
     1735static int nfsmount(struct mntent *mp, unsigned long vfsflags, char *filteropts)
     1736{
     1737    len_and_sockaddr *lsa;
     1738    char *opts;
     1739    char *end;
     1740    char *dotted;
     1741    int ret;
     1742
     1743# if ENABLE_FEATURE_IPV6
     1744    end = strchr(mp->mnt_fsname, ']');
     1745    if (end && end[1] == ':')
     1746        end++;
     1747    else
     1748# endif
     1749        /* mount_main() guarantees that ':' is there */
     1750        end = strchr(mp->mnt_fsname, ':');
     1751
     1752    *end = '\0';
     1753    lsa = xhost2sockaddr(mp->mnt_fsname, /*port:*/ 0);
     1754    *end = ':';
     1755    dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa);
     1756    if (ENABLE_FEATURE_CLEAN_UP) free(lsa);
     1757    opts = xasprintf("%s%saddr=%s",
     1758        filteropts ? filteropts : "",
     1759        filteropts ? "," : "",
     1760        dotted
     1761    );
     1762    if (ENABLE_FEATURE_CLEAN_UP) free(dotted);
     1763    ret = mount_it_now(mp, vfsflags, opts);
     1764    if (ENABLE_FEATURE_CLEAN_UP) free(opts);
     1765
     1766    return ret;
     1767}
    15811768
    15821769#endif // !ENABLE_FEATURE_MOUNT_NFS
     
    15881775{
    15891776    int rc = -1;
    1590     long vfsflags;
     1777    unsigned long vfsflags;
    15911778    char *loopFile = NULL, *filteropts = NULL;
    15921779    llist_t *fl = NULL;
     
    16381825        int len;
    16391826        char c;
     1827        char *hostname, *share;
     1828        char *dotted, *ip;
    16401829        len_and_sockaddr *lsa;
    1641         char *hostname, *dotted, *ip;
     1830
     1831        // Parse mp->mnt_fsname of the form "//hostname/share[/dir1/dir2]"
    16421832
    16431833        hostname = mp->mnt_fsname + 2;
    16441834        len = strcspn(hostname, "/\\");
    1645         if (len == 0 || hostname[len] == '\0')
     1835        share = hostname + len + 1;
     1836        if (len == 0          // 3rd char is a [back]slash (IOW: empty hostname)
     1837         || share[-1] == '\0' // no [back]slash after hostname
     1838         || share[0] == '\0'  // empty share name
     1839        ) {
    16461840            goto report_error;
    1647         c = hostname[len];
    1648         hostname[len] = '\0';
     1841        }
     1842        c = share[-1];
     1843        share[-1] = '\0';
     1844        len = strcspn(share, "/\\");
     1845
     1846        // "unc=\\hostname\share" option is mandatory
     1847        // after CIFS option parsing was rewritten in Linux 3.4.
     1848        // Must use backslashes.
     1849        // If /dir1/dir2 is present, also add "prefixpath=dir1/dir2"
     1850        {
     1851            char *unc = xasprintf(
     1852                share[len] != '\0'  /* "/dir1/dir2" exists? */
     1853                    ? "unc=\\\\%s\\%.*s,prefixpath=%s"
     1854                    : "unc=\\\\%s\\%.*s",
     1855                hostname,
     1856                len, share,
     1857                share + len + 1  /* "dir1/dir2" */
     1858            );
     1859            parse_mount_options(unc, &filteropts);
     1860            if (ENABLE_FEATURE_CLEAN_UP) free(unc);
     1861        }
     1862
    16491863        lsa = host2sockaddr(hostname, 0);
    1650         hostname[len] = c;
     1864        share[-1] = c;
    16511865        if (!lsa)
    16521866            goto report_error;
     
    16601874        if (ENABLE_FEATURE_CLEAN_UP) free(ip);
    16611875
    1662         // "-o mand" is required [why?]
    1663         vfsflags |= MS_MANDLOCK;
    16641876        mp->mnt_type = (char*)"cifs";
    16651877        rc = mount_it_now(mp, vfsflags, filteropts);
     
    16691881
    16701882    // Might this be an NFS filesystem?
    1671     if (ENABLE_FEATURE_MOUNT_NFS
    1672      && (!mp->mnt_type || strcmp(mp->mnt_type, "nfs") == 0)
     1883    if ((!mp->mnt_type || strncmp(mp->mnt_type, "nfs", 3) == 0)
    16731884     && strchr(mp->mnt_fsname, ':') != NULL
    16741885    ) {
     1886        if (!mp->mnt_type)
     1887            mp->mnt_type = (char*)"nfs";
    16751888        rc = nfsmount(mp, vfsflags, filteropts);
    16761889        goto report_error;
     
    16881901            loopFile = bb_simplify_path(mp->mnt_fsname);
    16891902            mp->mnt_fsname = NULL; // will receive malloced loop dev name
    1690             if (set_loop(&mp->mnt_fsname, loopFile, 0) < 0) {
     1903            if (set_loop(&mp->mnt_fsname, loopFile, 0, /*ro:*/ (vfsflags & MS_RDONLY)) < 0) {
    16911904                if (errno == EPERM || errno == EACCES)
    16921905                    bb_error_msg(bb_msg_perm_denied_are_you_root);
     
    17041917    // to the actual mount.
    17051918    if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) {
    1706         rc = mount_it_now(mp, vfsflags, filteropts);
     1919        char *next;
     1920        for (;;) {
     1921            next = mp->mnt_type ? strchr(mp->mnt_type, ',') : NULL;
     1922            if (next)
     1923                *next = '\0';
     1924            rc = mount_it_now(mp, vfsflags, filteropts);
     1925            if (rc == 0 || !next)
     1926                break;
     1927            mp->mnt_type = next + 1;
     1928        }
    17071929    } else {
    17081930        // Loop through filesystem types until mount succeeds
     
    17211943            mp->mnt_type = fl->data;
    17221944            rc = mount_it_now(mp, vfsflags, filteropts);
    1723             if (!rc)
     1945            if (rc == 0)
    17241946                break;
    17251947        }
     
    18172039    int i, j;
    18182040    int rc = EXIT_SUCCESS;
     2041    unsigned long cmdopt_flags;
    18192042    unsigned opt;
    18202043    struct mntent mtpair[2], *mtcur = mtpair;
     
    18222045
    18232046    IF_DESKTOP(int nonroot = ) sanitize_env_if_suid();
     2047
     2048    INIT_G();
    18242049
    18252050    // Parse long options, like --bind and --move.  Note that -o option
     
    18892114    // or "mount [opts] single_param"
    18902115
    1891     i = parse_mount_options(cmdopts, NULL); // FIXME: should be "long", not "int"
    1892     if (nonroot && (i & ~MS_SILENT)) // Non-root users cannot specify flags
     2116    cmdopt_flags = parse_mount_options(cmdopts, NULL);
     2117    if (nonroot && (cmdopt_flags & ~MS_SILENT)) // Non-root users cannot specify flags
    18932118        bb_error_msg_and_die(bb_msg_you_must_be_root);
    18942119
    18952120    // If we have a shared subtree flag, don't worry about fstab or mtab.
    18962121    if (ENABLE_FEATURE_MOUNT_FLAGS
    1897      && (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
     2122     && (cmdopt_flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
    18982123    ) {
    18992124        // verbose_mount(source, target, type, flags, data)
    1900         rc = verbose_mount("", argv[0], "", i, "");
     2125        rc = verbose_mount("", argv[0], "", cmdopt_flags, "");
    19012126        if (rc)
    19022127            bb_simple_perror_msg_and_die(argv[0]);
     
    19062131    // Open either fstab or mtab
    19072132    fstabname = "/etc/fstab";
    1908     if (i & MS_REMOUNT) {
     2133    if (cmdopt_flags & MS_REMOUNT) {
    19092134        // WARNING. I am not sure this matches util-linux's
    19102135        // behavior. It's possible util-linux does not
     
    20052230    // Were we looking for something specific?
    20062231    if (argv[0]) { // yes
    2007         long l;
     2232        unsigned long l;
    20082233
    20092234        // If we didn't find anything, complain
  • branches/3.2/mindi-busybox/util-linux/pivot_root.c

    r2725 r3232  
    99 * Licensed under GPLv2, see file LICENSE in this source tree.
    1010 */
     11
     12//usage:#define pivot_root_trivial_usage
     13//usage:       "NEW_ROOT PUT_OLD"
     14//usage:#define pivot_root_full_usage "\n\n"
     15//usage:       "Move the current root file system to PUT_OLD and make NEW_ROOT\n"
     16//usage:       "the new root file system"
     17
    1118#include "libbb.h"
    1219
  • branches/3.2/mindi-busybox/util-linux/rdate.c

    r2725 r3232  
    22/*
    33 * The Rdate command will ask a time server for the RFC 868 time
    4  *  and optionally set the system time.
     4 * and optionally set the system time.
    55 *
    66 * by Sterling Huxley <sterling@europa.com>
     
    88 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99*/
     10
     11//usage:#define rdate_trivial_usage
     12//usage:       "[-sp] HOST"
     13//usage:#define rdate_full_usage "\n\n"
     14//usage:       "Get and possibly set the system date/time from a remote HOST\n"
     15//usage:     "\n    -s  Set the system date/time (default)"
     16//usage:     "\n    -p  Print the date/time"
    1017
    1118#include "libbb.h"
     
    2936    fd = create_and_connect_stream_or_die(host, bb_lookup_port("time", "tcp", 37));
    3037
    31     if (safe_read(fd, (void *)&nett, 4) != 4)    /* read time from server */
     38    if (safe_read(fd, &nett, 4) != 4)    /* read time from server */
    3239        bb_error_msg_and_die("%s did not send the complete time", host);
    33     close(fd);
     40    if (ENABLE_FEATURE_CLEAN_UP)
     41        close(fd);
    3442
    35     /* convert from network byte order to local byte order.
     43    /* Convert from network byte order to local byte order.
    3644     * RFC 868 time is the number of seconds
    3745     * since 00:00 (midnight) 1 January 1900 GMT
    3846     * the RFC 868 time 2,208,988,800 corresponds to 00:00  1 Jan 1970 GMT
    39      * Subtract the RFC 868 time to get Linux epoch
     47     * Subtract the RFC 868 time to get Linux epoch.
    4048     */
    4149
     
    4755{
    4856    time_t remote_time;
    49     unsigned long flags;
     57    unsigned flags;
    5058
    5159    opt_complementary = "-1";
     
    5462    remote_time = askremotedate(argv[optind]);
    5563
    56     if ((flags & 2) == 0) {
     64    if (!(flags & 2)) { /* no -p (-s may be present) */
    5765        time_t current_time;
    5866
     
    6573    }
    6674
    67     if ((flags & 1) == 0)
     75    if (flags != 1) /* not lone -s */
    6876        printf("%s", ctime(&remote_time));
    6977
  • branches/3.2/mindi-busybox/util-linux/rdev.c

    r2725 r3232  
    1010 */
    1111
     12//usage:#define rdev_trivial_usage
     13//usage:       ""
     14//usage:#define rdev_full_usage "\n\n"
     15//usage:       "Print the device node associated with the filesystem mounted at '/'"
     16//usage:
     17//usage:#define rdev_example_usage
     18//usage:       "$ rdev\n"
     19//usage:       "/dev/mtdblock9 /\n"
     20
    1221#include "libbb.h"
    1322
     
    1524int rdev_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
    1625{
    17     char const * const root_device = find_block_device("/");
     26    const char *root_device = find_block_device("/");
    1827
    19     if (root_device != NULL) {
     28    if (root_device) {
    2029        printf("%s /\n", root_device);
    2130        return EXIT_SUCCESS;
  • branches/3.2/mindi-busybox/util-linux/readprofile.c

    r2725 r3232  
    3232 * Paul Mundt <lethal@linux-sh.org>.
    3333 */
     34
     35//usage:#define readprofile_trivial_usage
     36//usage:       "[OPTIONS]"
     37//usage:#define readprofile_full_usage "\n\n"
     38//usage:       "    -m mapfile  (Default: /boot/System.map)"
     39//usage:     "\n    -p profile  (Default: /proc/profile)"
     40//usage:     "\n    -M NUM      Set the profiling multiplier to NUM"
     41//usage:     "\n    -i      Print only info about the sampling step"
     42//usage:     "\n    -v      Verbose"
     43//usage:     "\n    -a      Print all symbols, even if count is 0"
     44//usage:     "\n    -b      Print individual histogram-bin counts"
     45//usage:     "\n    -s      Print individual counters within functions"
     46//usage:     "\n    -r      Reset all the counters (root only)"
     47//usage:     "\n    -n      Disable byte order auto-detection"
    3448
    3549#include "libbb.h"
     
    150164        if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3)
    151165            bb_error_msg_and_die("%s(%i): wrong map line",
    152                          mapFile, maplineno);
     166                    mapFile, maplineno);
    153167
    154168        if (!strcmp(fn_name, "_stext")) /* only elf works like this */ {
     
    185199        if (indx >= len / sizeof(*buf))
    186200            bb_error_msg_and_die("profile address out of range. "
    187                          "Wrong map file?");
     201                    "Wrong map file?");
    188202
    189203        while (indx < (next_add-add0)/step) {
     
    207221            if (optVerbose)
    208222                printf("%016llx %-40s %6i %8.4f\n", fn_add,
    209                        fn_name, this, this/(double)fn_len);
     223                    fn_name, this, this/(double)fn_len);
    210224            else
    211225                printf("%6i %-40s %8.4f\n",
    212                        this, fn_name, this/(double)fn_len);
     226                    this, fn_name, this/(double)fn_len);
    213227            if (optSub) {
    214228                unsigned long long scan;
     
    220234                    addr = (scan - 1)*step + add0;
    221235                    printf("\t%#llx\t%s+%#llx\t%u\n",
    222                            addr, fn_name, addr - fn_add,
    223                            buf[scan]);
     236                        addr, fn_name, addr - fn_add,
     237                        buf[scan]);
    224238                }
    225239            }
     
    238252    if (optVerbose)
    239253        printf("%016x %-40s %6i %8.4f\n",
    240                0, "total", total, total/(double)(fn_add-add0));
     254            0, "total", total, total/(double)(fn_add-add0));
    241255    else
    242256        printf("%6i %-40s %8.4f\n",
    243                total, "total", total/(double)(fn_add-add0));
     257            total, "total", total/(double)(fn_add-add0));
    244258
    245259    fclose(map);
  • branches/3.2/mindi-busybox/util-linux/rev.c

    r2725 r3232  
    77 */
    88
    9 //applet:IF_REV(APPLET(rev, _BB_DIR_BIN, _BB_SUID_DROP))
     9//applet:IF_REV(APPLET(rev, BB_DIR_BIN, BB_SUID_DROP))
    1010
    1111//kbuild:lib-$(CONFIG_REV) += rev.o
  • branches/3.2/mindi-busybox/util-linux/rtcwake.c

    r2725 r3232  
    2323 * That flag should not be needed on systems with adjtime support.
    2424 */
     25
     26//usage:#define rtcwake_trivial_usage
     27//usage:       "[-a | -l | -u] [-d DEV] [-m MODE] [-s SEC | -t TIME]"
     28//usage:#define rtcwake_full_usage "\n\n"
     29//usage:       "Enter a system sleep state until specified wakeup time\n"
     30//usage:    IF_LONG_OPTS(
     31//usage:     "\n    -a,--auto   Read clock mode from adjtime"
     32//usage:     "\n    -l,--local  Clock is set to local time"
     33//usage:     "\n    -u,--utc    Clock is set to UTC time"
     34//usage:     "\n    -d,--device=DEV Specify the RTC device"
     35//usage:     "\n    -m,--mode=MODE  Set the sleep state (default: standby)"
     36//usage:     "\n    -s,--seconds=SEC Set the timeout in SEC seconds from now"
     37//usage:     "\n    -t,--time=TIME  Set the timeout to TIME seconds from epoch"
     38//usage:    )
     39//usage:    IF_NOT_LONG_OPTS(
     40//usage:     "\n    -a  Read clock mode from adjtime"
     41//usage:     "\n    -l  Clock is set to local time"
     42//usage:     "\n    -u  Clock is set to UTC time"
     43//usage:     "\n    -d DEV  Specify the RTC device"
     44//usage:     "\n    -m MODE Set the sleep state (default: standby)"
     45//usage:     "\n    -s SEC  Set the timeout in SEC seconds from now"
     46//usage:     "\n    -t TIME Set the timeout to TIME seconds from epoch"
     47//usage:    )
    2548
    2649#include "libbb.h"
  • branches/3.2/mindi-busybox/util-linux/script.c

    r2725 r3232  
    1111 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1212 */
     13
     14//usage:#define script_trivial_usage
     15//usage:       "[-afq" IF_SCRIPTREPLAY("t") "] [-c PROG] [OUTFILE]"
     16//usage:#define script_full_usage "\n\n"
     17//usage:       "    -a  Append output"
     18//usage:     "\n    -c PROG Run PROG, not shell"
     19//usage:     "\n    -f  Flush output after each write"
     20//usage:     "\n    -q  Quiet"
     21//usage:    IF_SCRIPTREPLAY(
     22//usage:     "\n    -t  Send timing to stderr"
     23//usage:    )
     24
    1325#include "libbb.h"
    1426
     
    6678        printf("Script started, file is %s\n", fname);
    6779    }
    68     shell = getenv("SHELL");
    69     if (shell == NULL) {
    70         shell = DEFAULT_SHELL;
    71     }
     80    shell = get_shell_name();
    7281
    7382    pty = xgetpty(pty_line);
  • branches/3.2/mindi-busybox/util-linux/scriptreplay.c

    r2725 r3232  
    88 *
    99 */
     10
     11//usage:#define scriptreplay_trivial_usage
     12//usage:       "timingfile [typescript [divisor]]"
     13//usage:#define scriptreplay_full_usage "\n\n"
     14//usage:       "Play back typescripts, using timing information"
     15
    1016#include "libbb.h"
    1117
  • branches/3.2/mindi-busybox/util-linux/setarch.c

    r2725 r3232  
    66 *
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    8 */
     8 */
     9
     10//usage:#define setarch_trivial_usage
     11//usage:       "personality PROG ARGS"
     12//usage:#define setarch_full_usage "\n\n"
     13//usage:       "Personality may be:\n"
     14//usage:       "    linux32     Set 32bit uname emulation\n"
     15//usage:       "    linux64     Set 64bit uname emulation"
     16//usage:
     17//usage:#define linux32_trivial_usage NOUSAGE_STR
     18//usage:#define linux32_full_usage ""
     19//usage:
     20//usage:#define linux64_trivial_usage NOUSAGE_STR
     21//usage:#define linux64_full_usage ""
    922
    1023#include <sys/personality.h>
  • branches/3.2/mindi-busybox/util-linux/swaponoff.c

    r2725 r3232  
    88 */
    99
     10//usage:#define swapon_trivial_usage
     11//usage:       "[-a]" IF_FEATURE_SWAPON_PRI(" [-p PRI]") " [DEVICE]"
     12//usage:#define swapon_full_usage "\n\n"
     13//usage:       "Start swapping on DEVICE\n"
     14//usage:     "\n    -a  Start swapping on all swap devices"
     15//usage:    IF_FEATURE_SWAPON_PRI(
     16//usage:     "\n    -p PRI  Set swap device priority"
     17//usage:    )
     18//usage:
     19//usage:#define swapoff_trivial_usage
     20//usage:       "[-a] [DEVICE]"
     21//usage:#define swapoff_full_usage "\n\n"
     22//usage:       "Stop swapping on DEVICE\n"
     23//usage:     "\n    -a  Stop swapping on all swap devices"
     24
    1025#include "libbb.h"
    1126#include <mntent.h>
    12 #include <sys/swap.h>
     27#ifndef __BIONIC__
     28# include <sys/swap.h>
     29#endif
    1330
    1431#if ENABLE_FEATURE_MOUNT_LABEL
     
    1633#else
    1734# define resolve_mount_spec(fsname) ((void)0)
     35#endif
     36
     37#ifndef MNTTYPE_SWAP
     38# define MNTTYPE_SWAP "swap"
    1839#endif
    1940
     
    2748#define g_flags 0
    2849#endif
     50#define INIT_G() do { } while (0)
    2951
    3052static int swap_enable_disable(char *device)
     
    90112    int ret;
    91113
     114    INIT_G();
     115
    92116#if !ENABLE_FEATURE_SWAPON_PRI
    93117    ret = getopt32(argv, "a");
    94118#else
    95     opt_complementary = "p+";
     119    if (applet_name[5] == 'n')
     120        opt_complementary = "p+";
    96121    ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags);
    97122
  • branches/3.2/mindi-busybox/util-linux/switch_root.c

    r2725 r3232  
    66 * Licensed under GPLv2, see file LICENSE in this source tree.
    77 */
     8
     9//usage:#define switch_root_trivial_usage
     10//usage:       "[-c /dev/console] NEW_ROOT NEW_INIT [ARGS]"
     11//usage:#define switch_root_full_usage "\n\n"
     12//usage:       "Free initramfs and switch to another root fs:\n"
     13//usage:       "chroot to NEW_ROOT, delete all in /, move NEW_ROOT to /,\n"
     14//usage:       "execute NEW_INIT. PID must be 1. NEW_ROOT must be a mountpoint.\n"
     15//usage:     "\n    -c DEV  Reopen stdio to DEV after switch"
     16
    817#include <sys/vfs.h>
    918#include <sys/mount.h>
     
    106115    xchroot(".");
    107116    // The chdir is needed to recalculate "." and ".." links
    108     xchdir("/");
     117    /*xchdir("/"); - done in xchroot */
    109118
    110119    // If a new console specified, redirect stdin/stdout/stderr to it
  • branches/3.2/mindi-busybox/util-linux/umount.c

    r2725 r3232  
    88 * Licensed under GPLv2, see file LICENSE in this source tree.
    99 */
     10
     11//usage:#define umount_trivial_usage
     12//usage:       "[OPTIONS] FILESYSTEM|DIRECTORY"
     13//usage:#define umount_full_usage "\n\n"
     14//usage:       "Unmount file systems\n"
     15//usage:    IF_FEATURE_UMOUNT_ALL(
     16//usage:     "\n    -a  Unmount all file systems" IF_FEATURE_MTAB_SUPPORT(" in /etc/mtab")
     17//usage:    )
     18//usage:    IF_FEATURE_MTAB_SUPPORT(
     19//usage:     "\n    -n  Don't erase /etc/mtab entries"
     20//usage:    )
     21//usage:     "\n    -r  Try to remount devices as read-only if mount is busy"
     22//usage:     "\n    -l  Lazy umount (detach filesystem)"
     23//usage:     "\n    -f  Force umount (i.e., unreachable NFS server)"
     24//usage:    IF_FEATURE_MOUNT_LOOP(
     25//usage:     "\n    -D  Don't free loop device even if it has been used"
     26//usage:    )
     27//usage:
     28//usage:#define umount_example_usage
     29//usage:       "$ umount /dev/hdc1\n"
     30
    1031#include <mntent.h>
    1132#include <sys/mount.h>
     
    2445#endif
    2546
    26 /* ignored: -v -d -t -i */
    27 #define OPTION_STRING           "fldnra" "vdt:i"
     47/* Ignored: -v -t -i
     48 * bbox always acts as if -d is present.
     49 * -D can be used to suppress it (bbox extension).
     50 * Rationale:
     51 * (1) util-linux's umount does it if "loop=..." is seen in /etc/mtab:
     52 * thus, on many systems, bare umount _does_ drop loop devices.
     53 * (2) many users request this feature.
     54 */
     55#define OPTION_STRING           "fldDnra" "vt:i"
    2856#define OPT_FORCE               (1 << 0) // Same as MNT_FORCE
    2957#define OPT_LAZY                (1 << 1) // Same as MNT_DETACH
    30 #define OPT_FREELOOP            (1 << 2)
    31 #define OPT_NO_MTAB             (1 << 3)
    32 #define OPT_REMOUNT             (1 << 4)
    33 #define OPT_ALL                 (ENABLE_FEATURE_UMOUNT_ALL ? (1 << 5) : 0)
     58//#define OPT_FREE_LOOP           (1 << 2) // -d is assumed always present
     59#define OPT_DONT_FREE_LOOP      (1 << 3)
     60#define OPT_NO_MTAB             (1 << 4)
     61#define OPT_REMOUNT             (1 << 5)
     62#define OPT_ALL                 (ENABLE_FEATURE_UMOUNT_ALL ? (1 << 6) : 0)
    3463
    3564int umount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    145174            // De-allocate the loop device.  This ioctl should be ignored on
    146175            // any non-loop block devices.
    147             if (ENABLE_FEATURE_MOUNT_LOOP && (opt & OPT_FREELOOP) && m)
     176            if (ENABLE_FEATURE_MOUNT_LOOP && !(opt & OPT_DONT_FREE_LOOP) && m)
    148177                del_loop(m->device);
    149178            if (ENABLE_FEATURE_MTAB_SUPPORT && !(opt & OPT_NO_MTAB) && m)
  • branches/3.2/mindi-busybox/util-linux/volume_id/Kbuild.src

    r2725 r3232  
    3232### lib-$(CONFIG_FEATURE_VOLUMEID_MAC)              += mac.o
    3333### lib-$(CONFIG_FEATURE_VOLUMEID_MSDOS)            += msdos.o
     34lib-$(CONFIG_FEATURE_VOLUMEID_NILFS)            += nilfs.o
    3435lib-$(CONFIG_FEATURE_VOLUMEID_NTFS)             += ntfs.o
     36lib-$(CONFIG_FEATURE_VOLUMEID_EXFAT)            += exfat.o
    3537lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS)         += reiserfs.o
    3638lib-$(CONFIG_FEATURE_VOLUMEID_UDF)              += udf.o
  • branches/3.2/mindi-busybox/util-linux/volume_id/btrfs.c

    r2725 r3232  
    103103    volume_id_set_label_string(id, sb->label, VOLUME_ID_LABEL_SIZE);
    104104    volume_id_set_uuid(id, sb->fsid, UUID_DCE);
     105    IF_FEATURE_BLKID_TYPE(id->type = "btrfs";)
    105106
    106107    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/cramfs.c

    r2725 r3232  
    5252
    5353//      volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    54 //      id->type = "cramfs";
     54        IF_FEATURE_BLKID_TYPE(id->type = "cramfs";)
    5555        return 0;
    5656    }
  • branches/3.2/mindi-busybox/util-linux/volume_id/ext.c

    r2725 r3232  
    2020
    2121#include "volume_id_internal.h"
     22#include "bb_e2fs_defs.h"
    2223
    23 struct ext2_super_block {
    24     uint32_t    inodes_count;
    25     uint32_t    blocks_count;
    26     uint32_t    r_blocks_count;
    27     uint32_t    free_blocks_count;
    28     uint32_t    free_inodes_count;
    29     uint32_t    first_data_block;
    30     uint32_t    log_block_size;
    31     uint32_t    dummy3[7];
    32     uint8_t magic[2];
    33     uint16_t    state;
    34     uint32_t    dummy5[8];
    35     uint32_t    feature_compat;
    36     uint32_t    feature_incompat;
    37     uint32_t    feature_ro_compat;
    38     uint8_t uuid[16];
    39     uint8_t volume_name[16];
    40 } PACKED;
    41 
    42 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL     0x00000004
    43 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV   0x00000008
    4424#define EXT_SUPERBLOCK_OFFSET           0x400
    4525
     
    5535        return -1;
    5636
    57     if (es->magic[0] != 0123 || es->magic[1] != 0357) {
     37    if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) {
    5838        dbg("ext: no magic found");
    5939        return -1;
     
    6242//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    6343//  volume_id_set_label_raw(id, es->volume_name, 16);
    64     volume_id_set_label_string(id, es->volume_name, 16);
    65     volume_id_set_uuid(id, es->uuid, UUID_DCE);
     44    volume_id_set_label_string(id, (void*)es->s_volume_name, 16);
     45    volume_id_set_uuid(id, es->s_uuid, UUID_DCE);
    6646    dbg("ext: label '%s' uuid '%s'", id->label, id->uuid);
    6747
    68 //  if ((le32_to_cpu(es->feature_compat) & EXT3_FEATURE_COMPAT_HAS_JOURNAL) != 0)
    69 //      id->type = "ext3";
    70 //  else
    71 //      id->type = "ext2";
    72 
     48#if ENABLE_FEATURE_BLKID_TYPE
     49    if ((es->s_feature_ro_compat & cpu_to_le32(EXT4_FEATURE_RO_COMPAT_HUGE_FILE | EXT4_FEATURE_RO_COMPAT_DIR_NLINK))
     50     || (es->s_feature_incompat & cpu_to_le32(EXT4_FEATURE_INCOMPAT_EXTENTS | EXT4_FEATURE_INCOMPAT_64BIT))
     51    ) {
     52        id->type = "ext4";
     53    }
     54    else if (es->s_feature_compat & cpu_to_le32(EXT3_FEATURE_COMPAT_HAS_JOURNAL))
     55        id->type = "ext3";
     56    else
     57        id->type = "ext2";
     58#endif
    7359    return 0;
    7460}
  • branches/3.2/mindi-busybox/util-linux/volume_id/fat.c

    r2725 r3232  
    333333 ret:
    334334//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    335 //  id->type = "vfat";
     335    IF_FEATURE_BLKID_TYPE(id->type = "vfat";)
    336336
    337337    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/get_devname.c

    r2725 r3232  
    2020    char *label;
    2121    char *uc_uuid; /* prefix makes it easier to grep for */
     22    IF_FEATURE_BLKID_TYPE(const char *type;)
    2223} *uuidCache;
     24
     25#if !ENABLE_FEATURE_BLKID_TYPE
     26#define get_label_uuid(fd, label, uuid, type) \
     27    get_label_uuid(fd, label, uuid)
     28#define uuidcache_addentry(device, label, uuid, type) \
     29    uuidcache_addentry(device, label, uuid)
     30#endif
    2331
    2432/* Returns !0 on error.
     
    2735 * NB: closes fd. */
    2836static int
    29 get_label_uuid(int fd, char **label, char **uuid)
     37get_label_uuid(int fd, char **label, char **uuid, const char **type)
    3038{
    3139    int rv = 1;
     
    4250        goto ret;
    4351
    44     if (vid->label[0] != '\0' || vid->uuid[0] != '\0') {
     52    if (vid->label[0] != '\0' || vid->uuid[0] != '\0'
     53#if ENABLE_FEATURE_BLKID_TYPE
     54     || vid->type != NULL
     55#endif
     56    ) {
    4557        *label = xstrndup(vid->label, sizeof(vid->label));
    4658        *uuid  = xstrndup(vid->uuid, sizeof(vid->uuid));
     59#if ENABLE_FEATURE_BLKID_TYPE
     60        *type = vid->type;
     61        dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type);
     62#else
    4763        dbg("found label '%s', uuid '%s'", *label, *uuid);
     64#endif
    4865        rv = 0;
    4966    }
     
    5572/* NB: we take ownership of (malloc'ed) label and uuid */
    5673static void
    57 uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid)
     74uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type)
    5875{
    5976    struct uuidCache_s *last;
     
    7390    last->label = label;
    7491    last->uc_uuid = uuid;
     92    IF_FEATURE_BLKID_TYPE(last->type = type;)
    7593}
    7694
     
    84102        int depth UNUSED_PARAM)
    85103{
    86     char *uuid = uuid; /* for compiler */
    87     char *label = label;
    88     int fd;
    89 
    90104    /* note: this check rejects links to devices, among other nodes */
    91105    if (!S_ISBLK(statbuf->st_mode))
     
    100114        return TRUE;
    101115
    102     fd = open(device, O_RDONLY);
    103     if (fd < 0)
    104         return TRUE;
    105 
    106     /* get_label_uuid() closes fd in all cases (success & failure) */
    107     if (get_label_uuid(fd, &label, &uuid) == 0) {
    108         /* uuidcache_addentry() takes ownership of all three params */
    109         uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid);
    110     }
     116    add_to_uuid_cache(device);
     117
    111118    return TRUE;
    112119}
    113120
    114 static void
    115 uuidcache_init(void)
    116 {
     121static struct uuidCache_s*
     122uuidcache_init(int scan_devices)
     123{
     124    dbg("DBG: uuidCache=%x, uuidCache");
    117125    if (uuidCache)
    118         return;
     126        return uuidCache;
    119127
    120128    /* We were scanning /proc/partitions
     
    128136     * (Maybe add scanning of /sys/block/XXX/dev for devices
    129137     * somehow not having their /dev/XXX entries created?) */
    130 
    131     recursive_action("/dev", ACTION_RECURSE,
    132         uuidcache_check_device, /* file_action */
    133         NULL, /* dir_action */
    134         NULL, /* userData */
    135         0 /* depth */);
     138    if (scan_devices)
     139        recursive_action("/dev", ACTION_RECURSE,
     140            uuidcache_check_device, /* file_action */
     141            NULL, /* dir_action */
     142            NULL, /* userData */
     143            0 /* depth */);
     144
     145    return uuidCache;
    136146}
    137147
     
    145155    struct uuidCache_s *uc;
    146156
    147     uuidcache_init();
    148     uc = uuidCache;
    149 
     157    uc = uuidcache_init(/*scan_devices:*/ 1);
    150158    while (uc) {
    151159        switch (n) {
     
    212220
    213221/* Used by blkid */
    214 void display_uuid_cache(void)
    215 {
    216     struct uuidCache_s *u;
    217 
    218     uuidcache_init();
    219     u = uuidCache;
    220     while (u) {
    221         printf("%s:", u->device);
    222         if (u->label[0])
    223             printf(" LABEL=\"%s\"", u->label);
    224         if (u->uc_uuid[0])
    225             printf(" UUID=\"%s\"", u->uc_uuid);
     222void display_uuid_cache(int scan_devices)
     223{
     224    struct uuidCache_s *uc;
     225
     226    uc = uuidcache_init(scan_devices);
     227    while (uc) {
     228        printf("%s:", uc->device);
     229        if (uc->label[0])
     230            printf(" LABEL=\"%s\"", uc->label);
     231        if (uc->uc_uuid[0])
     232            printf(" UUID=\"%s\"", uc->uc_uuid);
     233#if ENABLE_FEATURE_BLKID_TYPE
     234    if (uc->type)
     235        printf(" TYPE=\"%s\"", uc->type);
     236#endif
    226237        bb_putchar('\n');
    227         u = u->next;
    228     }
    229 }
     238        uc = uc->next;
     239    }
     240}
     241
     242int add_to_uuid_cache(const char *device)
     243{
     244    char *uuid = uuid; /* for compiler */
     245    char *label = label;
     246#if ENABLE_FEATURE_BLKID_TYPE
     247    const char *type = type;
     248#endif
     249    int fd;
     250
     251    fd = open(device, O_RDONLY);
     252    if (fd < 0)
     253        return 0;
     254
     255    /* get_label_uuid() closes fd in all cases (success & failure) */
     256    if (get_label_uuid(fd, &label, &uuid, &type) == 0) {
     257        /* uuidcache_addentry() takes ownership of all four params */
     258        uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid, type);
     259        return 1;
     260    }
     261    return 0;
     262}
     263
    230264
    231265/* Used by mount and findfs */
     
    235269    struct uuidCache_s *uc;
    236270
    237     uuidcache_init();
    238     uc = uuidCache;
     271    uc = uuidcache_init(/*scan_devices:*/ 1);
    239272    while (uc) {
    240273        if (uc->label[0] && strcmp(spec, uc->label) == 0) {
     
    250283    struct uuidCache_s *uc;
    251284
    252     uuidcache_init();
    253     uc = uuidCache;
     285    uc = uuidcache_init(/*scan_devices:*/ 1);
    254286    while (uc) {
    255287        /* case of hex numbers doesn't matter */
  • branches/3.2/mindi-busybox/util-linux/volume_id/hfs.c

    r2725 r3232  
    132132#define HFSPLUS_POR_CNID        1
    133133
     134static void FAST_FUNC hfs_set_uuid(struct volume_id *id, const uint8_t *hfs_id)
     135{
     136#define hfs_id_len 8
     137    md5_ctx_t md5c;
     138    uint8_t uuid[16];
     139    unsigned i;
     140
     141    for (i = 0; i < hfs_id_len; i++)
     142        if (hfs_id[i] != 0)
     143            goto do_md5;
     144    return;
     145 do_md5:
     146    md5_begin(&md5c);
     147    md5_hash(&md5c, "\263\342\17\71\362\222\21\326\227\244\0\60\145\103\354\254", 16);
     148    md5_hash(&md5c, hfs_id, hfs_id_len);
     149    md5_end(&md5c, uuid);
     150    uuid[6] = 0x30 | (uuid[6] & 0x0f);
     151    uuid[8] = 0x80 | (uuid[8] & 0x3f);
     152    volume_id_set_uuid(id, uuid, UUID_DCE);
     153}
     154
    134155int FAST_FUNC volume_id_probe_hfs_hfsplus(struct volume_id *id /*,uint64_t off*/)
    135156{
     
    194215    }
    195216
    196     volume_id_set_uuid(id, hfs->finder_info.id, UUID_HFS);
     217    hfs_set_uuid(id, hfs->finder_info.id);
    197218//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    198 //  id->type = "hfs";
     219    IF_FEATURE_BLKID_TYPE(id->type = "hfs";)
    199220
    200221    return 0;
     
    208229
    209230 hfsplus:
    210     volume_id_set_uuid(id, hfsplus->finder_info.id, UUID_HFS);
     231    hfs_set_uuid(id, hfsplus->finder_info.id);
    211232
    212233    blocksize = be32_to_cpu(hfsplus->blocksize);
     
    287308 found:
    288309//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    289 //  id->type = "hfsplus";
     310    IF_FEATURE_BLKID_TYPE(id->type = "hfsplus";)
    290311
    291312    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/iso9660.c

    r2725 r3232  
    115115 found:
    116116//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    117 //  id->type = "iso9660";
     117    IF_FEATURE_BLKID_TYPE(id->type = "iso9660";)
    118118
    119119    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/jfs.c

    r2725 r3232  
    5555
    5656//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    57 //  id->type = "jfs";
     57    IF_FEATURE_BLKID_TYPE(id->type = "jfs";)
    5858
    5959    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/linux_raid.c

    r2725 r3232  
    7070
    7171//  snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u",
    72 //       le32_to_cpu(mdp->major_version),
    73 //       le32_to_cpu(mdp->minor_version),
    74 //       le32_to_cpu(mdp->patch_version));
     72//      le32_to_cpu(mdp->major_version),
     73//      le32_to_cpu(mdp->minor_version),
     74//      le32_to_cpu(mdp->patch_version));
    7575
    7676    dbg("found raid signature");
    7777//  volume_id_set_usage(id, VOLUME_ID_RAID);
    78 //  id->type = "linux_raid_member";
     78    IF_FEATURE_BLKID_TYPE(id->type = "linux_raid_member";)
    7979
    8080    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/linux_swap.c

    r2725 r3232  
    7373found:
    7474//  volume_id_set_usage(id, VOLUME_ID_OTHER);
    75 //  id->type = "swap";
     75    IF_FEATURE_BLKID_TYPE(id->type = "swap";)
    7676
    7777    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/luks.c

    r2725 r3232  
    9595//  volume_id_set_usage(id, VOLUME_ID_CRYPTO);
    9696    volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING);
    97 //  id->type = "crypto_LUKS";
     97    IF_FEATURE_BLKID_TYPE(id->type = "crypto_LUKS";)
    9898
    9999    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/ntfs.c

    r2725 r3232  
    133133
    134134    buf = volume_id_get_buffer(id, off + mft_off + (MFT_RECORD_VOLUME * mft_record_size),
    135              mft_record_size);
     135            mft_record_size);
    136136    if (buf == NULL)
    137137        goto found;
     
    151151        attr = (struct file_attribute*) &buf[attr_off];
    152152        attr_type = le32_to_cpu(attr->type);
    153         attr_len = le16_to_cpu(attr->len);
     153        attr_len = le32_to_cpu(attr->len);
    154154        val_off = le16_to_cpu(attr->value_offset);
    155155        val_len = le32_to_cpu(attr->value_len);
     
    166166
    167167        dbg("found attribute type 0x%x, len %i, at offset %i",
    168             attr_type, attr_len, attr_off);
     168            attr_type, attr_len, attr_off);
    169169
    170170//      if (attr_type == MFT_RECORD_ATTR_VOLUME_INFO) {
     
    189189 found:
    190190//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    191 //  id->type = "ntfs";
     191    IF_FEATURE_BLKID_TYPE(id->type = "ntfs";)
    192192
    193193    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/ocfs2.c

    r2725 r3232  
    102102                    OCFS2_MAX_VOL_LABEL_LEN : VOLUME_ID_LABEL_SIZE);
    103103    volume_id_set_uuid(id, os->s_uuid, UUID_DCE);
    104 //  id->type = "ocfs2";
     104    IF_FEATURE_BLKID_TYPE(id->type = "ocfs2";)
    105105    return 0;
    106106}
  • branches/3.2/mindi-busybox/util-linux/volume_id/reiserfs.c

    r2725 r3232  
    108108 found:
    109109//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    110 //  id->type = "reiserfs";
     110    IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";)
    111111
    112112    return 0;
  • branches/3.2/mindi-busybox/util-linux/volume_id/romfs.c

    r2725 r3232  
    4848
    4949//      volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    50 //      id->type = "romfs";
     50        IF_FEATURE_BLKID_TYPE(id->type = "romfs";)
    5151        return 0;
    5252    }
  • branches/3.2/mindi-busybox/util-linux/volume_id/sysv.c

    r2725 r3232  
    100100//          volume_id_set_label_raw(id, vs->s_fname, 6);
    101101            volume_id_set_label_string(id, vs->s_fname, 6);
    102 //          id->type = "sysv";
     102            IF_FEATURE_BLKID_TYPE(id->type = "sysv");
    103103            goto found;
    104104        }
     
    113113//          volume_id_set_label_raw(id, xs->s_fname, 6);
    114114            volume_id_set_label_string(id, xs->s_fname, 6);
    115 //          id->type = "xenix";
     115            IF_FEATURE_BLKID_TYPE(id->type = "xenix";)
    116116            goto found;
    117117        }
  • branches/3.2/mindi-busybox/util-linux/volume_id/udf.c

    r2725 r3232  
    110110
    111111        dbg("vsd: %c%c%c%c%c",
    112             vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]);
     112            vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]);
    113113
    114114        if (vsd->id[0] == '\0')
     
    168168 found:
    169169//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    170 //  id->type = "udf";
    171 
     170    IF_FEATURE_BLKID_TYPE(id->type = "udf";)
    172171    return 0;
    173172}
  • branches/3.2/mindi-busybox/util-linux/volume_id/unused_msdos.c

    r2725 r3232  
    110110        } else {
    111111            dbg("found 0x%x data partition at 0x%llx, len 0x%llx",
    112                 part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen);
     112                part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen);
    113113
    114114//          if (is_raid(part[i].sys_ind))
  • branches/3.2/mindi-busybox/util-linux/volume_id/unused_silicon_raid.c

    r2725 r3232  
    6363//  volume_id_set_usage(id, VOLUME_ID_RAID);
    6464//  snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u",
    65 //       le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver));
     65//      le16_to_cpu(sil->major_ver), le16_to_cpu(sil->minor_ver));
    6666//  id->type = "silicon_medley_raid_member";
    6767
  • branches/3.2/mindi-busybox/util-linux/volume_id/util.c

    r2725 r3232  
    3232        else
    3333            c = (buf[i] << 8) | buf[i+1];
    34         if (c == 0) {
    35             str[j] = '\0';
     34        if (c == 0)
    3635            break;
    37         } else if (c < 0x80) {
    38             if (j+1 >= len)
    39                 break;
    40             str[j++] = (uint8_t) c;
    41         } else if (c < 0x800) {
     36        if (j+1 >= len)
     37            break;
     38        if (c < 0x80) {
     39            /* 0xxxxxxx */
     40        } else {
     41            uint8_t topbits = 0xc0;
    4242            if (j+2 >= len)
    4343                break;
    44             str[j++] = (uint8_t) (0xc0 | (c >> 6));
    45             str[j++] = (uint8_t) (0x80 | (c & 0x3f));
    46         } else {
    47             if (j+3 >= len)
    48                 break;
    49             str[j++] = (uint8_t) (0xe0 | (c >> 12));
    50             str[j++] = (uint8_t) (0x80 | ((c >> 6) & 0x3f));
    51             str[j++] = (uint8_t) (0x80 | (c & 0x3f));
     44            if (c < 0x800) {
     45                /* 110yyyxx 10xxxxxx */
     46            } else {
     47                if (j+3 >= len)
     48                    break;
     49                /* 1110yyyy 10yyyyxx 10xxxxxx */
     50                str[j++] = (uint8_t) (0xe0 | (c >> 12));
     51                topbits = 0x80;
     52            }
     53            str[j++] = (uint8_t) (topbits | ((c >> 6) & 0x3f));
     54            c = 0x80 | (c & 0x3f);
    5255        }
     56        str[j++] = (uint8_t) c;
    5357    }
    5458    str[j] = '\0';
     
    126130void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count)
    127131{
    128      volume_id_set_unicode16(id->label, sizeof(id->label), buf, endianess, count);
     132    volume_id_set_unicode16(id->label, sizeof(id->label), buf, endianess, count);
    129133}
    130134
     
    132136{
    133137    unsigned i;
    134     unsigned count = 0;
    135 
    136     switch (format) {
    137     case UUID_DOS:
    138         count = 4;
    139         break;
    140     case UUID_NTFS:
    141     case UUID_HFS:
    142         count = 8;
    143         break;
    144     case UUID_DCE:
    145         count = 16;
    146         break;
    147     case UUID_DCE_STRING:
    148         /* 36 is ok, id->uuid has one extra byte for NUL */
    149         count = VOLUME_ID_UUID_SIZE;
    150         break;
    151     }
     138    unsigned count = (format == UUID_DCE_STRING ? VOLUME_ID_UUID_SIZE : 4 << format);
     139
    152140//  memcpy(id->uuid_raw, buf, count);
    153141//  id->uuid_raw_len = count;
     
    169157            buf[7], buf[6], buf[5], buf[4],
    170158            buf[3], buf[2], buf[1], buf[0]);
    171         break;
    172     case UUID_HFS:
    173         sprintf(id->uuid, "%02X%02X%02X%02X%02X%02X%02X%02X",
    174             buf[0], buf[1], buf[2], buf[3],
    175             buf[4], buf[5], buf[6], buf[7]);
    176159        break;
    177160    case UUID_DCE:
  • branches/3.2/mindi-busybox/util-linux/volume_id/volume_id.c

    r2725 r3232  
    9494    volume_id_probe_vfat,
    9595#endif
     96#if ENABLE_FEATURE_VOLUMEID_EXFAT
     97    volume_id_probe_exfat,
     98#endif
    9699#if ENABLE_FEATURE_VOLUMEID_MAC
    97100    volume_id_probe_mac_partition_map,
     101#endif
     102#if ENABLE_FEATURE_VOLUMEID_SQUASHFS
     103    volume_id_probe_squashfs,
    98104#endif
    99105#if ENABLE_FEATURE_VOLUMEID_XFS
     
    130136#if ENABLE_FEATURE_VOLUMEID_UFS
    131137    volume_id_probe_ufs,
     138#endif
     139#if ENABLE_FEATURE_VOLUMEID_NILFS
     140    volume_id_probe_nilfs,
    132141#endif
    133142#if ENABLE_FEATURE_VOLUMEID_NTFS
  • branches/3.2/mindi-busybox/util-linux/volume_id/volume_id_internal.h

    r2725 r3232  
    8181//  smallint    usage_id;
    8282//  const char  *usage;
    83 //  const char  *type;
     83#if ENABLE_FEATURE_BLKID_TYPE
     84    const char  *type;
     85#endif
    8486};
    8587
     
    135137#endif
    136138
     139/* volume_id_set_uuid(id,buf,fmt) assumes size of uuid buf
     140 * by shifting: 4 << fmt, except for fmt == UUID_DCE_STRING.
     141 * The constants below should match sizes.
     142 */
    137143enum uuid_format {
    138     UUID_DCE_STRING,
    139     UUID_DCE,
    140     UUID_DOS,
    141     UUID_NTFS,
    142     UUID_HFS,
     144    UUID_DOS = 0,       /* 4 bytes */
     145    UUID_NTFS = 1,      /* 8 bytes */
     146    UUID_DCE = 2,       /* 16 bytes */
     147    UUID_DCE_STRING = 3,    /* 36 bytes (VOLUME_ID_UUID_SIZE) */
    143148};
    144149
     
    211216//int FAST_FUNC volume_id_probe_msdos_part_table(struct volume_id *id /*,uint64_t off*/);
    212217
     218int FAST_FUNC volume_id_probe_nilfs(struct volume_id *id /*,uint64_t off*/);
     219
    213220int FAST_FUNC volume_id_probe_ntfs(struct volume_id *id /*,uint64_t off*/);
    214221
     222int FAST_FUNC volume_id_probe_exfat(struct volume_id *id /*,uint64_t off*/);
     223
    215224int FAST_FUNC volume_id_probe_ocfs2(struct volume_id *id /*,uint64_t off*/);
    216225
     
    219228int FAST_FUNC volume_id_probe_romfs(struct volume_id *id /*,uint64_t off*/);
    220229
     230int FAST_FUNC volume_id_probe_squashfs(struct volume_id *id /*,uint64_t off*/);
     231
    221232int FAST_FUNC volume_id_probe_sysv(struct volume_id *id /*,uint64_t off*/);
    222233
  • branches/3.2/mindi-busybox/util-linux/volume_id/xfs.c

    r2725 r3232  
    5555
    5656//  volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
    57 //  id->type = "xfs";
     57    IF_FEATURE_BLKID_TYPE(id->type = "xfs";)
    5858
    5959    return 0;
Note: See TracChangeset for help on using the changeset viewer.