Subject: misc/504: find(1) chokes on fdesc file system
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: John Kohl <jtk@kolvir.blrc.ma.us>
List: netbsd-bugs
Date: 10/01/1994 15:35:03
>Number:         504
>Category:       misc
>Synopsis:       find(1) chokes on fdesc file system
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct  1 15:35:02 1994
>Originator:     John Kohl
>Organization:
>Release:        1.0_BETA
>Environment:
System: NetBSD kolvir 1.0_BETA NetBSD 1.0_BETA (KOLVIR) #25: Thu Sep 29 23:31:17 EDT 1994 jtk@kolvir:/u1/NetBSD-1.0/src/sys/arch/i386/compile/KOLVIR i386


>Description:
find(1), as called from /usr/libexec/locate.updatedb, doesn't properly
prune its descents into the fdesc file system if said filesystem is
union mounted.


>How-To-Repeat:
1) mount /dev/fd with an fstab line like so:
	fdesc /dev fdesc rw,union 1 2
2) run find like so, and watch it choke:
# find /dev \( \! -fstype local -o -fstype fdesc -o -fstype kernfs \) -a -prune -o -print
/dev
/dev/fd
/dev/fd/0
/dev/fd/1
/dev/fd/2
/dev/fd/3
/dev/fd/4
find: 5: Bad file descriptor
Exit 1

>Fix:

The problem is that find doesn't record all the state needed when
crossing a mountpoint.  Here's a patch:

*** 1.1	1994/10/01 21:02:18
--- usr.bin/find/function.c	1994/10/01 21:03:55
***************
*** 381,389 ****
  		first = 0;
  		switch (plan->flags) {
  		case F_MTFLAG:
- 			val = sb.f_flags;
- 			break;
  		case F_MTTYPE:
  			strncpy(fstype, sb.f_fstypename, MFSNAMELEN);
  			fstype[MFSNAMELEN] = '\0';
  			break;
--- 381,392 ----
  		first = 0;
  		switch (plan->flags) {
  		case F_MTFLAG:
  		case F_MTTYPE:
+ 			/* copy both flags & type, so that if future
+ 			 * tests look at this same device crossing,
+ 			 * they'll have valid data for comparison
+ 			 */
+ 			val = sb.f_flags;
  			strncpy(fstype, sb.f_fstypename, MFSNAMELEN);
  			fstype[MFSNAMELEN] = '\0';
  			break;



>Audit-Trail:
>Unformatted: