From owner-freebsd-fs@FreeBSD.ORG Mon May 31 16:54:28 2010 Return-Path: Delivered-To: freebsd-fs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 76FFD106564A for ; Mon, 31 May 2010 16:54:28 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id BF19E8FC15 for ; Mon, 31 May 2010 16:54:27 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id TAA05565 for ; Mon, 31 May 2010 19:54:25 +0300 (EEST) (envelope-from avg@icyb.net.ua) Message-ID: <4C03E9C0.2010602@icyb.net.ua> Date: Mon, 31 May 2010 19:54:24 +0300 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.24 (X11/20100517) MIME-Version: 1.0 To: freebsd-fs@FreeBSD.org X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Subject: nullfs distinct path check: take into account filesystems X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 May 2010 16:54:28 -0000 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 #include +#include #include #include @@ -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