From 531019d5c358bead52adb2cfce0eb92544d722de Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 11 Apr 2011 14:05:57 +0200 Subject: [PATCH] umount: support non-canonical devnames in mtab Addresses: https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/755193 Signed-off-by: Karel Zak --- mount/fstab.c | 13 +++++++++++++ mount/umount.c | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mount/fstab.c b/mount/fstab.c index 32b8dac181..fd53ca4beb 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -307,10 +307,23 @@ getmntdevbackward (const char *name, struct mntentchn *mcprev) { mc0 = mtab_head(); if (!mcprev) mcprev = mc0; + + /* canonical names in mtab */ for (mc = mcprev->prev; mc && mc != mc0; mc = mc->prev) { if (streq(mc->m.mnt_fsname, name)) return mc; } + + /* non-canonical names in mtab (this is BAD THING!) */ + for (mc = mcprev->prev; mc && mc != mc0; mc = mc->prev) { + char *cn = canonicalize(mc->m.mnt_fsname); + int res = cn ? streq(cn, name) : 0; + + free(cn); + if (res) + return mc; + } + return NULL; } diff --git a/mount/umount.c b/mount/umount.c index 2e7bd31cef..add6c87daa 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -634,6 +634,7 @@ umount_file (char *arg) { mc = getmntdevbackward(file, NULL); if (mc) { struct mntentchn *mc1; + char *cn; mc1 = getmntdirbackward(mc->m.mnt_dir, NULL); if (!mc1) @@ -642,13 +643,15 @@ umount_file (char *arg) { die(EX_SOFTWARE, _("umount: confused when analyzing mtab")); - if (strcmp(file, mc1->m.mnt_fsname)) { + cn = canonicalize(mc1->m.mnt_fsname); + if (cn && strcmp(file, cn)) { /* Something was stacked over `file' on the same mount point. */ die(EX_FAIL, _("umount: cannot unmount %s -- %s is " "mounted over it on the same point"), file, mc1->m.mnt_fsname); } + free(cn); } } if (!mc && verbose) -- 2.47.2