[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] Have mount strip symlinks for path in mtab
From:       Ian Wienand <ianw () vmware ! com>
Date:       2008-10-29 17:39:36
Message-ID: 20081029173936.GA30051 () coopers ! eng ! vmware ! com
[Download RAW message or body]

Hi,

We noticed that when you mount a device through a symlink, the symlink
name stays in the mtab entry.

This means umount doesn't remove it (as it looks up the real path) and
also varies from Linux.

e.g. the semantics on Linux

/tmp$ ls -l
drwxr-xr-x 3 root root 1024 2008-10-29 10:21 foo
lrwxrwxrwx 1 root root    3 2008-10-29 10:25 link-to-foo -> foo

/tmp$ sudo mount /dev/ram0 link-to-foo

/tmp$ mount
/dev/ram0 on /tmp/foo type ext2 (rw)
[note, not /tmp/link-to-foo]

Thanks,

-i

Index: util-linux/mount.c
===================================================================
--- util-linux/mount.c	(revision 23853)
+++ util-linux/mount.c	(working copy)
@@ -456,6 +456,7 @@
 		FILE *mountTable = setmntent(bb_path_mtab_file, "a+");
 		const char *option_str = mount_option_str;
 		int i;
+		char *real_path = xmalloc(PATH_MAX);
 
 		if (!mountTable) {
 			bb_error_msg("no %s", bb_path_mtab_file);
@@ -478,6 +479,17 @@
 		// Convert to canonical pathnames as needed
 
 		mp->mnt_dir = bb_simplify_path(mp->mnt_dir);
+
+		// Strip out symlinks and swizzle result into mnt_dir
+		real_path = realpath(mp->mnt_dir, realpath);
+		if (real_path == NULL) {
+			bb_error_msg_and_die("Can not resolve real path for mtab");
+		}
+		if (ENABLE_FEATURE_CLEAN_UP) {
+			free(mp->mnt_dir);
+		}
+		mp->mnt_dir = real_path;
+
 		fsname = 0;
 		if (!mp->mnt_type || !*mp->mnt_type) { /* bind mount */
 			mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname);

_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic