[PATCH] Fix /etc/mtab updating with mount --move (was Re: [OT] util-linux 2.12p and a new maintainer)

From: Bill Rugolsky Jr.
Date: Thu Dec 23 2004 - 12:04:27 EST


On Thu, Dec 23, 2004 at 04:02:40AM +0100, Andries.Brouwer@xxxxxx wrote:
> Just released util-linux 2.12p.
> Find it the usual places, such as
> ftp://ftp.win.tue.nl/pub/linux-local/utils/util-linux
>
> I am happy to announce that Adrian Bunk is willing to
> take over maintenance of util-linux.

Andries & Adrian,

Back in February I had sent the patch at the following URL against
util-linux-2.12pre to util-linux@xxxxxxxxxxx, but it was never applied.
[Perhaps it was never received.]

http://groups-beta.google.com/group/linux.kernel/browse_frm/thread/2ab78ad70d79508c/de0cfbb377bc6a94?q=insubject:Fix+insubject:%2Fetc%2Fmtab+insubject:updating+insubject:with+insubject:mount

The executive summary is that the sequence

mkdir /tmp/a /tmp/b
mount -t ramfs none /tmp/a
mount --move /tmp/a /tmp/b

has the intended effect (according to /proc/mounts),
but corrupts /etc/mtab, which looks like:

none /tmp/a ramfs rw 0 0
/tmp/a /tmp/b none rw 0 0

i.e., as if we'd done --bind instead of --move.
The correct entry should be:

none /tmp/b ramfs rw 0 0

The bug is still in 2.12p; a rediffed patch is appended.
Sorry for not following up earlier.

Regards,

Bill Rugolsky


--- util-linux-2.12p/mount/fstab.c.mountmove 2004-12-21 14:09:24.000000000 -0500
+++ util-linux-2.12p/mount/fstab.c 2004-12-23 11:20:52.726564776 -0500
@@ -604,8 +604,12 @@
free(mc);
}
} else {
- /* A remount */
+ /* A remount or move */
mc->m.mnt_opts = instead->mnt_opts;
+ if (!streq(mc->m.mnt_dir, instead->mnt_dir)) {
+ free(mc->m.mnt_dir);
+ mc->m.mnt_dir = xstrdup(instead->mnt_dir);
+ }
}
} else if (instead) {
/* not found, add a new entry */
--- util-linux-2.12p/mount/mount.c.mountmove 2004-12-21 17:00:36.000000000 -0500
+++ util-linux-2.12p/mount/mount.c 2004-12-23 11:20:52.729564320 -0500
@@ -660,7 +660,9 @@
print_one (&mnt);

if (!nomtab && mtab_is_writable()) {
- if (flags & MS_REMOUNT)
+ if (flags & MS_MOVE)
+ update_mtab (mnt.mnt_fsname, &mnt);
+ else if (flags & MS_REMOUNT)
update_mtab (mnt.mnt_dir, &mnt);
else {
mntFILE *mfp;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/