Commit | Line | Data |
---|---|---|
b11be056 | 1 | /* dir.h 6.1 83/07/29 */ |
ad30fb67 KM |
2 | |
3 | /* | |
58765c2f BJ |
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). | |
7 | * | |
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. | |
15 | * | |
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 | |
26 | * dp->d_ino set to 0. | |
ad30fb67 | 27 | */ |
af0b24db SL |
28 | /* so user programs can just include dir.h */ |
29 | #if !defined(KERNEL) && !defined(DEV_BSIZE) | |
30 | #define DEV_BSIZE 512 | |
31 | #endif | |
58765c2f BJ |
32 | #define DIRBLKSIZ DEV_BSIZE |
33 | #define MAXNAMLEN 255 | |
ad30fb67 KM |
34 | |
35 | struct direct { | |
58765c2f BJ |
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 */ | |
ad30fb67 KM |
40 | }; |
41 | ||
42 | /* | |
58765c2f BJ |
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. | |
ad30fb67 KM |
47 | */ |
48 | #undef DIRSIZ | |
49 | #define DIRSIZ(dp) \ | |
58765c2f | 50 | ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) |
ad30fb67 | 51 | |
58765c2f | 52 | #ifndef KERNEL |
ad30fb67 | 53 | /* |
58765c2f | 54 | * Definitions for library routines operating on directories. |
ad30fb67 | 55 | */ |
58765c2f BJ |
56 | typedef struct _dirdesc { |
57 | int dd_fd; | |
58 | long dd_loc; | |
59 | long dd_size; | |
60 | char dd_buf[DIRBLKSIZ]; | |
61 | } DIR; | |
af0b24db SL |
62 | #ifndef NULL |
63 | #define NULL 0 | |
64 | #endif | |
58765c2f BJ |
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(); | |
af0b24db SL |
71 | #endif |
72 | ||
73 | #ifdef KERNEL | |
74 | /* | |
75 | * Template for manipulating directories. | |
76 | * Should use struct direct's, but the name field | |
77 | * is MAXNAMLEN - 1, and this just won't do. | |
78 | */ | |
79 | struct dirtemplate { | |
80 | u_long dot_ino; | |
81 | short dot_reclen; | |
82 | short dot_namlen; | |
83 | char dot_name[4]; /* must be multiple of 4 */ | |
84 | u_long dotdot_ino; | |
85 | short dotdot_reclen; | |
86 | short dotdot_namlen; | |
87 | char dotdot_name[4]; /* ditto */ | |
88 | }; | |
89 | #endif |