Updated docs/README-ATTACHMENTS, mainly to reflect that no setup is
[mmh] / docs / historical / mh-6.8.5 / miscellany / libndir / dir.h
1 /*      dir.h   4.4     82/07/25        */
2
3 /*
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.
27  */
28 #define DIRBLKSIZ       512
29 #define MAXNAMLEN       255
30
31 #ifdef pdp11
32 #define u_long long
33 #endif
34
35 struct  direct {
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 */
40 };
41
42 /*
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.
47  */
48 #undef DIRSIZ
49 #define DIRSIZ(dp) \
50     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
51
52 #ifndef KERNEL
53 /*
54  * Definitions for library routines operating on directories.
55  */
56 typedef struct _dirdesc {
57         int     dd_fd;
58         long    dd_loc;
59         long    dd_size;
60         char    dd_buf[DIRBLKSIZ];
61 } DIR;
62 #ifndef NULL
63 #define NULL 0
64 #endif
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();
71 #endif KERNEL