Date: Tue, 1 Jun 2010 22:06:58 +0300 From: Gleb Kurtsou <gleb.kurtsou@gmail.com> To: Andriy Gapon <avg@icyb.net.ua> Cc: freebsd-fs@FreeBSD.org Subject: Re: nullfs distinct path check: take into account filesystems Message-ID: <20100601190658.GA2594@tops.skynet.lt> In-Reply-To: <4C03E9C0.2010602@icyb.net.ua> References: <4C03E9C0.2010602@icyb.net.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On (31/05/2010 19:54), Andriy Gapon wrote: > > 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. Why don't we remove mount_nullfs entirely? Such check is trivial to do in kernel, all is needed is to change mntopts and add compatibility shims. Take a look at pefs_mount if interested: http://github.com/glk/pefs/blob/master/sys/fs/pefs/pefs_vfsops.c There is no mount_pefs and 'pefs mount' command exec's /sbin/mount, 'mount -t pefs' is supported as well; search for pefs_mount in: http://github.com/glk/pefs/blob/master/sbin/pefs/pefs_ctl.c Thanks, Gleb. > > 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"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100601190658.GA2594>