|
|
1.1 root 1: /*
2: * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: *
33: * @(#)dir.h 7.10 (Berkeley) 3/25/91
34: */
35:
36: #ifndef _DIR_H_
37: #define _DIR_H_
38:
39: /*
40: * A directory consists of some number of blocks of DIRBLKSIZ
41: * bytes, where DIRBLKSIZ is chosen such that it can be transferred
42: * to disk in a single atomic operation (e.g. 512 bytes on most machines).
43: *
44: * Each DIRBLKSIZ byte block contains some number of directory entry
45: * structures, which are of variable length. Each directory entry has
46: * a struct direct at the front of it, containing its inode number,
47: * the length of the entry, and the length of the name contained in
48: * the entry. These are followed by the name padded to a 4 byte boundary
49: * with null bytes. All names are guaranteed null terminated.
50: * The maximum length of a name in a directory is MAXNAMLEN.
51: *
52: * The macro DIRSIZ(dp) gives the amount of space required to represent
53: * a directory entry. Free space in a directory is represented by
54: * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes
55: * in a directory block are claimed by the directory entries. This
56: * usually results in the last entry in a directory having a large
57: * dp->d_reclen. When entries are deleted from a directory, the
58: * space is returned to the previous entry in the same directory
59: * block by increasing its dp->d_reclen. If the first entry of
60: * a directory block is free, then its dp->d_ino is set to 0.
61: * Entries other than the first in a directory do not normally have
62: * dp->d_ino set to 0.
63: */
64: #define DIRBLKSIZ DEV_BSIZE
65: #define MAXNAMLEN 255
66:
67: struct direct {
68: u_long d_ino; /* inode number of entry */
69: u_short d_reclen; /* length of this record */
70: u_short d_namlen; /* length of string in d_name */
71: char d_name[MAXNAMLEN + 1]; /* name with length <= MAXNAMLEN */
72: };
73:
74: /*
75: * The DIRSIZ macro gives the minimum record length which will hold
76: * the directory entry. This requires the amount of space in struct direct
77: * without the d_name field, plus enough space for the name with a terminating
78: * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
79: */
80: #define DIRSIZ(dp) \
81: ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
82:
83: /*
84: * Template for manipulating directories.
85: * Should use struct direct's, but the name field
86: * is MAXNAMLEN - 1, and this just won't do.
87: */
88: struct dirtemplate {
89: u_long dot_ino;
90: short dot_reclen;
91: short dot_namlen;
92: char dot_name[4]; /* must be multiple of 4 */
93: u_long dotdot_ino;
94: short dotdot_reclen;
95: short dotdot_namlen;
96: char dotdot_name[4]; /* ditto */
97: };
98: #endif /* !_DIR_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.