Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/util-linux/mount.c

    r3232 r3621  
    1818//
    1919
     20//config:config MOUNT
     21//config:   bool "mount"
     22//config:   default y
     23//config:   select PLATFORM_LINUX
     24//config:   help
     25//config:     All files and filesystems in Unix are arranged into one big directory
     26//config:     tree. The 'mount' utility is used to graft a filesystem onto a
     27//config:     particular part of the tree. A filesystem can either live on a block
     28//config:     device, or it can be accessible over the network, as is the case with
     29//config:     NFS filesystems. Most people using BusyBox will also want to enable
     30//config:     the 'mount' utility.
     31//config:
     32//config:config FEATURE_MOUNT_FAKE
     33//config:   bool "Support option -f"
     34//config:   default y
     35//config:   depends on MOUNT
     36//config:   help
     37//config:     Enable support for faking a file system mount.
     38//config:
     39//config:config FEATURE_MOUNT_VERBOSE
     40//config:   bool "Support option -v"
     41//config:   default y
     42//config:   depends on MOUNT
     43//config:   help
     44//config:     Enable multi-level -v[vv...] verbose messages. Useful if you
     45//config:     debug mount problems and want to see what is exactly passed
     46//config:     to the kernel.
     47//config:
     48//config:config FEATURE_MOUNT_HELPERS
     49//config:   bool "Support mount helpers"
     50//config:   default n
     51//config:   depends on MOUNT
     52//config:   help
     53//config:     Enable mounting of virtual file systems via external helpers.
     54//config:     E.g. "mount obexfs#-b00.11.22.33.44.55 /mnt" will in effect call
     55//config:     "obexfs -b00.11.22.33.44.55 /mnt"
     56//config:     Also "mount -t sometype [-o opts] fs /mnt" will try
     57//config:     "sometype [-o opts] fs /mnt" if simple mount syscall fails.
     58//config:     The idea is to use such virtual filesystems in /etc/fstab.
     59//config:
     60//config:config FEATURE_MOUNT_LABEL
     61//config:   bool "Support specifying devices by label or UUID"
     62//config:   default y
     63//config:   depends on MOUNT
     64//config:   select VOLUMEID
     65//config:   help
     66//config:     This allows for specifying a device by label or uuid, rather than by
     67//config:     name. This feature utilizes the same functionality as blkid/findfs.
     68//config:     This also enables label or uuid support for swapon.
     69//config:
     70//config:config FEATURE_MOUNT_NFS
     71//config:   bool "Support mounting NFS file systems on Linux < 2.6.23"
     72//config:   default n
     73//config:   depends on MOUNT
     74//config:   select FEATURE_HAVE_RPC
     75//config:   select FEATURE_SYSLOG
     76//config:   help
     77//config:     Enable mounting of NFS file systems on Linux kernels prior
     78//config:     to version 2.6.23. Note that in this case mounting of NFS
     79//config:     over IPv6 will not be possible.
     80//config:
     81//config:     Note that this option links in RPC support from libc,
     82//config:     which is rather large (~10 kbytes on uclibc).
     83//config:
     84//config:config FEATURE_MOUNT_CIFS
     85//config:   bool "Support mounting CIFS/SMB file systems"
     86//config:   default y
     87//config:   depends on MOUNT
     88//config:   help
     89//config:     Enable support for samba mounts.
     90//config:
     91//config:config FEATURE_MOUNT_FLAGS
     92//config:   depends on MOUNT
     93//config:   bool "Support lots of -o flags in mount"
     94//config:   default y
     95//config:   help
     96//config:     Without this, mount only supports ro/rw/remount. With this, it
     97//config:     supports nosuid, suid, dev, nodev, exec, noexec, sync, async, atime,
     98//config:     noatime, diratime, nodiratime, loud, bind, move, shared, slave,
     99//config:     private, unbindable, rshared, rslave, rprivate, and runbindable.
     100//config:
     101//config:config FEATURE_MOUNT_FSTAB
     102//config:   depends on MOUNT
     103//config:   bool "Support /etc/fstab and -a"
     104//config:   default y
     105//config:   help
     106//config:     Support mount all and looking for files in /etc/fstab.
     107//config:
     108//config:config FEATURE_MOUNT_OTHERTAB
     109//config:   depends on FEATURE_MOUNT_FSTAB
     110//config:   bool "Support -T <alt_fstab>"
     111//config:   default y
     112//config:   help
     113//config:     Support mount -T (specifying an alternate fstab)
     114
    20115//usage:#define mount_trivial_usage
    21 //usage:       "[OPTIONS] [-o OPTS] DEVICE NODE"
     116//usage:       "[OPTIONS] [-o OPT] DEVICE NODE"
    22117//usage:#define mount_full_usage "\n\n"
    23118//usage:       "Mount a filesystem. Filesystem autodetection requires /proc.\n"
     
    42137////usage:   "\n    -s      Sloppy (ignored)"
    43138//usage:     "\n    -r      Read-only mount"
    44 //usage:     "\n    -w      Read-write mount (default)"
     139////usage:     "\n  -w      Read-write mount (default)"
    45140//usage:     "\n    -t FSTYPE[,...] Filesystem type(s)"
     141//usage:    IF_FEATURE_MOUNT_OTHERTAB(
     142//usage:     "\n    -T FILE     Read FILE instead of /etc/fstab"
     143//usage:    )
    46144//usage:     "\n    -O OPT      Mount only filesystems with option OPT (-a only)"
    47145//usage:     "\n-o OPT:"
     
    65163//usage:    )
    66164//usage:     "\n    remount     Remount a mounted filesystem, changing flags"
    67 //usage:     "\n    ro/rw       Same as -r/-w"
     165//usage:     "\n    ro      Same as -r"
    68166//usage:     "\n"
    69167//usage:     "\nThere are filesystem-specific -o flags."
     
    126224
    127225#include "libbb.h"
     226#include "common_bufsiz.h"
    128227#if ENABLE_FEATURE_MOUNT_LABEL
    129228# include "volume_id.h"
     
    162261// Not real flags, but we want to be able to check for this.
    163262enum {
    164     MOUNT_USERS  = (1 << 28) * ENABLE_DESKTOP,
     263    MOUNT_USERS  = (1 << 27) * ENABLE_DESKTOP,
     264    MOUNT_NOFAIL = (1 << 28) * ENABLE_DESKTOP,
    165265    MOUNT_NOAUTO = (1 << 29),
    166266    MOUNT_SWAP   = (1 << 30),
     267    MOUNT_FAKEFLAGS = MOUNT_USERS | MOUNT_NOFAIL | MOUNT_NOAUTO | MOUNT_SWAP
    167268};
    168269
    169270
    170 #define OPTION_STR "o:t:rwanfvsiO:"
     271#define OPTION_STR "o:t:rwanfvsiO:" IF_FEATURE_MOUNT_OTHERTAB("T:")
    171272enum {
    172273    OPT_o = (1 << 0),
     
    181282    OPT_i = (1 << 9),
    182283    OPT_O = (1 << 10),
     284    OPT_T = (1 << 11),
    183285};
    184286
     
    228330        IF_DESKTOP(/* "user"  */ MOUNT_USERS,)
    229331        IF_DESKTOP(/* "users" */ MOUNT_USERS,)
     332        IF_DESKTOP(/* "nofail" */ MOUNT_NOFAIL,)
    230333        /* "_netdev" */ 0,
    231334        IF_DESKTOP(/* "comment=" */ 0,) /* systemd uses this in fstab */
     
    275378};
    276379
    277 static const char mount_option_str[] =
     380static const char mount_option_str[] ALIGN1 =
    278381    IF_FEATURE_MOUNT_LOOP(
    279382        "loop\0"
     
    287390        IF_DESKTOP("user\0")
    288391        IF_DESKTOP("users\0")
     392        IF_DESKTOP("nofail\0")
    289393        "_netdev\0"
    290394        IF_DESKTOP("comment=\0") /* systemd uses this in fstab */
     
    345449} FIX_ALIASING;
    346450enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) };
    347 #define G (*(struct globals*)&bb_common_bufsiz1)
     451#define G (*(struct globals*)bb_common_bufsiz1)
    348452#define nfs_mount_version (G.nfs_mount_version)
    349453#if ENABLE_FEATURE_MOUNT_VERBOSE
     
    354458#define fslist            (G.fslist           )
    355459#define getmntent_buf     (G.getmntent_buf    )
    356 #define INIT_G() do { } while (0)
     460#define INIT_G() do { setup_common_bufsiz(); } while (0)
    357461
    358462#if ENABLE_FEATURE_MTAB_SUPPORT
     
    543647
    544648        while ((buf = xmalloc_fgetline(f)) != NULL) {
    545             if (strncmp(buf, "nodev", 5) == 0 && isspace(buf[5]))
     649            if (is_prefixed_with(buf, "nodev") && isspace(buf[5]))
    546650                goto next;
    547651            fs = skip_whitespace(buf);
     
    573677{
    574678    int rc = 0;
     679
     680    vfsflags &= ~(unsigned long)MOUNT_FAKEFLAGS;
    575681
    576682    if (FAKE_IT) {
     
    8981004#endif
    8991005/* Convert each NFSERR_BLAH into EBLAH */
    900 static const uint8_t nfs_err_stat[] = {
     1006static const uint8_t nfs_err_stat[] ALIGN1 = {
    9011007     1,  2,  5,  6, 13, 17,
    9021008    19, 20, 21, 22, 27, 28,
     
    9111017typedef uint16_t nfs_err_type;
    9121018#endif
    913 static const nfs_err_type nfs_err_errnum[] = {
     1019static const nfs_err_type nfs_err_errnum[] ALIGN2 = {
    9141020    EPERM , ENOENT      , EIO      , ENXIO , EACCES, EEXIST,
    9151021    ENODEV, ENOTDIR     , EISDIR   , EINVAL, EFBIG , ENOSPC,
     
    12661372                continue;
    12671373            case 18: // "proto"
    1268                 if (!strncmp(opteq, "tcp", 3))
     1374                if (is_prefixed_with(opteq, "tcp"))
    12691375                    tcp = 1;
    1270                 else if (!strncmp(opteq, "udp", 3))
     1376                else if (is_prefixed_with(opteq, "udp"))
    12711377                    tcp = 0;
    12721378                else
     
    13611467                "acl\0";
    13621468            int val = 1;
    1363             if (!strncmp(opt, "no", 2)) {
     1469            if (is_prefixed_with(opt, "no")) {
    13641470                val = 0;
    13651471                opt += 2;
     
    18571963                share + len + 1  /* "dir1/dir2" */
    18581964            );
    1859             parse_mount_options(unc, &filteropts);
    1860             if (ENABLE_FEATURE_CLEAN_UP) free(unc);
     1965            parse_mount_options(unc, &filteropts);
     1966            if (ENABLE_FEATURE_CLEAN_UP) free(unc);
    18611967        }
    18621968
     
    18811987
    18821988    // Might this be an NFS filesystem?
    1883     if ((!mp->mnt_type || strncmp(mp->mnt_type, "nfs", 3) == 0)
     1989    if ((!mp->mnt_type || is_prefixed_with(mp->mnt_type, "nfs"))
    18841990     && strchr(mp->mnt_fsname, ':') != NULL
    18851991    ) {
     
    19532059        if (ENABLE_FEATURE_CLEAN_UP) {
    19542060            free(loopFile);
    1955             free(mp->mnt_fsname);
     2061            /* No, "rc != 0" needs it: free(mp->mnt_fsname); */
    19562062        }
    19572063    }
     
    19622068
    19632069    if (errno == EBUSY && ignore_busy)
     2070        return 0;
     2071    if (errno == ENOENT && (vfsflags & MOUNT_NOFAIL))
    19642072        return 0;
    19652073    if (rc != 0)
     
    20352143    char *storage_path;
    20362144    llist_t *lst_o = NULL;
    2037     const char *fstabname;
     2145    const char *fstabname = "/etc/fstab";
    20382146    FILE *fstab;
    20392147    int i, j;
     
    20622170    opt_complementary = "?2o::" IF_FEATURE_MOUNT_VERBOSE("vv");
    20632171    opt = getopt32(argv, OPTION_STR, &lst_o, &fstype, &O_optmatch
     2172            IF_FEATURE_MOUNT_OTHERTAB(, &fstabname)
    20642173            IF_FEATURE_MOUNT_VERBOSE(, &verbose));
    20652174    while (lst_o) append_mount_options(&cmdopts, llist_pop(&lst_o)); // -o
     
    21292238    }
    21302239
     2240    // A malicious user could overmount /usr without this.
     2241    if (ENABLE_FEATURE_MOUNT_OTHERTAB && nonroot)
     2242        fstabname = "/etc/fstab";
    21312243    // Open either fstab or mtab
    2132     fstabname = "/etc/fstab";
    21332244    if (cmdopt_flags & MS_REMOUNT) {
    21342245        // WARNING. I am not sure this matches util-linux's
Note: See TracChangeset for help on using the changeset viewer.