From nobody@FreeBSD.org  Thu Apr  7 20:47:50 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 11A4F1065674
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  7 Apr 2011 20:47:50 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id DD3AE8FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  7 Apr 2011 20:47:49 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p37KlnJC053409
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 7 Apr 2011 20:47:49 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p37Klnwx053408;
	Thu, 7 Apr 2011 20:47:49 GMT
	(envelope-from nobody)
Message-Id: <201104072047.p37Klnwx053408@red.freebsd.org>
Date: Thu, 7 Apr 2011 20:47:49 GMT
From: Marcin Wisnicki <mwisnicki+freebsd@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: find(1) does not detect nullfs
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         156258
>Category:       bin
>Synopsis:       [patch] find(1) does not detect nullfs
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 07 20:50:11 UTC 2011
>Closed-Date:    Wed Jul 20 07:49:23 UTC 2011
>Last-Modified:  Wed Jul 20 07:49:23 UTC 2011
>Originator:     Marcin Wisnicki
>Release:        8.2-STABLE
>Organization:
>Environment:
>Description:
find(1) utility does not correctly detect nullfs filesystems with -fstype option.

Nullfs copies statfs.f_type from lower fs, f_fstypename however is set to nullfs.
>How-To-Repeat:
% mkdir /jails
% mount -t nullfs /tmp /jails

% find /jails -maxdepth 0 -fstype nullfs
% gfind /jails -maxdepth 0 -fstype nullfs
/jails
>Fix:
Compare fstypename. This is how gnu find and find on other *BSDs work.
Patch adopted from NetBSD (from 1994 ;) is below.

Also I have added XXX comment to val_flags assignment, this is not related to the fix but it did catch my attention.
I don't understand why gcc emits no warning when assigning uint64 field to int variable. I've tried WARNS=6 -Wall -pedantic -Wconversion but it didn't help. Can someone explain this to me ?

Patch attached with submission follows:

diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 26c022c..cc75aaf 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -846,7 +846,8 @@ f_fstype(PLAN *plan, FTSENT *entry)
 	static dev_t curdev;	/* need a guaranteed illegal dev value */
 	static int first = 1;
 	struct statfs sb;
-	static int val_type, val_flags;
+	static int val_flags;
+	static char fstype[sizeof(sb.f_fstypename)];
 	char *p, save[2] = {0,0};
 
 	if ((plan->flags & F_MTMASK) == F_MTUNKNOWN)
@@ -887,14 +888,15 @@ f_fstype(PLAN *plan, FTSENT *entry)
 		 * Further tests may need both of these values, so
 		 * always copy both of them.
 		 */
+		/* XXX integer truncation ? */
 		val_flags = sb.f_flags;
-		val_type = sb.f_type;
+		strlcpy(fstype, sb.f_fstypename, sizeof(fstype));
 	}
 	switch (plan->flags & F_MTMASK) {
 	case F_MTFLAG:
 		return val_flags & plan->mt_data;
 	case F_MTTYPE:
-		return val_type == plan->mt_data;
+		return (strncmp(fstype, plan->c_data, sizeof(fstype)) == 0);
 	default:
 		abort();
 	}
@@ -905,22 +907,12 @@ c_fstype(OPTION *option, char ***argvp)
 {
 	char *fsname;
 	PLAN *new;
-	struct xvfsconf vfc;
 
 	fsname = nextarg(option, argvp);
 	ftsoptions &= ~FTS_NOSTAT;
 
 	new = palloc(option);
 
-	/*
-	 * Check first for a filesystem name.
-	 */
-	if (getvfsbyname(fsname, &vfc) == 0) {
-		new->flags |= F_MTTYPE;
-		new->mt_data = vfc.vfc_typenum;
-		return new;
-	}
-
 	switch (*fsname) {
 	case 'l':
 		if (!strcmp(fsname, "local")) {
@@ -938,12 +930,8 @@ c_fstype(OPTION *option, char ***argvp)
 		break;
 	}
 
-	/*
-	 * We need to make filesystem checks for filesystems
-	 * that exists but aren't in the kernel work.
-	 */
-	fprintf(stderr, "Warning: Unknown filesystem type %s\n", fsname);
-	new->flags |= F_MTUNKNOWN;
+	new->flags |= F_MTTYPE;
+	new->c_data = fsname;
 	return new;
 }
 


>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/156258: commit references a PR
Date: Mon, 13 Jun 2011 05:22:21 +0000 (UTC)

 Author: avatar
 Date: Mon Jun 13 05:22:07 2011
 New Revision: 223035
 URL: http://svn.freebsd.org/changeset/base/223035
 
 Log:
   Using statfs.f_fstypename rather than statfs.f_type whilst performing fstype
   comparsion as nullfs will copy f_type from underlayer FS.
   
   PR:		bin/156258
   Submitted by:	Marcin Wisnicki <mwisnicki+freebsd@gmail.com>
   MFC after:	1 month
 
 Modified:
   head/usr.bin/find/function.c
 
 Modified: head/usr.bin/find/function.c
 ==============================================================================
 --- head/usr.bin/find/function.c	Mon Jun 13 04:55:29 2011	(r223034)
 +++ head/usr.bin/find/function.c	Mon Jun 13 05:22:07 2011	(r223035)
 @@ -846,7 +846,8 @@ f_fstype(PLAN *plan, FTSENT *entry)
  	static dev_t curdev;	/* need a guaranteed illegal dev value */
  	static int first = 1;
  	struct statfs sb;
 -	static int val_type, val_flags;
 +	static int val_flags;
 +	static char fstype[sizeof(sb.f_fstypename)];
  	char *p, save[2] = {0,0};
  
  	if ((plan->flags & F_MTMASK) == F_MTUNKNOWN)
 @@ -888,13 +889,13 @@ f_fstype(PLAN *plan, FTSENT *entry)
  		 * always copy both of them.
  		 */
  		val_flags = sb.f_flags;
 -		val_type = sb.f_type;
 +		strlcpy(fstype, sb.f_fstypename, sizeof(fstype));
  	}
  	switch (plan->flags & F_MTMASK) {
  	case F_MTFLAG:
  		return val_flags & plan->mt_data;
  	case F_MTTYPE:
 -		return val_type == plan->mt_data;
 +		return (strncmp(fstype, plan->c_data, sizeof(fstype)) == 0);
  	default:
  		abort();
  	}
 @@ -905,22 +906,11 @@ c_fstype(OPTION *option, char ***argvp)
  {
  	char *fsname;
  	PLAN *new;
 -	struct xvfsconf vfc;
  
  	fsname = nextarg(option, argvp);
  	ftsoptions &= ~FTS_NOSTAT;
  
  	new = palloc(option);
 -
 -	/*
 -	 * Check first for a filesystem name.
 -	 */
 -	if (getvfsbyname(fsname, &vfc) == 0) {
 -		new->flags |= F_MTTYPE;
 -		new->mt_data = vfc.vfc_typenum;
 -		return new;
 -	}
 -
  	switch (*fsname) {
  	case 'l':
  		if (!strcmp(fsname, "local")) {
 @@ -938,12 +928,8 @@ c_fstype(OPTION *option, char ***argvp)
  		break;
  	}
  
 -	/*
 -	 * We need to make filesystem checks for filesystems
 -	 * that exists but aren't in the kernel work.
 -	 */
 -	fprintf(stderr, "Warning: Unknown filesystem type %s\n", fsname);
 -	new->flags |= F_MTUNKNOWN;
 +	new->flags |= F_MTTYPE;
 +	new->c_data = fsname;
  	return new;
  }
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/156258: commit references a PR
Date: Mon, 18 Jul 2011 04:54:24 +0000 (UTC)

 Author: avatar
 Date: Mon Jul 18 04:54:12 2011
 New Revision: 224173
 URL: http://svn.freebsd.org/changeset/base/224173
 
 Log:
   MFC r223035: Using statfs.f_fstypename rather than statfs.f_type whilst
   performing fstype comparsion as nullfs will copy f_type from underlayer FS.
   
   PR:		bin/156258
   Submitted by:	Marcin Wisnicki <mwisnicki+freebsd@gmail.com>
 
 Modified:
   stable/8/usr.bin/find/function.c
 Directory Properties:
   stable/8/usr.bin/find/   (props changed)
 
 Modified: stable/8/usr.bin/find/function.c
 ==============================================================================
 --- stable/8/usr.bin/find/function.c	Mon Jul 18 03:40:49 2011	(r224172)
 +++ stable/8/usr.bin/find/function.c	Mon Jul 18 04:54:12 2011	(r224173)
 @@ -851,7 +851,8 @@ f_fstype(PLAN *plan, FTSENT *entry)
  	static dev_t curdev;	/* need a guaranteed illegal dev value */
  	static int first = 1;
  	struct statfs sb;
 -	static int val_type, val_flags;
 +	static int val_flags;
 +	static char fstype[sizeof(sb.f_fstypename)];
  	char *p, save[2] = {0,0};
  
  	if ((plan->flags & F_MTMASK) == F_MTUNKNOWN)
 @@ -893,13 +894,13 @@ f_fstype(PLAN *plan, FTSENT *entry)
  		 * always copy both of them.
  		 */
  		val_flags = sb.f_flags;
 -		val_type = sb.f_type;
 +		strlcpy(fstype, sb.f_fstypename, sizeof(fstype));
  	}
  	switch (plan->flags & F_MTMASK) {
  	case F_MTFLAG:
  		return val_flags & plan->mt_data;
  	case F_MTTYPE:
 -		return val_type == plan->mt_data;
 +		return (strncmp(fstype, plan->c_data, sizeof(fstype)) == 0);
  	default:
  		abort();
  	}
 @@ -910,22 +911,11 @@ c_fstype(OPTION *option, char ***argvp)
  {
  	char *fsname;
  	PLAN *new;
 -	struct xvfsconf vfc;
  
  	fsname = nextarg(option, argvp);
  	ftsoptions &= ~FTS_NOSTAT;
  
  	new = palloc(option);
 -
 -	/*
 -	 * Check first for a filesystem name.
 -	 */
 -	if (getvfsbyname(fsname, &vfc) == 0) {
 -		new->flags |= F_MTTYPE;
 -		new->mt_data = vfc.vfc_typenum;
 -		return new;
 -	}
 -
  	switch (*fsname) {
  	case 'l':
  		if (!strcmp(fsname, "local")) {
 @@ -943,12 +933,8 @@ c_fstype(OPTION *option, char ***argvp)
  		break;
  	}
  
 -	/*
 -	 * We need to make filesystem checks for filesystems
 -	 * that exists but aren't in the kernel work.
 -	 */
 -	fprintf(stderr, "Warning: Unknown filesystem type %s\n", fsname);
 -	new->flags |= F_MTUNKNOWN;
 +	new->flags |= F_MTTYPE;
 +	new->c_data = fsname;
  	return new;
  }
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/156258: commit references a PR
Date: Tue, 19 Jul 2011 03:30:52 +0000 (UTC)

 Author: avatar
 Date: Tue Jul 19 03:30:42 2011
 New Revision: 224208
 URL: http://svn.freebsd.org/changeset/base/224208
 
 Log:
   MFC r223035: Using statfs.f_fstypename rather than statfs.f_type whilst
   performing fstype comparsion as nullfs will copy f_type from underlayer FS.
   
   PR:		bin/156258
   Submitted by:	Marcin Wisnicki <mwisnicki+freebsd@gmail.com>
 
 Modified:
   stable/7/usr.bin/find/function.c
 Directory Properties:
   stable/7/usr.bin/find/   (props changed)
 
 Modified: stable/7/usr.bin/find/function.c
 ==============================================================================
 --- stable/7/usr.bin/find/function.c	Tue Jul 19 00:37:24 2011	(r224207)
 +++ stable/7/usr.bin/find/function.c	Tue Jul 19 03:30:42 2011	(r224208)
 @@ -841,7 +841,8 @@ f_fstype(PLAN *plan, FTSENT *entry)
  	static dev_t curdev;	/* need a guaranteed illegal dev value */
  	static int first = 1;
  	struct statfs sb;
 -	static int val_type, val_flags;
 +	static int val_flags;
 +	static char fstype[sizeof(sb.f_fstypename)];
  	char *p, save[2] = {0,0};
  
  	if ((plan->flags & F_MTMASK) == F_MTUNKNOWN)
 @@ -883,13 +884,13 @@ f_fstype(PLAN *plan, FTSENT *entry)
  		 * always copy both of them.
  		 */
  		val_flags = sb.f_flags;
 -		val_type = sb.f_type;
 +		strlcpy(fstype, sb.f_fstypename, sizeof(fstype));
  	}
  	switch (plan->flags & F_MTMASK) {
  	case F_MTFLAG:
  		return val_flags & plan->mt_data;
  	case F_MTTYPE:
 -		return val_type == plan->mt_data;
 +		return (strncmp(fstype, plan->c_data, sizeof(fstype)) == 0);
  	default:
  		abort();
  	}
 @@ -900,22 +901,11 @@ c_fstype(OPTION *option, char ***argvp)
  {
  	char *fsname;
  	PLAN *new;
 -	struct xvfsconf vfc;
  
  	fsname = nextarg(option, argvp);
  	ftsoptions &= ~FTS_NOSTAT;
  
  	new = palloc(option);
 -
 -	/*
 -	 * Check first for a filesystem name.
 -	 */
 -	if (getvfsbyname(fsname, &vfc) == 0) {
 -		new->flags |= F_MTTYPE;
 -		new->mt_data = vfc.vfc_typenum;
 -		return new;
 -	}
 -
  	switch (*fsname) {
  	case 'l':
  		if (!strcmp(fsname, "local")) {
 @@ -933,12 +923,8 @@ c_fstype(OPTION *option, char ***argvp)
  		break;
  	}
  
 -	/*
 -	 * We need to make filesystem checks for filesystems
 -	 * that exists but aren't in the kernel work.
 -	 */
 -	fprintf(stderr, "Warning: Unknown filesystem type %s\n", fsname);
 -	new->flags |= F_MTUNKNOWN;
 +	new->flags |= F_MTTYPE;
 +	new->c_data = fsname;
  	return new;
  }
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: avatar 
State-Changed-When: Wed Jul 20 07:48:21 UTC 2011 
State-Changed-Why:  
Patch committed to -CURRENT and 7/8 stable as well.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=156258 
>Unformatted:
