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/util-linux/umount.c

    r1765 r2725  
    66 * Copyright (C) 2005 by Rob Landley <rob@landley.net>
    77 *
    8  * Licensed under GPL version 2, see file LICENSE in this tarball for details.
     8 * Licensed under GPLv2, see file LICENSE in this source tree.
    99 */
    10 
    1110#include <mntent.h>
    12 #include <getopt.h>
     11#include <sys/mount.h>
    1312#include "libbb.h"
    1413
    15 #define OPTION_STRING       "flDnravdt:"
    16 #define OPT_FORCE           1
    17 #define OPT_LAZY            2
    18 #define OPT_DONTFREELOOP    4
    19 #define OPT_NO_MTAB         8
    20 #define OPT_REMOUNT         16
    21 #define OPT_ALL             (ENABLE_FEATURE_UMOUNT_ALL ? 32 : 0)
     14#if defined(__dietlibc__)
     15// TODO: This does not belong here.
     16/* 16.12.2006, Sampo Kellomaki (sampo@iki.fi)
     17 * dietlibc-0.30 does not have implementation of getmntent_r() */
     18static struct mntent *getmntent_r(FILE* stream, struct mntent* result,
     19        char* buffer UNUSED_PARAM, int bufsize UNUSED_PARAM)
     20{
     21    struct mntent* ment = getmntent(stream);
     22    return memcpy(result, ment, sizeof(*ment));
     23}
     24#endif
    2225
    23 int umount_main(int argc, char **argv);
    24 int umount_main(int argc, char **argv)
     26/* ignored: -v -d -t -i */
     27#define OPTION_STRING           "fldnra" "vdt:i"
     28#define OPT_FORCE               (1 << 0) // Same as MNT_FORCE
     29#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)
     34
     35int umount_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     36int umount_main(int argc UNUSED_PARAM, char **argv)
    2537{
    2638    int doForce;
    27     char path[2*PATH_MAX];
    2839    struct mntent me;
    2940    FILE *fp;
    30     char *fstype = 0;
     41    char *fstype = NULL;
    3142    int status = EXIT_SUCCESS;
    3243    unsigned opt;
     
    3748    } *mtl, *m;
    3849
    39     /* Parse any options */
    40 
    4150    opt = getopt32(argv, OPTION_STRING, &fstype);
    42 
    43     argc -= optind;
     51    //argc -= optind;
    4452    argv += optind;
    4553
     54    // MNT_FORCE and MNT_DETACH (from linux/fs.h) must match
     55    // OPT_FORCE and OPT_LAZY, otherwise this trick won't work:
    4656    doForce = MAX((opt & OPT_FORCE), (opt & OPT_LAZY));
    4757
     
    5161     * entry.  Notice that this also naturally reverses the list so that -a
    5262     * umounts the most recent entries first. */
     63    m = mtl = NULL;
    5364
    54     m = mtl = 0;
    55 
    56     /* If we're umounting all, then m points to the start of the list and
    57      * the argument list should be empty (which will match all). */
    58 
     65    // If we're umounting all, then m points to the start of the list and
     66    // the argument list should be empty (which will match all).
    5967    fp = setmntent(bb_path_mtab_file, "r");
    6068    if (!fp) {
    6169        if (opt & OPT_ALL)
    62             bb_error_msg_and_die("cannot open %s", bb_path_mtab_file);
     70            bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file);
    6371    } else {
    64         while (getmntent_r(fp, &me, path, sizeof(path))) {
     72        while (getmntent_r(fp, &me, bb_common_bufsiz1, sizeof(bb_common_bufsiz1))) {
    6573            /* Match fstype if passed */
    66             if (fstype && match_fstype(&me, fstype))
     74            if (!match_fstype(&me, fstype))
    6775                continue;
    68             m = xmalloc(sizeof(struct mtab_list));
     76            m = xzalloc(sizeof(*m));
    6977            m->next = mtl;
    7078            m->device = xstrdup(me.mnt_fsname);
     
    7583    }
    7684
    77     /* If we're not umounting all, we need at least one argument. */
     85    // If we're not umounting all, we need at least one argument.
    7886    if (!(opt & OPT_ALL) && !fstype) {
    79         m = 0;
    80         if (!argc) bb_show_usage();
     87        if (!argv[0])
     88            bb_show_usage();
     89        m = NULL;
    8190    }
    8291
     
    8594        int curstat;
    8695        char *zapit = *argv;
     96        char *path;
    8797
    8898        // Do we already know what to umount this time through the loop?
    89         if (m) safe_strncpy(path, m->dir, PATH_MAX);
     99        if (m)
     100            path = xstrdup(m->dir);
    90101        // For umount -a, end of mtab means time to exit.
    91         else if (opt & OPT_ALL) break;
    92         // Get next command line argument (and look it up in mtab list)
    93         else if (!argc--) break;
     102        else if (opt & OPT_ALL)
     103            break;
     104        // Use command line argument (and look it up in mtab list)
    94105        else {
     106            if (!zapit)
     107                break;
    95108            argv++;
    96             realpath(zapit, path);
    97             for (m = mtl; m; m = m->next)
    98                 if (!strcmp(path, m->dir) || !strcmp(path, m->device))
    99                     break;
     109            path = xmalloc_realpath(zapit);
     110            if (path) {
     111                for (m = mtl; m; m = m->next)
     112                    if (strcmp(path, m->dir) == 0 || strcmp(path, m->device) == 0)
     113                        break;
     114            }
    100115        }
    101116        // If we couldn't find this sucker in /etc/mtab, punt by passing our
     
    108123
    109124        // Force the unmount, if necessary.
    110         if (curstat && doForce) {
     125        if (curstat && doForce)
    111126            curstat = umount2(zapit, doForce);
    112             if (curstat)
    113                 bb_error_msg("forced umount of %s failed!", zapit);
    114         }
    115127
    116128        // If still can't umount, maybe remount read-only?
    117         if (curstat && (opt & OPT_REMOUNT) && errno == EBUSY && m) {
    118             curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL);
    119             bb_error_msg(curstat ? "cannot remount %s read-only" :
    120                          "%s busy - remounted read-only", m->device);
    121         }
    122 
    123129        if (curstat) {
    124             status = EXIT_FAILURE;
    125             bb_perror_msg("cannot umount %s", zapit);
     130            if ((opt & OPT_REMOUNT) && errno == EBUSY && m) {
     131                // Note! Even if we succeed here, later we should not
     132                // free loop device or erase mtab entry!
     133                const char *msg = "%s busy - remounted read-only";
     134                curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL);
     135                if (curstat) {
     136                    msg = "can't remount %s read-only";
     137                    status = EXIT_FAILURE;
     138                }
     139                bb_error_msg(msg, m->device);
     140            } else {
     141                status = EXIT_FAILURE;
     142                bb_perror_msg("can't %sumount %s", (doForce ? "forcibly " : ""), zapit);
     143            }
    126144        } else {
    127             /* De-allocate the loop device.  This ioctl should be ignored on
    128              * any non-loop block devices. */
    129             if (ENABLE_FEATURE_MOUNT_LOOP && !(opt & OPT_DONTFREELOOP) && m)
     145            // De-allocate the loop device.  This ioctl should be ignored on
     146            // any non-loop block devices.
     147            if (ENABLE_FEATURE_MOUNT_LOOP && (opt & OPT_FREELOOP) && m)
    130148                del_loop(m->device);
    131149            if (ENABLE_FEATURE_MTAB_SUPPORT && !(opt & OPT_NO_MTAB) && m)
     
    136154        // Note this means that "umount /dev/blah" will unmount all instances
    137155        // of /dev/blah, not just the most recent.
    138         while (m && (m = m->next))
    139             if ((opt & OPT_ALL) || !strcmp(path, m->device))
    140                 break;
     156        if (m) {
     157            while ((m = m->next) != NULL)
     158                // NB: if m is non-NULL, path is non-NULL as well
     159                if ((opt & OPT_ALL) || strcmp(path, m->device) == 0)
     160                    break;
     161        }
     162        free(path);
    141163    }
    142164
    143165    // Free mtab list if necessary
    144 
    145166    if (ENABLE_FEATURE_CLEAN_UP) {
    146167        while (mtl) {
Note: See TracChangeset for help on using the changeset viewer.