]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
0d3e0b37 | 2 | * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved. |
2bd0ea18 NS |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it would be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 | * | |
12 | * Further, this software is distributed without any warranty that it is | |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | #ifndef __XFS_DIR2_SF_H__ | |
33 | #define __XFS_DIR2_SF_H__ | |
34 | ||
35 | /* | |
36 | * Directory layout when stored internal to an inode. | |
37 | * | |
38 | * Small directories are packed as tightly as possible so as to | |
39 | * fit into the literal area of the inode. | |
40 | */ | |
41 | ||
42 | struct dirent; | |
43 | struct uio; | |
44 | struct xfs_dabuf; | |
45 | struct xfs_da_args; | |
46 | struct xfs_dir2_block; | |
47 | struct xfs_inode; | |
48 | struct xfs_mount; | |
49 | struct xfs_trans; | |
50 | ||
51 | /* | |
52 | * Maximum size of a shortform directory. | |
53 | */ | |
54 | #define XFS_DIR2_SF_MAX_SIZE \ | |
55 | (XFS_DINODE_MAX_SIZE - (uint)sizeof(xfs_dinode_core_t) - \ | |
56 | (uint)sizeof(xfs_agino_t)) | |
57 | ||
58 | /* | |
59 | * Inode number stored as 8 8-bit values. | |
60 | */ | |
61 | typedef struct { __uint8_t i[8]; } xfs_dir2_ino8_t; | |
62 | ||
63 | #define XFS_DIR2_SF_GET_INO8_ARCH(di,arch) \ | |
64 | (xfs_ino_t)(DIRINO_GET_ARCH(&di,arch)) | |
65 | #define XFS_DIR2_SF_GET_INO8(di) \ | |
66 | XFS_DIR2_SF_GET_INO8_ARCH(di,ARCH_NOCONVERT) | |
67 | ||
68 | /* | |
69 | * Inode number stored as 4 8-bit values. | |
70 | * Works a lot of the time, when all the inode numbers in a directory | |
71 | * fit in 32 bits. | |
72 | */ | |
73 | typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t; | |
74 | #define XFS_DIR2_SF_GET_INO4_ARCH(di,arch) \ | |
75 | (xfs_ino_t)(DIRINO4_GET_ARCH(&di,arch)) | |
76 | #define XFS_DIR2_SF_GET_INO4(di) \ | |
77 | XFS_DIR2_SF_GET_INO4_ARCH(di,ARCH_NOCONVERT) | |
78 | ||
79 | typedef union { | |
80 | xfs_dir2_ino8_t i8; | |
81 | xfs_dir2_ino4_t i4; | |
82 | } xfs_dir2_inou_t; | |
83 | #define XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL) | |
84 | ||
85 | /* | |
86 | * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t. | |
87 | * Only need 16 bits, this is the byte offset into the single block form. | |
88 | */ | |
89 | typedef struct { __uint8_t i[2]; } xfs_dir2_sf_off_t; | |
90 | ||
91 | /* | |
92 | * The parent directory has a dedicated field, and the self-pointer must | |
93 | * be calculated on the fly. | |
94 | * | |
95 | * Entries are packed toward the top as tightly as possible. The header | |
96 | * and the elements must be bcopy()'d out into a work area to get correct | |
97 | * alignment for the inode number fields. | |
98 | */ | |
99 | typedef struct xfs_dir2_sf_hdr { | |
100 | __uint8_t count; /* count of entries */ | |
101 | __uint8_t i8count; /* count of 8-byte inode #s */ | |
102 | xfs_dir2_inou_t parent; /* parent dir inode number */ | |
103 | } xfs_dir2_sf_hdr_t; | |
104 | ||
105 | typedef struct xfs_dir2_sf_entry { | |
106 | __uint8_t namelen; /* actual name length */ | |
107 | xfs_dir2_sf_off_t offset; /* saved offset */ | |
108 | __uint8_t name[1]; /* name, variable size */ | |
109 | xfs_dir2_inou_t inumber; /* inode number, var. offset */ | |
110 | } xfs_dir2_sf_entry_t; | |
111 | ||
112 | typedef struct xfs_dir2_sf { | |
113 | xfs_dir2_sf_hdr_t hdr; /* shortform header */ | |
114 | xfs_dir2_sf_entry_t list[1]; /* shortform entries */ | |
115 | } xfs_dir2_sf_t; | |
116 | ||
117 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_HDR_SIZE) | |
118 | int xfs_dir2_sf_hdr_size(int i8count); | |
119 | #define XFS_DIR2_SF_HDR_SIZE(i8count) xfs_dir2_sf_hdr_size(i8count) | |
120 | #else | |
121 | #define XFS_DIR2_SF_HDR_SIZE(i8count) \ | |
122 | ((uint)sizeof(xfs_dir2_sf_hdr_t) - \ | |
123 | ((i8count) == 0) * \ | |
124 | ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t))) | |
125 | #endif | |
126 | ||
127 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_INUMBERP) | |
128 | xfs_dir2_inou_t *xfs_dir2_sf_inumberp(xfs_dir2_sf_entry_t *sfep); | |
129 | #define XFS_DIR2_SF_INUMBERP(sfep) xfs_dir2_sf_inumberp(sfep) | |
130 | #else | |
131 | #define XFS_DIR2_SF_INUMBERP(sfep) \ | |
132 | ((xfs_dir2_inou_t *)&(sfep)->name[(sfep)->namelen]) | |
133 | #endif | |
134 | ||
135 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_GET_INUMBER) | |
136 | xfs_intino_t xfs_dir2_sf_get_inumber_arch(xfs_dir2_sf_t *sfp, xfs_dir2_inou_t *from, | |
137 | xfs_arch_t arch); | |
138 | #define XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, from, arch) \ | |
139 | xfs_dir2_sf_get_inumber_arch(sfp, from, arch) | |
140 | ||
141 | #else | |
142 | #define XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, from, arch) \ | |
143 | ((sfp)->hdr.i8count == 0 ? \ | |
144 | (xfs_intino_t)XFS_DIR2_SF_GET_INO4_ARCH(*(from), arch) : \ | |
145 | (xfs_intino_t)XFS_DIR2_SF_GET_INO8_ARCH(*(from), arch)) | |
146 | #endif | |
147 | ||
148 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_PUT_INUMBER) | |
149 | void xfs_dir2_sf_put_inumber_arch(xfs_dir2_sf_t *sfp, xfs_ino_t *from, | |
150 | xfs_dir2_inou_t *to, xfs_arch_t arch); | |
151 | #define XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp,from,to,arch) \ | |
152 | xfs_dir2_sf_put_inumber_arch(sfp,from,to,arch) | |
153 | #else | |
154 | #define XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp,from,to,arch) \ | |
155 | if ((sfp)->hdr.i8count == 0) { \ | |
156 | DIRINO4_COPY_ARCH(from,to,arch); \ | |
157 | } else { \ | |
158 | DIRINO_COPY_ARCH(from,to,arch); \ | |
159 | } | |
160 | #endif | |
161 | ||
162 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_GET_OFFSET) | |
163 | xfs_dir2_data_aoff_t xfs_dir2_sf_get_offset_arch(xfs_dir2_sf_entry_t *sfep, | |
164 | xfs_arch_t arch); | |
165 | xfs_dir2_data_aoff_t xfs_dir2_sf_get_offset(xfs_dir2_sf_entry_t *sfep); | |
166 | #define XFS_DIR2_SF_GET_OFFSET_ARCH(sfep,arch) \ | |
167 | xfs_dir2_sf_get_offset_arch(sfep,arch) | |
168 | #else | |
169 | #define XFS_DIR2_SF_GET_OFFSET_ARCH(sfep,arch) \ | |
170 | INT_GET_UNALIGNED_16_ARCH(&(sfep)->offset.i,arch) | |
171 | #endif | |
172 | ||
173 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_PUT_OFFSET) | |
174 | void xfs_dir2_sf_put_offset_arch(xfs_dir2_sf_entry_t *sfep, | |
175 | xfs_dir2_data_aoff_t off, xfs_arch_t arch); | |
176 | #define XFS_DIR2_SF_PUT_OFFSET_ARCH(sfep,off,arch) \ | |
177 | xfs_dir2_sf_put_offset_arch(sfep,off,arch) | |
178 | #else | |
179 | #define XFS_DIR2_SF_PUT_OFFSET_ARCH(sfep,off,arch) \ | |
180 | INT_SET_UNALIGNED_16_ARCH(&(sfep)->offset.i,off,arch) | |
181 | #endif | |
182 | ||
183 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_ENTSIZE_BYNAME) | |
184 | int xfs_dir2_sf_entsize_byname(xfs_dir2_sf_t *sfp, int len); | |
185 | #define XFS_DIR2_SF_ENTSIZE_BYNAME(sfp,len) \ | |
186 | xfs_dir2_sf_entsize_byname(sfp,len) | |
187 | #else | |
188 | #define XFS_DIR2_SF_ENTSIZE_BYNAME(sfp,len) /* space a name uses */ \ | |
189 | ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (len) - \ | |
190 | ((sfp)->hdr.i8count == 0) * \ | |
191 | ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t))) | |
192 | #endif | |
193 | ||
194 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_ENTSIZE_BYENTRY) | |
195 | int xfs_dir2_sf_entsize_byentry(xfs_dir2_sf_t *sfp, xfs_dir2_sf_entry_t *sfep); | |
196 | #define XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep) \ | |
197 | xfs_dir2_sf_entsize_byentry(sfp,sfep) | |
198 | #else | |
199 | #define XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep) /* space an entry uses */ \ | |
200 | ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (sfep)->namelen - \ | |
201 | ((sfp)->hdr.i8count == 0) * \ | |
202 | ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t))) | |
203 | #endif | |
204 | ||
205 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_FIRSTENTRY) | |
206 | xfs_dir2_sf_entry_t *xfs_dir2_sf_firstentry(xfs_dir2_sf_t *sfp); | |
207 | #define XFS_DIR2_SF_FIRSTENTRY(sfp) xfs_dir2_sf_firstentry(sfp) | |
208 | #else | |
209 | #define XFS_DIR2_SF_FIRSTENTRY(sfp) /* first entry in struct */ \ | |
210 | ((xfs_dir2_sf_entry_t *) \ | |
211 | ((char *)(sfp) + XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count))) | |
212 | #endif | |
213 | ||
214 | #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_NEXTENTRY) | |
215 | xfs_dir2_sf_entry_t *xfs_dir2_sf_nextentry(xfs_dir2_sf_t *sfp, | |
216 | xfs_dir2_sf_entry_t *sfep); | |
217 | #define XFS_DIR2_SF_NEXTENTRY(sfp,sfep) xfs_dir2_sf_nextentry(sfp,sfep) | |
218 | #else | |
219 | #define XFS_DIR2_SF_NEXTENTRY(sfp,sfep) /* next entry in struct */ \ | |
220 | ((xfs_dir2_sf_entry_t *) \ | |
221 | ((char *)(sfep) + XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep))) | |
222 | #endif | |
223 | ||
224 | /* | |
225 | * Functions. | |
226 | */ | |
227 | ||
228 | extern int | |
229 | xfs_dir2_block_sfsize(struct xfs_inode *dp, | |
230 | struct xfs_dir2_block *block, | |
231 | xfs_dir2_sf_hdr_t *sfhp); | |
232 | ||
233 | extern int | |
234 | xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_dabuf *bp, | |
235 | int size, xfs_dir2_sf_hdr_t *sfhp); | |
236 | ||
237 | extern int | |
238 | xfs_dir2_sf_addname(struct xfs_da_args *args); | |
239 | ||
240 | extern int | |
241 | xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino); | |
242 | ||
243 | extern int | |
244 | xfs_dir2_sf_getdents(struct xfs_inode *dp, struct uio *uio, int *eofp, | |
0e266570 | 245 | struct xfs_dirent *dbp, xfs_dir2_put_t put); |
2bd0ea18 NS |
246 | |
247 | extern int | |
248 | xfs_dir2_sf_lookup(struct xfs_da_args *args); | |
249 | ||
250 | extern int | |
251 | xfs_dir2_sf_removename(struct xfs_da_args *args); | |
252 | ||
253 | extern int | |
254 | xfs_dir2_sf_replace(struct xfs_da_args *args); | |
255 | ||
256 | #endif /* __XFS_DIR2_SF_H__ */ |