]> err.no Git - util-linux/commitdiff
umount: check for overlaid mounts
authorGuan Xin <guanx.bac@gmail.com>
Mon, 29 Sep 2008 09:38:06 +0000 (11:38 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 29 Sep 2008 09:38:06 +0000 (11:38 +0200)
Linux cannot umount a device whose mount point is hidden by subsequent
mount(s). i.e. We must umount the devices associated to a mount point
in the reverse order of when they were mounted.  If umount was called
violating this rule, report error and exit.

Signed-off-by: Guan Xin <guanx.bac@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
mount/umount.c

index b2bbdae3c6be93f5e2a224d7bfaf48e9feeda4c7..b571a300b7bedf81cc82157a4a143c762e1674ad 100644 (file)
@@ -474,8 +474,27 @@ umount_file (char *arg) {
                printf(_("Trying to umount %s\n"), file);
 
        mc = getmntdirbackward(file, NULL);
-       if (!mc)
+       if (!mc) {
                mc = getmntdevbackward(file, NULL);
+               if (mc) {
+                       struct mntentchn *mc1;
+
+                       mc1 = getmntdirbackward(mc->m.mnt_dir, NULL);
+                       if (!mc1)
+                               /* 'mc1' must exist, though not necessarily
+                                   equals to `mc'. Otherwise we go mad. */
+                               die(EX_SOFTWARE,
+                                   _("umount: confused when analyzing mtab"));
+
+                       if (strcmp(file, mc1->m.mnt_fsname)) {
+                               /* Something was stacked over `file' on the
+                                  same mount point. */
+                               die(EX_FAIL, _("umount: cannot umount %s -- %s is "
+                                   "mounted over it on the same point."),
+                                   file, mc1->m.mnt_fsname);
+                       }
+               }
+       }
        if (!mc && verbose)
                printf(_("Could not find %s in mtab\n"), file);