1 /* dir.h 4.4 82/07/25 */
4 * A directory consists of some number of blocks of DIRBLKSIZ
5 * bytes, where DIRBLKSIZ is chosen such that it can be transferred
6 * to disk in a single atomic operation (e.g. 512 bytes on most machines).
8 * Each DIRBLKSIZ byte block contains some number of directory entry
9 * structures, which are of variable length. Each directory entry has
10 * a struct direct at the front of it, containing its inode number,
11 * the length of the entry, and the length of the name contained in
12 * the entry. These are followed by the name padded to a 4 byte boundary
13 * with null bytes. All names are guaranteed null terminated.
14 * The maximum length of a name in a directory is MAXNAMLEN.
16 * The macro DIRSIZ(dp) gives the amount of space required to represent
17 * a directory entry. Free space in a directory is represented by
18 * entries which have dp->d_reclen >= DIRSIZ(dp). All DIRBLKSIZ bytes
19 * in a directory block are claimed by the directory entries. This
20 * usually results in the last entry in a directory having a large
21 * dp->d_reclen. When entries are deleted from a directory, the
22 * space is returned to the previous entry in the same directory
23 * block by increasing its dp->d_reclen. If the first entry of
24 * a directory block is free, then its dp->d_ino is set to 0.
25 * Entries other than the first in a directory do not normally have
36 u_long d_ino; /* inode number of entry */
37 u_short d_reclen; /* length of this record */
38 u_short d_namlen; /* length of string in d_name */
39 char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */
43 * The DIRSIZ macro gives the minimum record length which will hold
44 * the directory entry. This requires the amount of space in struct direct
45 * without the d_name field, plus enough space for the name with a terminating
46 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
50 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
54 * Definitions for library routines operating on directories.
56 typedef struct _dirdesc {
60 char dd_buf[DIRBLKSIZ];
65 extern DIR *opendir();
66 extern struct direct *readdir();
67 extern long telldir();
68 extern void seekdir();
69 #define rewinddir(dirp) seekdir((dirp), (long)0)
70 extern void closedir();