Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwvax!zazen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!nic.csu.net!csun!kithrup!sef From: sef@kithrup.COM (Sean Eric Fagan) Newsgroups: comp.unix.programmer Subject: Re: How is the UNIX directory set up? Message-ID: <1991Feb09.105903.17744@kithrup.COM> Date: 9 Feb 91 10:59:03 GMT References: <2265@njitgw.njit.edu> Distribution: usa Organization: Kithrup Enterprises, Ltd. Lines: 43 In article <2265@njitgw.njit.edu> gaines@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 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@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.