]>
git.saurik.com Git - apple/xnu.git/blob - bsd/ufs/ufs/dir.h
9a86ec824b34fdc81111959b1e70bfa53054f5cf
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)dir.h 8.5 (Berkeley) 4/27/95
66 #include <sys/appleapiopts.h>
68 #ifdef __APPLE_API_UNSTABLE
70 * Theoretically, directories can be more than 2Gb in length, however, in
71 * practice this seems unlikely. So, we define the type doff_t as a 32-bit
72 * quantity to keep down the cost of doing lookup on a 32-bit machine.
74 #define doff_t int32_t
75 #define MAXDIRSIZE (0x7fffffff)
78 * A directory consists of some number of blocks of DIRBLKSIZ
79 * bytes, where DIRBLKSIZ is chosen such that it can be transferred
80 * to disk in a single atomic operation (e.g. 512 bytes on most machines).
82 * Each DIRBLKSIZ byte block contains some number of directory entry
83 * structures, which are of variable length. Each directory entry has
84 * a struct direct at the front of it, containing its inode number,
85 * the length of the entry, and the length of the name contained in
86 * the entry. These are followed by the name padded to a 4 byte boundary
87 * with null bytes. All names are guaranteed null terminated.
88 * The maximum length of a name in a directory is MAXNAMLEN.
90 * The macro DIRSIZ(fmt, dp) gives the amount of space required to represent
91 * a directory entry. Free space in a directory is represented by
92 * entries which have dp->d_reclen > DIRSIZ(fmt, dp). All DIRBLKSIZ bytes
93 * in a directory block are claimed by the directory entries. This
94 * usually results in the last entry in a directory having a large
95 * dp->d_reclen. When entries are deleted from a directory, the
96 * space is returned to the previous entry in the same directory
97 * block by increasing its dp->d_reclen. If the first entry of
98 * a directory block is free, then its dp->d_ino is set to 0.
99 * Entries other than the first in a directory do not normally have
100 * dp->d_ino set to 0.
103 #define DIRBLKSIZ 1024
105 #define DIRBLKSIZ DEV_BSIZE
107 #define MAXNAMLEN 255
110 u_int32_t d_ino
; /* inode number of entry */
111 u_int16_t d_reclen
; /* length of this record */
112 u_int8_t d_type
; /* file type, see below */
113 u_int8_t d_namlen
; /* length of string in d_name */
114 char d_name
[MAXNAMLEN
+ 1];/* name with length <= MAXNAMLEN */
131 * Convert between stat structure types and directory types.
133 #define IFTODT(mode) (((mode) & 0170000) >> 12)
134 #define DTTOIF(dirtype) ((dirtype) << 12)
137 * The DIRSIZ macro gives the minimum record length which will hold
138 * the directory entry. This requires the amount of space in struct direct
139 * without the d_name field, plus enough space for the name with a terminating
140 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
142 #if (BYTE_ORDER == LITTLE_ENDIAN)
143 #define DIRSIZ(oldfmt, dp) \
145 ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
146 ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
148 #define DIRSIZ(oldfmt, dp) \
149 ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
155 * Template for manipulating directories. Should use struct direct's,
156 * but the name field is MAXNAMLEN - 1, and this just won't do.
163 char dot_name
[4]; /* must be multiple of 4 */
164 u_int32_t dotdot_ino
;
165 int16_t dotdot_reclen
;
166 u_int8_t dotdot_type
;
167 u_int8_t dotdot_namlen
;
168 char dotdot_name
[4]; /* ditto */
172 * This is the old format of directories, sanz type element.
174 struct odirtemplate
{
177 u_int16_t dot_namlen
;
178 char dot_name
[4]; /* must be multiple of 4 */
179 u_int32_t dotdot_ino
;
180 int16_t dotdot_reclen
;
181 u_int16_t dotdot_namlen
;
182 char dotdot_name
[4]; /* ditto */
184 #endif /* __APPLE_API_UNSTABLE */
185 #endif /* !_DIR_H_ */