ReactOS  0.4.14-dev-337-gf981a68
dir.h
Go to the documentation of this file.
1 /* $NetBSD: dir.h,v 1.17 2003/08/07 16:34:42 agc Exp $ */
2 
3 /*
4  * Copyright (c) 1982, 1986, 1989, 1993
5  * The Regents of the University of California. All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in the
19  * documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  * may be used to endorse or promote products derived from this software
22  * without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * @(#)dir.h 8.5 (Berkeley) 4/27/95
37  */
38 
39 #ifndef _UFS_UFS_DIR_H_
40 #define _UFS_UFS_DIR_H_
41 
42 #include "type.h"
43 
44 /*
45  * Theoretically, directories can be more than 2Gb in length, however, in
46  * practice this seems unlikely. So, we define the type doff_t as a 32-bit
47  * quantity to keep down the cost of doing lookup on a 32-bit machine.
48  */
49 #define doff_t int32_t
50 #define MAXDIRSIZE (0x7fffffff)
51 
52 /*
53  * A directory consists of some number of blocks of DIRBLKSIZ
54  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
55  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
56  *
57  * Each DIRBLKSIZ byte block contains some number of directory entry
58  * structures, which are of variable length. Each directory entry has
59  * a struct direct at the front of it, containing its inode number,
60  * the length of the entry, and the length of the name contained in
61  * the entry. These are followed by the name padded to a 4 byte boundary.
62  * All names are guaranteed null terminated.
63  * The maximum length of a name in a directory is MAXNAMLEN.
64  *
65  * The macro DIRSIZ(fmt, dp) gives the amount of space required to represent
66  * a directory entry. Free space in a directory is represented by
67  * entries which have dp->d_reclen > DIRSIZ(fmt, dp). All DIRBLKSIZ bytes
68  * in a directory block are claimed by the directory entries. This
69  * usually results in the last entry in a directory having a large
70  * dp->d_reclen. When entries are deleted from a directory, the
71  * space is returned to the previous entry in the same directory
72  * block by increasing its dp->d_reclen. If the first entry of
73  * a directory block is free, then its dp->d_ino is set to 0.
74  * Entries other than the first in a directory do not normally have
75  * dp->d_ino set to 0.
76  */
77 #undef DIRBLKSIZ
78 #define DIRBLKSIZ DEV_BSIZE
79 #undef MAXNAMLEN
80 #define MAXNAMLEN 255
81 #define APPLEUFS_DIRBLKSIZ 1024
82 
83 struct direct {
84  u_int32_t d_ino; /* inode number of entry */
85  u_int16_t d_reclen; /* length of this record */
86  u_int8_t d_type; /* file type, see below */
87  u_int8_t d_namlen; /* length of string in d_name */
88  char d_name[MAXNAMLEN + 1];/* name with length <= MAXNAMLEN */
89 };
90 
91 /*
92  * File types
93  */
94 #define DT_UNKNOWN 0
95 #define DT_FIFO 1
96 #define DT_CHR 2
97 #define DT_DIR 4
98 #define DT_BLK 6
99 #define DT_REG 8
100 #define DT_LNK 10
101 #define DT_SOCK 12
102 #define DT_WHT 14
103 
104 /*
105  * Convert between stat structure types and directory types.
106  */
107 #define IFTODT(mode) (((mode) & 0170000) >> 12)
108 #define DTTOIF(dirtype) ((dirtype) << 12)
109 
110 /*
111  * The DIRSIZ macro gives the minimum record length which will hold
112  * the directory entry. This requires the amount of space in struct direct
113  * without the d_name field, plus enough space for the name with a terminating
114  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
115  */
116 #define DIRECTSIZ(namlen) \
117  ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((namlen)+1 + 3) &~ 3))
118 
119 #if (BYTE_ORDER == LITTLE_ENDIAN)
120 #define DIRSIZ(oldfmt, dp, needswap) \
121  (((oldfmt) && !(needswap)) ? \
122  DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
123 #else
124 #define DIRSIZ(oldfmt, dp, needswap) \
125  (((oldfmt) && (needswap)) ? \
126  DIRECTSIZ((dp)->d_type) : DIRECTSIZ((dp)->d_namlen))
127 #endif
128 
129 #define OLDDIRFMT 1
130 #define NEWDIRFMT 0
131 
132 /*
133  * Template for manipulating directories. Should use struct direct's,
134  * but the name field is MAXNAMLEN - 1, and this just won't do.
135  */
136 struct dirtemplate {
141  char dot_name[4]; /* must be multiple of 4 */
146  char dotdot_name[4]; /* ditto */
147 };
148 
149 /*
150  * This is the old format of directories, sanz type element.
151  */
152 struct odirtemplate {
156  char dot_name[4]; /* must be multiple of 4 */
160  char dotdot_name[4]; /* ditto */
161 };
162 #endif /* !_UFS_UFS_DIR_H_ */
int16_t dotdot_reclen
Definition: dir.h:143
Definition: dir.h:83
u_int32_t dotdot_ino
Definition: dir.h:142
u_int32_t dot_ino
Definition: dir.h:137
char dotdot_name[4]
Definition: dir.h:146
u_int16_t dotdot_namlen
Definition: dir.h:159
u_int16_t dot_namlen
Definition: dir.h:155
int16_t dot_reclen
Definition: dir.h:154
unsigned char u_int8_t
Definition: rosdhcp.h:33
u_int32_t d_ino
Definition: dir.h:84
char dotdot_name[4]
Definition: dir.h:160
u_int8_t d_type
Definition: dir.h:86
char d_name[MAXNAMLEN+1]
Definition: dir.h:88
u_int8_t dotdot_type
Definition: dir.h:144
char dot_name[4]
Definition: dir.h:156
unsigned short u_int16_t
Definition: rosdhcp.h:34
u_int8_t dotdot_namlen
Definition: dir.h:145
unsigned int u_int32_t
Definition: rosdhcp.h:35
u_int16_t d_reclen
Definition: dir.h:85
int16_t dot_reclen
Definition: dir.h:138
u_int8_t dot_namlen
Definition: dir.h:140
u_int32_t dotdot_ino
Definition: dir.h:157
char dot_name[4]
Definition: dir.h:141
u_int32_t dot_ino
Definition: dir.h:153
#define MAXNAMLEN
Definition: dir.h:80
INT16 int16_t
Definition: types.h:70
u_int8_t dot_type
Definition: dir.h:139
int16_t dotdot_reclen
Definition: dir.h:158
u_int8_t d_namlen
Definition: dir.h:87