Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 May 1998 10:00:01 -0700 (PDT)
From:      Ian Dowse <iedowse@maths.tcd.ie>
To:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: bin/6658: -stable getcwd(3) performs unnecessary lstats 
Message-ID:  <199805171700.KAA16811@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/6658; it has been noted by GNATS.

From: Ian Dowse <iedowse@maths.tcd.ie>
To: freebsd-gnats-submit@freebsd.org
Cc:  Subject: Re: bin/6658: -stable getcwd(3) performs unnecessary lstats 
Date: Sun, 17 May 1998 18:03:16 +0100

 In message <9805170338.aa14317@walton.maths.tcd.ie>, iedowse writes:
 >
 >! 
 >! 			if (!statfs(".", &sfs) &&
 
 Whoops... That of course will only work for the first mount point. The
 corrected patch is below.
 
 Ian
 
 
 *** /usr/src/lib/libc/gen/getcwd.c	Thu Mar 26 09:22:48 1998
 --- getcwd.c	Sun May 17 17:40:25 1998
 ***************
 *** 36,41 ****
 --- 36,42 ----
   #endif /* LIBC_SCCS and not lint */
   
   #include <sys/param.h>
 + #include <sys/mount.h>
   #include <sys/stat.h>
   
   #include <errno.h>
 ***************
 *** 169,175 ****
   				if (dp->d_fileno == ino)
   					break;
   			}
 ! 		} else
   			for (;;) {
   				if (!(dp = readdir(dir)))
   					goto notfound;
 --- 170,197 ----
   				if (dp->d_fileno == ino)
   					break;
   			}
 ! 		} else {
 ! 			struct statfs sfs;
 ! 			char *dirname;
 ! 
 ! 			/*
 ! 			 * Try to get the directory name by using statfs on
 ! 			 * the mount point. 
 ! 			 */
 ! 			if (!statfs(up[3] ? up + 3 : ".", &sfs) &&
 ! 			    (dirname = rindex(sfs.f_mntonname, '/'))) 
 ! 				while((dp = readdir(dir))) {
 ! 					if (ISDOT(dp))
 ! 						continue;
 ! 					bcopy(dp->d_name, bup, dp->d_namlen+1);
 ! 					if (!strcmp(dirname + 1, dp->d_name) &&
 ! 					    !lstat(up, &s) &&
 ! 					    s.st_dev == dev &&
 ! 					    s.st_ino == ino)
 ! 						goto found;
 ! 				}
 ! 			rewinddir(dir);
 ! 
   			for (;;) {
   				if (!(dp = readdir(dir)))
   					goto notfound;
 ***************
 *** 187,193 ****
 --- 209,217 ----
   				if (s.st_dev == dev && s.st_ino == ino)
   					break;
   			}
 + 		}
   
 + found:
   		/*
   		 * Check for length of the current name, preceding slash,
   		 * leading slash.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199805171700.KAA16811>