2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* $NetBSD: ext2fs_dir.h,v 1.4 2000/01/28 16:00:23 bouyer Exp $ */
27 * Copyright (c) 1997 Manuel Bouyer.
28 * Copyright (c) 1982, 1986, 1989, 1993
29 * The Regents of the University of California. All rights reserved.
30 * (c) UNIX System Laboratories, Inc.
31 * All or some portions of this file are derived from material licensed
32 * to the University of California by American Telephone and Telegraph
33 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
34 * the permission of UNIX System Laboratories, Inc.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)dir.h 8.4 (Berkeley) 8/10/94
65 * Modified for ext2fs by Manuel Bouyer.
68 * ext2fs_dir.h - Headers for Ext2 disk directory structures.
70 * Copyright (c) 2000 Apple Computer, Inc.
75 #ifndef _EXT2FS_DIR_H_
76 #define _EXT2FS_DIR_H_
79 * Theoretically, directories can be more than 2Gb in length, however, in
80 * practice this seems unlikely. So, we define the type doff_t as a 32-bit
81 * quantity to keep down the cost of doing lookup on a 32-bit machine.
83 #define doff_t int32_t
84 #define EXT2FS_MAXDIRSIZE (0x7fffffff)
87 * A directory consists of some number of blocks of e2fs_bsize bytes.
89 * Each block contains some number of directory entry
90 * structures, which are of variable length. Each directory entry has
91 * a struct direct at the front of it, containing its inode number,
92 * the length of the entry, and the length of the name contained in
93 * the entry. These are followed by the name padded to a 4 byte boundary
94 * with null bytes. All names are guaranteed null terminated.
95 * The maximum length of a name in a directory is EXT2FS_MAXNAMLEN.
97 * The macro EXT2FS_DIRSIZ(fmt, dp) gives the amount of space required to
98 * represent a directory entry. Free space in a directory is represented by
99 * entries which have dp->e2d_reclen > DIRSIZ(fmt, dp). All d2fs_bsize bytes
100 * in a directory block are claimed by the directory entries. This
101 * usually results in the last entry in a directory having a large
102 * dp->e2d_reclen. When entries are deleted from a directory, the
103 * space is returned to the previous entry in the same directory
104 * block by increasing its dp->e2d_reclen. If the first entry of
105 * a directory block is free, then its dp->e2d_ino is set to 0.
106 * Entries other than the first in a directory do not normally have
107 * dp->e2d_ino set to 0.
108 * Ext2 rev 0 has a 16 bits e2d_namlen. For Ext2 vev 1 this has been split
109 * into a 8 bits e2d_namlen and 8 bits e2d_type (looks like ffs, isnt't it ? :)
110 * It's safe to use this for rev 0 as well because all ext2 are little-endian.
113 #define EXT2FS_MAXNAMLEN 255
115 struct ext2fs_direct
{
116 u_int32_t e2d_ino
; /* inode number of entry */
117 u_int16_t e2d_reclen
; /* length of this record */
118 u_int8_t e2d_namlen
; /* length of string in d_name */
119 u_int8_t e2d_type
; /* file type */
120 char e2d_name
[EXT2FS_MAXNAMLEN
];/* name with length <= EXT2FS_MAXNAMLEN */
123 /* Ext2 directory file types (not the same as FFS. Sigh. */
124 #define EXT2_FT_UNKNOWN 0
125 #define EXT2_FT_REG_FILE 1
126 #define EXT2_FT_DIR 2
127 #define EXT2_FT_CHRDEV 3
128 #define EXT2_FT_BLKDEV 4
129 #define EXT2_FT_FIFO 5
130 #define EXT2_FT_SOCK 6
131 #define EXT2_FT_SYMLINK 7
133 #define EXT2_FT_MAX 8
135 #define E2IFTODT(mode) (((mode) & 0170000) >> 12)
137 static __inline__ u_int8_t inot2ext2dt
__P((u_int16_t
))
138 __attribute__((__unused__
));
139 static __inline__ u_int8_t
144 case E2IFTODT(EXT2_IFIFO
):
146 case E2IFTODT(EXT2_IFCHR
):
147 return EXT2_FT_CHRDEV
;
148 case E2IFTODT(EXT2_IFDIR
):
150 case E2IFTODT(EXT2_IFBLK
):
151 return EXT2_FT_BLKDEV
;
152 case E2IFTODT(EXT2_IFREG
):
153 return EXT2_FT_REG_FILE
;
154 case E2IFTODT(EXT2_IFLNK
):
155 return EXT2_FT_SYMLINK
;
156 case E2IFTODT(EXT2_IFSOCK
):
164 * The EXT2FS_DIRSIZ macro gives the minimum record length which will hold
165 * the directory entryfor a name len "len" (without the terminating null byte).
166 * This requires the amount of space in struct direct
167 * without the d_name field, plus enough space for the name without a
168 * terminating null byte, rounded up to a 4 byte boundary.
170 #define EXT2FS_DIRSIZ(len) \
171 (( 8 + len + 3) &~ 3)
174 * Template for manipulating directories. Should use struct direct's,
175 * but the name field is EXT2FS_MAXNAMLEN - 1, and this just won't do.
177 struct ext2fs_dirtemplate
{
182 char dot_name
[4]; /* must be multiple of 4 */
183 u_int32_t dotdot_ino
;
184 int16_t dotdot_reclen
;
185 u_int8_t dotdot_namlen
;
186 u_int8_t dotdot_type
;
187 char dotdot_name
[4]; /* ditto */
190 #endif /* !_EXT2FS_DIR_H_ */