Chameleon

Chameleon Svn Source Tree

Root/branches/slice/trunkM/i386/include/ufs/ufs/dir.h

1/*
2 * Copyright (c) 2000-2008 Apple, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29/*
30 * Copyright (c) 1982, 1986, 1989, 1993
31 *The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 *This product includes software developed by the University of
49 *California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 *@(#)dir.h8.5 (Berkeley) 4/27/95
67 */
68
69#ifndef _DIR_H_
70#define_DIR_H_
71
72#ifdef __APPLE_API_UNSTABLE
73/*
74 * Theoretically, directories can be more than 2Gb in length, however, in
75 * practice this seems unlikely. So, we define the type doff_t as a 32-bit
76 * quantity to keep down the cost of doing lookup on a 32-bit machine.
77 */
78#definedoff_tint32_t
79#define MAXDIRSIZE(0x7fffffff)
80
81/*
82 * A directory consists of some number of blocks of DIRBLKSIZ
83 * bytes, where DIRBLKSIZ is chosen such that it can be transferred
84 * to disk in a single atomic operation (e.g. 512 bytes on most machines).
85 *
86 * Each DIRBLKSIZ byte block contains some number of directory entry
87 * structures, which are of variable length. Each directory entry has
88 * a struct direct at the front of it, containing its inode number,
89 * the length of the entry, and the length of the name contained in
90 * the entry. These are followed by the name padded to a 4 byte boundary
91 * with null bytes. All names are guaranteed null terminated.
92 * The maximum length of a name in a directory is UFSMAXNAMLEN.
93 *
94 * The macro DIRSIZ(fmt, dp) gives the amount of space required to represent
95 * a directory entry. Free space in a directory is represented by
96 * entries which have dp->d_reclen > DIRSIZ(fmt, dp). All DIRBLKSIZ bytes
97 * in a directory block are claimed by the directory entries. This
98 * usually results in the last entry in a directory having a large
99 * dp->d_reclen. When entries are deleted from a directory, the
100 * space is returned to the previous entry in the same directory
101 * block by increasing its dp->d_reclen. If the first entry of
102 * a directory block is free, then its dp->d_ino is set to 0.
103 * Entries other than the first in a directory do not normally have
104 * dp->d_ino set to 0.
105 */
106#ifdef __APPLE__
107#define DIRBLKSIZ1024
108#else
109#define DIRBLKSIZDEV_BSIZE
110#endif
111#defineUFSMAXNAMLEN255
112
113structdirect {
114u_int32_t d_ino;/* inode number of entry */
115u_int16_t d_reclen;/* length of this record */
116u_int8_t d_type; /* file type, see below */
117u_int8_t d_namlen;/* length of string in d_name */
118char d_name[UFSMAXNAMLEN + 1];/* name with length <= UFSMAXNAMLEN */
119} __attribute__((packed,aligned(4)));
120
121/*
122 * File types
123 */
124#defineDT_UNKNOWN 0
125#defineDT_FIFO 1
126#defineDT_CHR 2
127#defineDT_DIR 4
128#defineDT_BLK 6
129#defineDT_REG 8
130#defineDT_LNK10
131#defineDT_SOCK12
132#defineDT_WHT14
133
134/*
135 * Convert between stat structure types and directory types.
136 */
137#defineIFTODT(mode)(((mode) & 0170000) >> 12)
138#defineDTTOIF(dirtype)((dirtype) << 12)
139
140/*
141 * The DIRSIZ macro gives the minimum record length which will hold
142 * the directory entry. This requires the amount of space in struct direct
143 * without the d_name field, plus enough space for the name with a terminating
144 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
145 */
146#if (BYTE_ORDER == LITTLE_ENDIAN)
147#define DIRSIZ(oldfmt, dp) \
148 ((oldfmt) ? \
149 ((sizeof(struct direct) - (UFSMAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
150 ((sizeof(struct direct) - (UFSMAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
151#else
152#define DIRSIZ(oldfmt, dp) \
153 ((sizeof(struct direct) - (UFSMAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
154#endif
155#define OLDDIRFMT1
156#define NEWDIRFMT0
157
158/*
159 * Template for manipulating directories. Should use struct direct's,
160 * but the name field is UFSMAXNAMLEN - 1, and this just won't do.
161 */
162struct dirtemplate {
163u_int32_tdot_ino;
164int16_tdot_reclen;
165u_int8_tdot_type;
166u_int8_tdot_namlen;
167chardot_name[4];/* must be multiple of 4 */
168u_int32_tdotdot_ino;
169int16_tdotdot_reclen;
170u_int8_tdotdot_type;
171u_int8_tdotdot_namlen;
172chardotdot_name[4];/* ditto */
173} __attribute__((packed,aligned(4)));
174
175/*
176 * This is the old format of directories, sanz type element.
177 */
178struct odirtemplate {
179u_int32_tdot_ino;
180int16_tdot_reclen;
181u_int16_tdot_namlen;
182chardot_name[4];/* must be multiple of 4 */
183u_int32_tdotdot_ino;
184int16_tdotdot_reclen;
185u_int16_tdotdot_namlen;
186chardotdot_name[4];/* ditto */
187} __attribute__((packed,aligned(4)));
188
189#endif /* __APPLE_API_UNSTABLE */
190#endif /* !_DIR_H_ */
191

Archive Download this file

Revision: 1171