help with dir. structure sysV vs. 4.2BSD

Guy Harris guy at sun.uucp
Sat Aug 17 19:48:09 AEST 1985


> In K&P's book "The Unix Programming Enviroment"
> a spelling correction algorithym is presented to
> use with such things as paginators. (see spname 
> in the index.) It is written for sysV/4.1 directory
> structures. I am having trouble converting it to 4.2
> 
> It uses a low level read (shown below; it is in
> mindist() ) to look at the directory. I believe this 
> is the line which gives me trouble.

Using low level reads to look at the directory is the wrong thing to do on
any 4.2BSD system; it's also not the best thing to do on the V7 file system,
either.  If you use the "directory library", either in its V7 file system
form or its 4.2 file system form, you can move your code between systems
using the two different file systems without change.

See DIRECTORY(3) for a writeup on this library.  The library was originally
written for 4.1aBSD, which used the V7 file system, and programs were
converted to use it; later, a 4.2BSD version was written.  The V7 file
system version was posted to net.sources by Kirk McKusick a long time ago,
and is available in the distributions of several bits of software like
"sendmail" and the RTI/4.2BSD UUCP.  Another V7 file system version was
posted by Doug Gwyn more recently.

Everybody out there offering a UNIX with a V7 file system (this means you,
AT&T) should provide the directory library with their system, and rewrite
their programs to use it.  It's easy, it's fun, and it fixes at least two
known bugs in S5 utilities, since "readdir" always null-terminates the file
name, while the filename isn't necessarily terminated in the raw directory
structure (this causes "ls -C" to screw up its pagination if it encounters a
14-character file name, and I believe it also screwed up "make" or the
shell).

	Guy Harris



More information about the Comp.unix.wizards mailing list