Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/miscutils/mountpoint.c

    r1765 r2725  
    33 * mountpoint implementation for busybox
    44 *
    5  * Copyright (C) 2005 Bernhard Fischer
     5 * Copyright (C) 2005 Bernhard Reutner-Fischer
    66 *
    7  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 *
    99 * Based on sysvinit's mountpoint
     
    1212#include "libbb.h"
    1313
    14 int mountpoint_main(int argc, char **argv);
    15 int mountpoint_main(int argc, char **argv)
     14int mountpoint_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     15int mountpoint_main(int argc UNUSED_PARAM, char **argv)
    1616{
    1717    struct stat st;
     18    const char *msg;
    1819    char *arg;
    19     int opt = getopt32(argv, "qdx");
     20    int rc, opt;
     21
     22    opt_complementary = "=1"; /* must have one argument */
     23    opt = getopt32(argv, "qdxn");
    2024#define OPT_q (1)
    2125#define OPT_d (2)
    2226#define OPT_x (4)
     27#define OPT_n (8)
     28    arg = argv[optind];
     29    msg = "%s";
    2330
    24     if (optind != argc - 1)
    25         bb_show_usage();
     31    rc = (opt & OPT_x) ? stat(arg, &st) : lstat(arg, &st);
     32    if (rc != 0)
     33        goto err;
    2634
    27     arg = argv[optind];
     35    if (opt & OPT_x) {
     36        if (S_ISBLK(st.st_mode)) {
     37            printf("%u:%u\n", major(st.st_rdev),
     38                        minor(st.st_rdev));
     39            return EXIT_SUCCESS;
     40        }
     41        errno = 0; /* make perror_msg work as error_msg */
     42        msg = "%s: not a block device";
     43        goto err;
     44    }
    2845
    29     if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) {
    30         if (opt & OPT_x) {
    31             if (S_ISBLK(st.st_mode)) {
    32                 printf("%u:%u\n", major(st.st_rdev),
    33                             minor(st.st_rdev));
    34                 return EXIT_SUCCESS;
    35             } else {
    36                 if (opt & OPT_q)
    37                     putchar('\n');
    38                 else
    39                     bb_error_msg("%s: not a block device", arg);
     46    errno = ENOTDIR;
     47    if (S_ISDIR(st.st_mode)) {
     48        dev_t st_dev = st.st_dev;
     49        ino_t st_ino = st.st_ino;
     50        char *p = xasprintf("%s/..", arg);
     51
     52        if (stat(p, &st) == 0) {
     53            //int is_mnt = (st_dev != st.st_dev) || (st_dev == st.st_dev && st_ino == st.st_ino);
     54            int is_not_mnt = (st_dev == st.st_dev) && (st_ino != st.st_ino);
     55
     56            if (opt & OPT_d)
     57                printf("%u:%u\n", major(st_dev), minor(st_dev));
     58            if (opt & OPT_n) {
     59                const char *d = find_block_device(arg);
     60                /* name is undefined, but device is mounted -> anonymous superblock! */
     61                /* happens with btrfs */
     62                if (!d) {
     63                    d = "UNKNOWN";
     64                    /* TODO: iterate /proc/mounts, or /proc/self/mountinfo
     65                     * to find out the device name */
     66                }
     67                printf("%s %s\n", d, arg);
    4068            }
    41             return EXIT_FAILURE;
    42         } else
    43         if (S_ISDIR(st.st_mode)) {
    44             dev_t st_dev = st.st_dev;
    45             ino_t st_ino = st.st_ino;
    46             char *p = xasprintf("%s/..", arg);
     69            if (!(opt & (OPT_q | OPT_d | OPT_n)))
     70                printf("%s is %sa mountpoint\n", arg, is_not_mnt ? "not " : "");
     71            return is_not_mnt;
     72        }
     73        arg = p;
     74        /* else: stat had set errno, just fall through */
     75    }
    4776
    48             if (stat(p, &st) == 0) {
    49                 int ret = (st_dev != st.st_dev) ||
    50                     (st_dev == st.st_dev && st_ino == st.st_ino);
    51                 if (opt & OPT_d)
    52                     printf("%u:%u\n", major(st_dev), minor(st_dev));
    53                 else if (!(opt & OPT_q))
    54                     printf("%s is %sa mountpoint\n", arg, ret?"":"not ");
    55                 return !ret;
    56             }
    57         } else {
    58             if (!(opt & OPT_q))
    59                 bb_error_msg("%s: not a directory", arg);
    60             return EXIT_FAILURE;
    61         }
    62     }
     77 err:
    6378    if (!(opt & OPT_q))
    64         bb_perror_msg("%s", arg);
     79        bb_perror_msg(msg, arg);
    6580    return EXIT_FAILURE;
    6681}
Note: See TracChangeset for help on using the changeset viewer.