BSD 4_3 release
[unix-history] / usr / man / man5 / dir.5
CommitLineData
49625d7c
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
3bd54658 4.\"
95f51977 5.\" @(#)dir.5 6.1 (Berkeley) 5/15/85
49625d7c 6.\"
95f51977 7.TH DIR 5 "May 15, 1985"
49625d7c 8.UC 5
3bd54658
KM
9.SH NAME
10dir \- format of directories
11.SH SYNOPSIS
12.B #include <sys/types.h>
13.br
14.B #include <sys/dir.h>
15.SH DESCRIPTION
49625d7c 16A directory behaves exactly like an ordinary file, save that no
3bd54658
KM
17user may write into a directory.
18The fact that a file is a directory is indicated by
49625d7c
KM
19a bit in the flag word of its i-node entry; see
20.IR fs (5).
21The structure of a directory entry as given in the include file is:
3bd54658 22.RS
49625d7c 23.ta 8n +10n +10n
3bd54658
KM
24.PP
25.nf
49625d7c
KM
26/*
27 * A directory consists of some number of blocks of DIRBLKSIZ
28 * bytes, where DIRBLKSIZ is chosen such that it can be transferred
29 * to disk in a single atomic operation (e.g. 512 bytes on most machines).
30 *
31 * Each DIRBLKSIZ byte block contains some number of directory entry
32 * structures, which are of variable length. Each directory entry has
33 * a struct direct at the front of it, containing its inode number,
34 * the length of the entry, and the length of the name contained in
35 * the entry. These are followed by the name padded to a 4 byte boundary
36 * with null bytes. All names are guaranteed null terminated.
37 * The maximum length of a name in a directory is MAXNAMLEN.
38 *
39 * The macro DIRSIZ(dp) gives the amount of space required to represent
40 * a directory entry. Free space in a directory is represented by
41 * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes
42 * in a directory block are claimed by the directory entries. This
43 * usually results in the last entry in a directory having a large
44 * dp->d_reclen. When entries are deleted from a directory, the
45 * space is returned to the previous entry in the same directory
46 * block by increasing its dp->d_reclen. If the first entry of
47 * a directory block is free, then its dp->d_ino is set to 0.
48 * Entries other than the first in a directory do not normally have
49 * dp->d_ino set to 0.
50 */
51#ifdef KERNEL
52#define DIRBLKSIZ DEV_BSIZE
53#else
54#define DIRBLKSIZ 512
3bd54658 55#endif
49625d7c
KM
56
57#define MAXNAMLEN 255
58
59/*
60 * The DIRSIZ macro gives the minimum record length which will hold
61 * the directory entry. This requires the amount of space in struct direct
62 * without the d_name field, plus enough space for the name with a terminating
63 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
64 */
65#undef DIRSIZ
66#define DIRSIZ(dp) \e
67 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
68
69struct direct {
70 u_long d_ino;
71 short d_reclen;
72 short d_namlen;
73 char d_name[MAXNAMLEN + 1];
74 /* typically shorter */
75};
76
77struct _dirdesc {
78 int dd_fd;
79 long dd_loc;
80 long dd_size;
81 char dd_buf[DIRBLKSIZ];
3bd54658
KM
82};
83.fi
84.RE
85.PP
86By convention, the first two entries in each directory
49625d7c
KM
87are for `.' and `..'. The first is an entry for the
88directory itself. The second is for the parent directory.
89The meaning of `..' is modified for the root directory
90of the master file system (\*(lq/\*(rq),
91where `..' has the same meaning as `.'.
3bd54658 92.SH "SEE ALSO"
49625d7c 93fs(5)