Date: Mon, 31 May 2010 19:54:24 +0300 From: Andriy Gapon <avg@icyb.net.ua> To: freebsd-fs@FreeBSD.org Subject: nullfs distinct path check: take into account filesystems Message-ID: <4C03E9C0.2010602@icyb.net.ua>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C03E9C0.2010602>
