|
|
1.1 root 1: /*
2: <sys/_dir.h> -- definitions for 4.2,4.3BSD directories
3:
4: last edit: 25-Apr-1987 D A Gwyn
5:
6: A directory consists of some number of blocks of DIRBLKSIZ bytes each,
7: where DIRBLKSIZ is chosen such that it can be transferred to disk in a
8: single atomic operation (e.g., 512 bytes on most machines).
9:
10: Each DIRBLKSIZ-byte block contains some number of directory entry
11: structures, which are of variable length. Each directory entry has the
12: beginning of a (struct direct) at the front of it, containing its
13: filesystem-unique ident number, the length of the entry, and the length
14: of the name contained in the entry. These are followed by the NUL-
15: terminated name padded to a (long) boundary with 0 bytes. The maximum
16: length of a name in a directory is MAXNAMELEN.
17:
18: The macro DIRSIZ(dp) gives the amount of space required to represent a
19: directory entry. Free space in a directory is represented by entries
20: that have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes in a
21: directory block are claimed by the directory entries; this usually
22: results in the last entry in a directory having a large dp->d_reclen.
23: When entries are deleted from a directory, the space is returned to the
24: previous entry in the same directory block by increasing its
25: dp->d_reclen. If the first entry of a directory block is free, then
26: its dp->d_fileno is set to 0; entries other than the first in a
27: directory do not normally have dp->d_fileno set to 0.
28:
29: prerequisite: <sys/types.h>
30: */
31:
32: #if defined(accel) || defined(sun) || defined(vax)
33: #define DIRBLKSIZ 512 /* size of directory block */
34: #else
35: #ifdef alliant
36: #define DIRBLKSIZ 4096 /* size of directory block */
37: #else
38: #ifdef gould
39: #define DIRBLKSIZ 1024 /* size of directory block */
40: #else
41: #ifdef ns32000 /* Dynix System V */
42: #define DIRBLKSIZ 2600 /* size of directory block */
43: #else /* be conservative; multiple blocks are okay but fractions are not */
44: #define DIRBLKSIZ 4096 /* size of directory block */
45: #endif
46: #endif
47: #endif
48: #endif
49:
50: #define MAXNAMELEN 255 /* maximum filename length */
51: /* NOTE: not MAXNAMLEN, which has been preempted by SVR3 <dirent.h> */
52:
53: struct direct /* data from read()/_getdirentries() */
54: {
55: unsigned long d_fileno; /* unique ident of entry */
56: unsigned short d_reclen; /* length of this record */
57: unsigned short d_namlen; /* length of string in d_name */
58: char d_name[MAXNAMELEN+1]; /* NUL-terminated filename */
59: /* typically shorter */
60: };
61:
62: /*
63: The DIRSIZ macro gives the minimum record length which will hold the
64: directory entry. This requires the amount of space in a (struct
65: direct) without the d_name field, plus enough space for the name with a
66: terminating NUL character, rounded up to a (long) boundary.
67:
68: (Note that Berkeley didn't properly compensate for struct padding,
69: but we nevertheless have to use the same size as the actual system.)
70: */
71:
72: #define DIRSIZ( dp ) ((sizeof(struct direct) - (MAXNAMELEN+1) \
73: + sizeof(long) + (dp)->d_namlen) \
74: / sizeof(long) * sizeof(long))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.