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

List:       freebsd-fs
Subject:    nullfs distinct path check: take into account filesystems
From:       Andriy Gapon <avg () icyb ! net ! ua>
Date:       2010-05-31 16:54:24
Message-ID: 4C03E9C0.2010602 () icyb ! net ! ua
[Download RAW message or body]


Right now mount_nullfs doesn't allow to, for example, mount / in /tmp/somedir even
if /tmp is a different filesystem.
I think there is no reason to do that and thus propose the following patch.

diff --git a/sbin/mount_nullfs/mount_nullfs.c b/sbin/mount_nullfs/mount_nullfs.c
index abca9fa..4bd426f 100644
--- a/sbin/mount_nullfs/mount_nullfs.c
+++ b/sbin/mount_nullfs/mount_nullfs.c
@@ -46,6 +46,7 @@ static const char rcsid[] =

 #include <sys/param.h>
 #include <sys/mount.h>
+#include <sys/stat.h>
 #include <sys/uio.h>

 #include <err.h>
@@ -62,7 +63,8 @@ struct mntopt mopts[] = {
 	MOPT_END
 };

-int	subdir(const char *, const char *);
+static int	samefs(const char *p1, const char *p2);
+static int	subdir(const char *, const char *);
 static void	usage(void) __dead2;

 int
@@ -93,7 +95,8 @@ main(int argc, char *argv[])
 	(void)checkpath(argv[0], target);
 	(void)checkpath(argv[1], source);

-	if (subdir(target, source) || subdir(source, target))
+	if (samefs(target, source)
+	    && (subdir(target, source) || subdir(source, target)))
 		errx(EX_USAGE, "%s (%s) and %s are not distinct paths",
 		    argv[0], target, argv[1]);

@@ -116,6 +119,21 @@ main(int argc, char *argv[])
 }

 int
+samefs(const char *p1, const char *p2)
+{
+	struct stat sb;
+	uint32_t fsid1;
+	uint32_t fsid2;
+
+	stat(p1, &sb);
+	fsid1 = sb.st_dev;
+	stat(p2, &sb);
+	fsid2 = sb.st_dev;
+
+	return (fsid1 == fsid2);
+}
+
+int
 subdir(const char *p, const char *dir)
 {
 	int l;

-- 
Andriy Gapon
_______________________________________________
freebsd-fs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-fs
To unsubscribe, send any mail to "freebsd-fs-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread] 

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