How is the UNIX directory set up?
Sean Eric Fagan
sef at kithrup.COM
Sat Feb 9 21:59:03 AEST 1991
In article <2265 at njitgw.njit.edu> gaines at mars.njit.edu (Starman) writes:
>Hi,
> I'm working on reading in the directory from the . file. I've
>broken up the structire so far as follows:
Use opendir(), readdir() and closedir(). If they are not available on your
system, several pd or liberated versions exist in various places.
>Bytes 0-3 : file number
>Bytes 4-5 : File type
>Bytes 6-7 : filename length
Bzzt.
I know of three unix directory formats, two of which are:
Version 7:
2 bytes -- inode number
14 bytes -- file name, padded out with nuls
BSD 4.2 and later:
4 bytes -- inode number
2 bytes -- directory entry length
2 btyes -- name length
<x> bytes -- name and possible 0 padding
Note that the byte counts are... well, they will probably be that size on
all machines. The actual types for the BSD one are u_long, u_short,
u_short, and char. BSD 4.3 and earlier do not allow filenames with 8-bit
characters (i.e., *real* ascii only), in addition to the other limits.
Whenever possible, try not to know the format of directories; it will only
cause problems. In addition, if you have it, I also recommend the use of
pathconf() and fpathconf(); these can be used to, among other things, find
out the maximum filename length on the given (valid) path. See POSIX
1003.1...
--
Sean Eric Fagan | "I made the universe, but please don't blame me for it;
sef at kithrup.COM | I had a bellyache at the time."
-----------------+ -- The Turtle (Stephen King, _It_)
Any opinions expressed are my own, and generally unpopular with others.
More information about the Comp.unix.programmer
mailing list