From 992283e8e49d941069973832e166eacb8ea6cf6c Mon Sep 17 00:00:00 2001 From: Guan Xin Date: Mon, 29 Sep 2008 11:38:06 +0200 Subject: [PATCH] umount: check for overlaid mounts 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 Signed-off-by: Karel Zak --- mount/umount.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mount/umount.c b/mount/umount.c index b2bbdae3..b571a300 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -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); -- 2.39.5