Reading directories

Guy Harris guy at auspex.UUCP
Tue Oct 25 03:14:35 AEST 1988


>It is clear why directories should not be arbitrarily writable but I
>don't see any such reason why they shouldn't be readable.  The portable
>directory reading routines could use the existing read(2) system call,
>instead of adding (yet another) system call just to read directories.

It would probably have been possible, in principle, to have "read()" on
a directory not give you the raw data in the directory file, but give you
the directory entries in a "standard" format; over NFS, it would do a
NFS "readdir" call rather than a "read" call.

However, that wasn't what was done; I don't know the reason why not, but
one possibility I can think of is that they wanted SunOS 1.x binaries
to still be able to read directories on local files (so that your 1.x
binaries weren't immediately obsolete, and you or the vendor would have
time to recompile.  Thus, instead of modifying "read()" in that fashion,
they added "getdirentries".

You can probably make philosophical arguments either way, but they're
irrelevant because 1) either way works well enough, and neither one
works significantly better (as several people have pointed out, old
programs that "knew" what directory entries looked like would break if
they thought they looked like V7-style directories, so keeping "read()"
wouldn't have let them continue to work) and 2) Sun already introduced
"getdirentries", and AT&T added "getdents" in S5R3 (which Sun picked up
in SunOS 4.0), so the choice has already been made.

Adding "yet another" system call is hardly *ipso facto* a bad thing.



More information about the Comp.unix.wizards mailing list