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 /* $NetBSD: ext2fs_dir.h,v 1.4 2000/01/28 16:00:23 bouyer Exp $ */
24 * Copyright (c) 1997 Manuel Bouyer.
25 * Copyright (c) 1982, 1986, 1989, 1993
26 * The Regents of the University of California. All rights reserved.
27 * (c) UNIX System Laboratories, Inc.
28 * All or some portions of this file are derived from material licensed
29 * to the University of California by American Telephone and Telegraph
30 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
31 * the permission of UNIX System Laboratories, Inc.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)dir.h 8.4 (Berkeley) 8/10/94
62 * Modified for ext2fs by Manuel Bouyer.
65 * ext2fs_dir.h - Headers for Ext2 disk directory structures.
67 * Copyright (c) 2000 Apple Computer, Inc.
72 #ifndef _EXT2FS_DIR_H_
73 #define _EXT2FS_DIR_H_
76 * Theoretically, directories can be more than 2Gb in length, however, in
77 * practice this seems unlikely. So, we define the type doff_t as a 32-bit
78 * quantity to keep down the cost of doing lookup on a 32-bit machine.
80 #define doff_t int32_t
81 #define EXT2FS_MAXDIRSIZE (0x7fffffff)
84 * A directory consists of some number of blocks of e2fs_bsize bytes.
86 * Each 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 EXT2FS_MAXNAMLEN.
94 * The macro EXT2FS_DIRSIZ(fmt, dp) gives the amount of space required to
95 * represent a directory entry. Free space in a directory is represented by
96 * entries which have dp->e2d_reclen > DIRSIZ(fmt, dp). All d2fs_bsize 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->e2d_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->e2d_reclen. If the first entry of
102 * a directory block is free, then its dp->e2d_ino is set to 0.
103 * Entries other than the first in a directory do not normally have
104 * dp->e2d_ino set to 0.
105 * Ext2 rev 0 has a 16 bits e2d_namlen. For Ext2 vev 1 this has been split
106 * into a 8 bits e2d_namlen and 8 bits e2d_type (looks like ffs, isnt't it ? :)
107 * It's safe to use this for rev 0 as well because all ext2 are little-endian.
110 #define EXT2FS_MAXNAMLEN 255
112 struct ext2fs_direct
{
113 u_int32_t e2d_ino
; /* inode number of entry */
114 u_int16_t e2d_reclen
; /* length of this record */
115 u_int8_t e2d_namlen
; /* length of string in d_name */
116 u_int8_t e2d_type
; /* file type */
117 char e2d_name
[EXT2FS_MAXNAMLEN
];/* name with length <= EXT2FS_MAXNAMLEN */
120 /* Ext2 directory file types (not the same as FFS. Sigh. */
121 #define EXT2_FT_UNKNOWN 0
122 #define EXT2_FT_REG_FILE 1
123 #define EXT2_FT_DIR 2
124 #define EXT2_FT_CHRDEV 3
125 #define EXT2_FT_BLKDEV 4
126 #define EXT2_FT_FIFO 5
127 #define EXT2_FT_SOCK 6
128 #define EXT2_FT_SYMLINK 7
130 #define EXT2_FT_MAX 8
132 #define E2IFTODT(mode) (((mode) & 0170000) >> 12)
134 static __inline__ u_int8_t inot2ext2dt
__P((u_int16_t
))
135 __attribute__((__unused__
));
136 static __inline__ u_int8_t
141 case E2IFTODT(EXT2_IFIFO
):
143 case E2IFTODT(EXT2_IFCHR
):
144 return EXT2_FT_CHRDEV
;
145 case E2IFTODT(EXT2_IFDIR
):
147 case E2IFTODT(EXT2_IFBLK
):
148 return EXT2_FT_BLKDEV
;
149 case E2IFTODT(EXT2_IFREG
):
150 return EXT2_FT_REG_FILE
;
151 case E2IFTODT(EXT2_IFLNK
):
152 return EXT2_FT_SYMLINK
;
153 case E2IFTODT(EXT2_IFSOCK
):
161 * The EXT2FS_DIRSIZ macro gives the minimum record length which will hold
162 * the directory entryfor a name len "len" (without the terminating null byte).
163 * This requires the amount of space in struct direct
164 * without the d_name field, plus enough space for the name without a
165 * terminating null byte, rounded up to a 4 byte boundary.
167 #define EXT2FS_DIRSIZ(len) \
168 (( 8 + len + 3) &~ 3)
171 * Template for manipulating directories. Should use struct direct's,
172 * but the name field is EXT2FS_MAXNAMLEN - 1, and this just won't do.
174 struct ext2fs_dirtemplate
{
179 char dot_name
[4]; /* must be multiple of 4 */
180 u_int32_t dotdot_ino
;
181 int16_t dotdot_reclen
;
182 u_int8_t dotdot_namlen
;
183 u_int8_t dotdot_type
;
184 char dotdot_name
[4]; /* ditto */
187 #endif /* !_EXT2FS_DIR_H_ */