Anything faster than stat(S)? need to determine File or Dir

Conor P. Cahill cpcahil at virtech.uucp
Sun Nov 12 02:43:12 AEST 1989


In article <17264 at rpp386.cactus.org>, jfh at rpp386.cactus.org (John F. Haugh II) writes:
> Just for the sake of disagreeing, what about other system calls that
> are able to distinguish between a file being a directory or not?
> 
> How about code like this -
> 
	[sample of using access() deleted]
> 
> We know all of the initial path exists because of the first access()
> call.  And with the second access() call we can discover if the
> last component of `path' isn't a directory since errno would be ENOTDIR
> rather than ENOENT.

So you want to replace a single call to stat() with multiple calls to 
access().  That doesn't make any sense since the major overhead to both
the stat and access system calls is that the path must be traversed and since
you are calling access twice, you have to traverse the path twice.

stat() is the most effecient mechanism that can be used to obtain information
about a file system entry since it just looks up an inode and copies
the data to the user's data area. If you are stating all entries in a
directory on a very heavily loaded system you could probably get some
performance gain by chdir()ing to the directory and then stating the
entities with just the basename (thereby not having to parse the path
every time).  This shouldn't have much of an effect on a lightly loaded
system due to caching.

-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list