1DIR(5)                        File Formats Manual                       DIR(5)
2
3
4

NAME

6       dir - format of directories
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/dir.h>
11

DESCRIPTION

13       A  directory  behaves  exactly like an ordinary file, save that no user
14       may write into a directory.  The fact that a file  is  a  directory  is
15       indicated  by  a  bit  in the flag word of its i-node entry; see fs(5).
16       The structure of a directory entry as given in the include file is:
17
18              /*
19               * A directory consists of some number of blocks of DIRBLKSIZ
20               * bytes, where DIRBLKSIZ is chosen such that it can be transferred
21               * to disk in a single atomic operation (e.g. 512 bytes on most machines).
22               *
23               * Each DIRBLKSIZ byte block contains some number of directory entry
24               * structures, which are of variable length.  Each directory entry has
25               * a struct direct at the front of it, containing its inode number,
26               * the length of the entry, and the length of the name contained in
27               * the entry.  These are followed by the name padded to a 4 byte boundary
28               * with null bytes.  All names are guaranteed null terminated.
29               * The maximum length of a name in a directory is MAXNAMLEN.
30               *
31               * The macro DIRSIZ(dp) gives the amount of space required to represent
32               * a directory entry.  Free space in a directory is represented by
33               * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
34               * in a directory block are claimed by the directory entries.  This
35               * usually results in the last entry in a directory having a large
36               * dp->d_reclen.  When entries are deleted from a directory, the
37               * space is returned to the previous entry in the same directory
38               * block by increasing its dp->d_reclen.  If the first entry of
39               * a directory block is free, then its dp->d_ino is set to 0.
40               * Entries other than the first in a directory do not normally have
41               * dp->d_ino set to 0.
42               */
43
44              #define DIRBLKSIZ 512
45
46              #define MAXNAMLEN 63
47
48              /*
49               * The DIRSIZ macro gives the minimum record length which will hold
50               * the directory entry.  This requires the amount of space in struct direct
51               * without the d_name field, plus enough space for the name with a terminating
52               * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
53               */
54              #undef DIRSIZ
55              #define DIRSIZ(dp) \
56                  ((((sizeof (struct direct) - (MAXNAMLEN+1)) + (dp)->d_namlen+1) + 3) &~ 3)
57
58              struct  direct {
59                      ino_t     d_ino;
60                      short     d_reclen;
61                      short     d_namlen;
62                      char      d_name[MAXNAMLEN + 1];
63                      /* typically shorter */
64              };
65
66              struct _dirdesc {
67                      int       dd_fd;
68                      long      dd_loc;
69                      long      dd_size;
70                      char      dd_buf[DIRBLKSIZ];
71              };
72
73       By convention, the first two entries in each directory are for `.'  and
74       `..'.   The  first is an entry for the directory itself.  The second is
75       for the parent directory.  The meaning of `..' is modified for the root
76       directory  of  the  master  file  system (“/”), where `..' has the same
77       meaning as `.'.
78

SEE ALSO

80       fs(5)
81

BUGS

83       The 63 character MAXNAMLEN value is shorter  than  the  255  characters
84       allowed  by 4BSD.  This could lead to file name portability problems in
85       unusual circumstances.
86
87       The disk format of directories is only slightly different from the 4BSD
88       directory  format, the inode number is of type ino_t rather than u_long
89       to reduce the amount of 32 bit arithmetic in the kernel.
90
91
92
934.2 Berkeley Distribution        May 15, 1985                           DIR(5)
Impressum