]>
git.saurik.com Git - apple/xnu.git/blob - bsd/ufs/ufs/dir.h
2b8527ddc10c48cffc11ea144ca4bc1bb7c4a459
2 * Copyright (c) 2000 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
67 * Theoretically, directories can be more than 2Gb in length, however, in
68 * practice this seems unlikely. So, we define the type doff_t as a 32-bit
69 * quantity to keep down the cost of doing lookup on a 32-bit machine.
71 #define doff_t int32_t
72 #define MAXDIRSIZE (0x7fffffff)
75 * A directory consists of some number of blocks of DIRBLKSIZ
76 * bytes, where DIRBLKSIZ is chosen such that it can be transferred
77 * to disk in a single atomic operation (e.g. 512 bytes on most machines).
79 * Each DIRBLKSIZ byte block contains some number of directory entry
80 * structures, which are of variable length. Each directory entry has
81 * a struct direct at the front of it, containing its inode number,
82 * the length of the entry, and the length of the name contained in
83 * the entry. These are followed by the name padded to a 4 byte boundary
84 * with null bytes. All names are guaranteed null terminated.
85 * The maximum length of a name in a directory is MAXNAMLEN.
87 * The macro DIRSIZ(fmt, dp) gives the amount of space required to represent
88 * a directory entry. Free space in a directory is represented by
89 * entries which have dp->d_reclen > DIRSIZ(fmt, dp). All DIRBLKSIZ bytes
90 * in a directory block are claimed by the directory entries. This
91 * usually results in the last entry in a directory having a large
92 * dp->d_reclen. When entries are deleted from a directory, the
93 * space is returned to the previous entry in the same directory
94 * block by increasing its dp->d_reclen. If the first entry of
95 * a directory block is free, then its dp->d_ino is set to 0.
96 * Entries other than the first in a directory do not normally have
100 #define DIRBLKSIZ 1024
102 #define DIRBLKSIZ DEV_BSIZE
104 #define MAXNAMLEN 255
107 u_int32_t d_ino
; /* inode number of entry */
108 u_int16_t d_reclen
; /* length of this record */
109 u_int8_t d_type
; /* file type, see below */
110 u_int8_t d_namlen
; /* length of string in d_name */
111 char d_name
[MAXNAMLEN
+ 1];/* name with length <= MAXNAMLEN */
128 * Convert between stat structure types and directory types.
130 #define IFTODT(mode) (((mode) & 0170000) >> 12)
131 #define DTTOIF(dirtype) ((dirtype) << 12)
134 * The DIRSIZ macro gives the minimum record length which will hold
135 * the directory entry. This requires the amount of space in struct direct
136 * without the d_name field, plus enough space for the name with a terminating
137 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
139 #if (BYTE_ORDER == LITTLE_ENDIAN)
140 #define DIRSIZ(oldfmt, dp) \
142 ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
143 ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
145 #define DIRSIZ(oldfmt, dp) \
146 ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
152 * Template for manipulating directories. Should use struct direct's,
153 * but the name field is MAXNAMLEN - 1, and this just won't do.
160 char dot_name
[4]; /* must be multiple of 4 */
161 u_int32_t dotdot_ino
;
162 int16_t dotdot_reclen
;
163 u_int8_t dotdot_type
;
164 u_int8_t dotdot_namlen
;
165 char dotdot_name
[4]; /* ditto */
169 * This is the old format of directories, sanz type element.
171 struct odirtemplate
{
174 u_int16_t dot_namlen
;
175 char dot_name
[4]; /* must be multiple of 4 */
176 u_int32_t dotdot_ino
;
177 int16_t dotdot_reclen
;
178 u_int16_t dotdot_namlen
;
179 char dotdot_name
[4]; /* ditto */
181 #endif /* !_DIR_H_ */