Changeset 904 in MondoRescue for trunk/mindi-busybox/util-linux/umount.c


Ignore:
Timestamp:
Oct 25, 2006, 1:51:57 AM (18 years ago)
Author:
Bruno Cornec
Message:

merge -r890:902 $SVN_M/branches/stable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mindi-busybox/util-linux/umount.c

    r821 r904  
    1515#include <mntent.h>
    1616#include <errno.h>
    17 #include <string.h>
    1817#include <getopt.h>
    1918
    20 #define OPTION_STRING       "flDnrvad"
     19#define OPTION_STRING       "flDnravd"
    2120#define OPT_FORCE           1
    2221#define OPT_LAZY            2
     
    2423#define OPT_NO_MTAB         8
    2524#define OPT_REMOUNT         16
    26 #define OPT_IGNORED         32  // -v is ignored
    27 #define OPT_ALL             (ENABLE_FEATURE_UMOUNT_ALL ? 64 : 0)
     25#define OPT_ALL             (ENABLE_FEATURE_UMOUNT_ALL ? 32 : 0)
    2826
    2927int umount_main(int argc, char **argv)
     
    7876        if (!argc) bb_show_usage();
    7977    }
    80 
    81 
    8278   
    8379    // Loop through everything we're supposed to umount, and do so.
    8480    for (;;) {
    8581        int curstat;
     82        char *zapit = *argv;
    8683
    8784        // Do we already know what to umount this time through the loop?
     
    9289        else if (!argc--) break;
    9390        else {
    94             realpath(*argv++, path);
     91            argv++;
     92            realpath(zapit, path);
    9593            for (m = mtl; m; m = m->next)
    9694                if (!strcmp(path, m->dir) || !strcmp(path, m->device))
    9795                    break;
    9896        }
     97        // If we couldn't find this sucker in /etc/mtab, punt by passing our
     98        // command line argument straight to the umount syscall.  Otherwise,
     99        // umount the directory even if we were given the block device.
     100        if (m) zapit = m->dir;
    99101
    100102        // Let's ask the thing nicely to unmount.
    101         curstat = umount(path);
     103        curstat = umount(zapit);
    102104
    103105        // Force the unmount, if necessary.
    104106        if (curstat && doForce) {
    105             curstat = umount2(path, doForce);
     107            curstat = umount2(zapit, doForce);
    106108            if (curstat)
    107                 bb_error_msg_and_die("forced umount of %s failed!", path);
     109                bb_error_msg_and_die("forced umount of %s failed!", zapit);
    108110        }
    109111
    110112        // If still can't umount, maybe remount read-only?
    111113        if (curstat && (opt & OPT_REMOUNT) && errno == EBUSY && m) {
    112             curstat = mount(m->device, path, NULL, MS_REMOUNT|MS_RDONLY, NULL);
     114            curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL);
    113115            bb_error_msg(curstat ? "Cannot remount %s read-only" :
    114116                         "%s busy - remounted read-only", m->device);
    115117        }
    116118
    117         /* De-allocate the loop device.  This ioctl should be ignored on any
    118          * non-loop block devices. */
    119         if (ENABLE_FEATURE_MOUNT_LOOP && !(opt & OPT_DONTFREELOOP) && m)
    120             del_loop(m->device);
     119        if (curstat) {
     120            status = EXIT_FAILURE;
     121            bb_perror_msg("Couldn't umount %s", zapit);
     122        } else {
     123            /* De-allocate the loop device.  This ioctl should be ignored on
     124             * any non-loop block devices. */
     125            if (ENABLE_FEATURE_MOUNT_LOOP && !(opt & OPT_DONTFREELOOP) && m)
     126                del_loop(m->device);
     127            if (ENABLE_FEATURE_MTAB_SUPPORT && !(opt & OPT_NO_MTAB) && m)
     128                erase_mtab(m->dir);
     129        }
    121130
    122         if (curstat) {
    123             /* Yes, the ENABLE is redundant here, but the optimizer for ARM
    124              * can't do simple constant propagation in local variables... */
    125             if(ENABLE_FEATURE_MTAB_SUPPORT && !(opt & OPT_NO_MTAB) && m)
    126                 erase_mtab(m->dir);
    127             status = EXIT_FAILURE;
    128             bb_perror_msg("Couldn't umount %s", path);
    129         }
    130131        // Find next matching mtab entry for -a or umount /dev
     132        // Note this means that "umount /dev/blah" will unmount all instances
     133        // of /dev/blah, not just the most recent.
    131134        while (m && (m = m->next))
    132135            if ((opt & OPT_ALL) || !strcmp(path,m->device))
Note: See TracChangeset for help on using the changeset viewer.