Reading directories (was: Re: directory copying with cp; broken?)

forsyth at minster.york.ac.uk forsyth at minster.york.ac.uk
Fri Oct 21 03:51:58 AEST 1988


There is no trouble with using read() to replace getdirentries (or
whatever).  Inodes (or vnodes in some cults) have a type. The kernel
obviously knows when you are reading a directory, and can put whatever
information it likes into your buffer.  For instance, it could format
the information in the same way as getdirentries does now, if that
were a sensible format.  Each file system type's read implementation would
map its file system dependent structure into the portable one.  In
fact, the Newcastle Connection read() has been doing something similar for
years!

I once considered changing directory read() to return just the
list of file names, separated by newlines.  Then a simple ls X == cat X | sort.
The representation is convenient for programs, portable, and
completely hides file system dependent information.  (Think carefully about
pwd before rushing off to try this, though.)

Any good scheme should not have odd restrictions: ``nbytes must be greater than or equal
to the block size associated with the file...sizes less than this may cause errors on
certain filesystems'' [getdirentries(2)].



More information about the Comp.unix.wizards mailing list