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