[PATCH] Update /etc/mtab when using `mount --move`.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 mount/mount.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/mount/mount.c b/mount/mount.c
index b4bb020..8e850b0 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -764,6 +764,25 @@ update_mtab_entry(const char *spec, const char *node, const char *type,
 		else {
 			mntFILE *mfp;
 
+			/* when moving a mount point, we have to make sure the mtab
+			 * gets updated properly.  We get info about the old mount
+			 * point, copy it to the new mount point, and then delete
+			 * the old mount point. */
+			if (flags & MS_MOVE) {
+				const char *olddir = mnt.mnt_fsname;
+				struct mntentchn *oldmc = oldmc = getmntfile(olddir);
+				if (oldmc != NULL) {
+					mnt.mnt_fsname = xstrdup(oldmc->m.mnt_fsname);
+					mnt.mnt_type = oldmc->m.mnt_type;
+					mnt.mnt_opts = oldmc->m.mnt_opts;
+					mnt.mnt_freq = oldmc->m.mnt_freq;
+					mnt.mnt_passno = oldmc->m.mnt_passno;
+				}
+				update_mtab(olddir, NULL);
+				if (oldmc != NULL)
+					my_free(olddir);
+			}
+
 			lock_mtab();
 			mfp = my_setmntent(MOUNTED, "a+");
 			if (mfp == NULL || mfp->mntent_fp == NULL) {
-- 
1.5.1

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux