summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mount/fstab.c18
-rw-r--r--mount/fstab.h1
-rw-r--r--mount/mount.c5
3 files changed, 22 insertions, 2 deletions
diff --git a/mount/fstab.c b/mount/fstab.c
index 97d64a2c8..bfb2e5d35 100644
--- a/mount/fstab.c
+++ b/mount/fstab.c
@@ -216,6 +216,24 @@ getmntfile (const char *name) {
}
/*
+ * Given the name NAME, and the place MCPREV we found it last time,
+ * try to find it in mtab.
+ */
+struct mntentchn *
+getmntfilebackward (const char *name, struct mntentchn *mcprev) {
+ struct mntentchn *mc, *mc0;
+
+ mc0 = mtab_head();
+ if (!mcprev)
+ mcprev = mc0;
+ for (mc = mcprev->prev; mc && mc != mc0; mc = mc->prev)
+ if (streq(mc->m.mnt_dir, name) ||
+ streq(mc->m.mnt_fsname, name))
+ return mc;
+ return NULL;
+}
+
+/*
* Given the directory name NAME, and the place MCPREV we found it last time,
* try to find more occurrences.
*/
diff --git a/mount/fstab.h b/mount/fstab.h
index 38f7bab93..e98550646 100644
--- a/mount/fstab.h
+++ b/mount/fstab.h
@@ -15,6 +15,7 @@ struct mntentchn {
struct mntentchn *mtab_head (void);
struct mntentchn *getmntfile (const char *name);
+struct mntentchn *getmntfilebackward (const char *name, struct mntentchn *mcprev);
struct mntentchn *getmntoptfile (const char *file);
struct mntentchn *getmntdirbackward (const char *dir, struct mntentchn *mc);
struct mntentchn *getmntdevbackward (const char *dev, struct mntentchn *mc);
diff --git a/mount/mount.c b/mount/mount.c
index 433941e1d..2e819e95b 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -2140,10 +2140,11 @@ getfs(const char *spec, const char *uuid, const char *label)
/*
* D) remount -- try /etc/mtab
* Earlier mtab was tried first, but this would sometimes try the
- * wrong mount in case mtab had the root device entry wrong.
+ * wrong mount in case mtab had the root device entry wrong. Try
+ * the last occurrence first, since that is the visible mount.
*/
if (!mc && (devname || spec))
- mc = getmntfile (devname ? devname : spec);
+ mc = getmntfilebackward (devname ? devname : spec, NULL);
my_free(devname);
return mc;