]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
eject: add --no-partitions-unmount
authorKarel Zak <kzak@redhat.com>
Wed, 13 Jun 2012 11:46:24 +0000 (13:46 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 13 Jun 2012 11:46:24 +0000 (13:46 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/eject.1
sys-utils/eject.c

index 5d7cfa0a95db508f4c731455d658eb40b7abce87..1a232293baa0fabfc6bcac4d4fa7ca8cd6b31301 100644 (file)
@@ -59,10 +59,12 @@ This option allow you to use /proc/mounts instead /etc/mtab. It also passes the
 This option specifies that the drive should be ejected using a tape drive
 offline command.
 .IP "\fB\-m, \-\-no-unmount\fP"
-This option allows eject to work with device drivers which automatically mount
-removable media and therefore must be always mount(1)ed.  The option tells eject
-to not try to unmount the given device, even if it is mounted according to
-/etc/mtab or /proc/mounts.
+The option tells eject to not try to unmount at all.
+.IP "\fB\-M, \-\-no-partitions-unmount\fP"
+The option tells eject to not try to unmount another partitions on partitioned
+devices. If another partition is mounted the program will not attempt to eject
+the media. It will attempt to unmount only mountpoint or mounted device given
+on eject command line.
 .IP "\fB\-n, \-\-noop\fP"
 With this option the selected device is displayed but no action is performed.
 .IP "\fB\-t, \-\-trayclose\fP"
@@ -124,8 +126,9 @@ will follow the link and use the device that it points to.
 If
 .B eject
 determines that the device can have multiple partitions, it will attempt to
-unmount all mounted partitions of the device before ejecting.  If an unmount
-fails, the program will not attempt to eject the media.
+unmount all mounted partitions of the device before ejecting (see
+--no-partitions-unmount). If an unmount fails, the program will not attempt to
+eject the media.
 .PP
 You can eject an audio CD.  Some CD-ROM drives will refuse to open the tray if
 the drive is empty.  Some devices do not support the tray close command.
index 4f3fb831f8f086f0f3e1a94388f97602c789f551..240e27e74bd225b2615887794502d5e9bd9570b6 100644 (file)
@@ -90,6 +90,7 @@ static int v_option;
 static int x_option;
 static int p_option;
 static int m_option;
+static int M_option;
 static int i_option;
 static int a_arg;
 static int i_arg;
@@ -134,23 +135,24 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
                _(" %s [options] [<device>|<mountpoint>]\n"), program_invocation_short_name);
 
        fputs(USAGE_OPTIONS, out);
-       fputs(_(" -a, --auto <on|off>        turn auto-eject feature on or off\n"
-               " -c, --changerslot <slot>   switch discs on a CD-ROM changer\n"
-               " -d, --default              display default device\n"
-               " -f, --floppy               eject floppy\n"
-               " -F, --force                don't care about device type\n"
-               " -i, --manualeject <on|off> toggle manual eject protection on/off\n"
-               " -m, --no-unmount           do not unmount device even if it is mounted\n"
-               " -n, --noop                 don't eject, just show device found\n"
-               " -p, --proc                 use /proc/mounts instead of /etc/mtab\n"
-               " -q, --tape                 eject tape\n"
-               " -r, --cdrom                eject CD-ROM\n"
-               " -s, --scsi                 eject SCSI device\n"
-               " -t, --trayclose            close tray\n"
-               " -T, --traytoggle           toggle tray\n"
-               " -v, --verbose              enable verbose output\n"
-               " -x, --cdspeed <speed>      set CD-ROM max speed\n"
-               " -X, --listspeed            list CD-ROM available speeds\n"),
+       fputs(_(" -a, --auto <on|off>         turn auto-eject feature on or off\n"
+               " -c, --changerslot <slot>    switch discs on a CD-ROM changer\n"
+               " -d, --default               display default device\n"
+               " -f, --floppy                eject floppy\n"
+               " -F, --force                 don't care about device type\n"
+               " -i, --manualeject <on|off>  toggle manual eject protection on/off\n"
+               " -m, --no-unmount            do not unmount device even if it is mounted\n"
+               " -M, --no-partitions-unmount do not unmount another partitions\n"
+               " -n, --noop                  don't eject, just show device found\n"
+               " -p, --proc                  use /proc/mounts instead of /etc/mtab\n"
+               " -q, --tape                  eject tape\n"
+               " -r, --cdrom                 eject CD-ROM\n"
+               " -s, --scsi                  eject SCSI device\n"
+               " -t, --trayclose             close tray\n"
+               " -T, --traytoggle            toggle tray\n"
+               " -v, --verbose               enable verbose output\n"
+               " -x, --cdspeed <speed>       set CD-ROM max speed\n"
+               " -X, --listspeed             list CD-ROM available speeds\n"),
                out);
 
        fputs(USAGE_SEPARATOR, out);
@@ -181,6 +183,7 @@ static void parse_args(int argc, char **argv, char **device)
                {"manualeject", required_argument, NULL, 'i'},
                {"noop",        no_argument,       NULL, 'n'},
                {"no-unmount",  no_argument,       NULL, 'm'},
+               {"no-partitions-unmount", no_argument, NULL, 'M' },
                {"proc",        no_argument,       NULL, 'p'},
                {"scsi",        no_argument,       NULL, 's'},
                {"tape",        no_argument,       NULL, 'q'},
@@ -193,7 +196,7 @@ static void parse_args(int argc, char **argv, char **device)
        int c;
 
        while ((c = getopt_long(argc, argv,
-                               "a:c:i:x:dfFhnqrstTXvVpm", long_opts, NULL)) != -1) {
+                               "a:c:i:x:dfFhnqrstTXvVpmM", long_opts, NULL)) != -1) {
                switch (c) {
                case 'a':
                        a_option = 1;
@@ -236,6 +239,9 @@ static void parse_args(int argc, char **argv, char **device)
                case 'm':
                        m_option = 1;
                        break;
+               case 'M':
+                       M_option = 1;
+                       break;
                case 'n':
                        n_option = 1;
                        break;
@@ -743,16 +749,17 @@ static char *get_disk_devname(const char *device)
        return st.st_rdev == diskno ? NULL : find_device(diskname);
 }
 
-static void umount_partitions(const char *disk)
+static int umount_partitions(const char *disk, int checkonly)
 {
        struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY;
        dev_t devno;
        DIR *dir = NULL;
        struct dirent *d;
+       int count = 0;
 
        devno = sysfs_devname_to_devno(disk, NULL);
        if (sysfs_init(&cxt, devno, NULL) != 0)
-               return;
+               return 0;
 
        /* open /sys/block/<wholedisk> */
        if (!(dir = sysfs_opendir(&cxt, NULL)))
@@ -768,8 +775,12 @@ static void umount_partitions(const char *disk)
                        char *dev = find_device(d->d_name);
 
                        if (dev && device_get_mountpoint(&dev, &mnt) == 0) {
-                               verbose(_("%s: mounted at %s"), dev, mnt);
-                               umount_one(mnt);
+                               verbose(_("%s: mounted on %s"), dev, mnt);
+                               if (checkonly)
+                                       warnx(_("warning: %s: mounted on %s"), dev, mnt);
+                               else
+                                       umount_one(mnt);
+                               count++;
                        }
                        free(dev);
                }
@@ -779,6 +790,8 @@ done:
        if (dir)
                closedir(dir);
        sysfs_deinit(&cxt);
+
+       return count;
 }
 
 static int is_hotpluggable_subsystem(const char *name)
@@ -1035,9 +1048,14 @@ int main(int argc, char **argv)
        /* if it is a multipartition device, unmount any other partitions on
           the device */
        if (m_option != 1) {
+               int rc;
+
                if (mountpoint)
                        umount_one(mountpoint);         /* usually whole-disk */
-               umount_partitions(device);
+
+               rc = umount_partitions(device, M_option);
+               if (M_option && rc)
+                       errx(EXIT_FAILURE, _("error: %s: device in use"), device);
        }
 
        /* handle -c option */