]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/xfs_dir2_leaf.h
0c044a456236af59d531cfab5d60fb7fb5b2797a
[thirdparty/xfsprogs-dev.git] / include / xfs_dir2_leaf.h
1 /*
2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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_LEAF_H__
33 #define __XFS_DIR2_LEAF_H__
34
35 /*
36 * Directory version 2, leaf block structures.
37 */
38
39 struct dirent;
40 struct uio;
41 struct xfs_dabuf;
42 struct xfs_da_args;
43 struct xfs_inode;
44 struct xfs_mount;
45 struct xfs_trans;
46
47 /*
48 * Constants.
49 */
50
51 /*
52 * Offset of the leaf/node space. First block in this space
53 * is the btree root.
54 */
55 #define XFS_DIR2_LEAF_SPACE 1
56 #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
57 #define XFS_DIR2_LEAF_FIRSTDB(mp) \
58 XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_LEAF_OFFSET)
59
60 /*
61 * Types.
62 */
63
64 /*
65 * Offset in data space of a data entry.
66 */
67 typedef __uint32_t xfs_dir2_dataptr_t;
68 #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0x7fffffff)
69 #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
70
71 /*
72 * Structures.
73 */
74
75 /*
76 * Leaf block header.
77 */
78 typedef struct xfs_dir2_leaf_hdr {
79 xfs_da_blkinfo_t info; /* header for da routines */
80 __uint16_t count; /* count of entries */
81 __uint16_t stale; /* count of stale entries */
82 } xfs_dir2_leaf_hdr_t;
83
84 /*
85 * Leaf block entry.
86 */
87 typedef struct xfs_dir2_leaf_entry {
88 xfs_dahash_t hashval; /* hash value of name */
89 xfs_dir2_dataptr_t address; /* address of data entry */
90 } xfs_dir2_leaf_entry_t;
91
92 /*
93 * Leaf block tail.
94 */
95 typedef struct xfs_dir2_leaf_tail {
96 __uint32_t bestcount;
97 } xfs_dir2_leaf_tail_t;
98
99 /*
100 * Leaf block.
101 * bests and tail are at the end of the block for single-leaf only
102 * (magic = XFS_DIR2_LEAF1_MAGIC not XFS_DIR2_LEAFN_MAGIC).
103 */
104 typedef struct xfs_dir2_leaf {
105 xfs_dir2_leaf_hdr_t hdr; /* leaf header */
106 xfs_dir2_leaf_entry_t ents[1]; /* entries */
107 /* ... */
108 xfs_dir2_data_off_t bests[1]; /* best free counts */
109 xfs_dir2_leaf_tail_t tail; /* leaf tail */
110 } xfs_dir2_leaf_t;
111
112 /*
113 * Macros.
114 * The DB blocks are logical directory block numbers, not filesystem blocks.
115 */
116
117 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_MAX_LEAF_ENTS)
118 int
119 xfs_dir2_max_leaf_ents(struct xfs_mount *mp);
120 #define XFS_DIR2_MAX_LEAF_ENTS(mp) \
121 xfs_dir2_max_leaf_ents(mp)
122 #else
123 #define XFS_DIR2_MAX_LEAF_ENTS(mp) \
124 ((int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) / \
125 (uint)sizeof(xfs_dir2_leaf_entry_t)))
126 #endif
127
128 /*
129 * Get address of the bestcount field in the single-leaf block.
130 */
131 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_LEAF_TAIL_P)
132 xfs_dir2_leaf_tail_t *
133 xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp);
134 #define XFS_DIR2_LEAF_TAIL_P(mp,lp) \
135 xfs_dir2_leaf_tail_p(mp, lp)
136 #else
137 #define XFS_DIR2_LEAF_TAIL_P(mp,lp) \
138 ((xfs_dir2_leaf_tail_t *)\
139 ((char *)(lp) + (mp)->m_dirblksize - \
140 (uint)sizeof(xfs_dir2_leaf_tail_t)))
141 #endif
142
143 /*
144 * Get address of the bests array in the single-leaf block.
145 */
146 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_LEAF_BESTS_P)
147 xfs_dir2_data_off_t *
148 xfs_dir2_leaf_bests_p_arch(xfs_dir2_leaf_tail_t *ltp, xfs_arch_t arch);
149 #define XFS_DIR2_LEAF_BESTS_P_ARCH(ltp,arch) xfs_dir2_leaf_bests_p_arch(ltp,arch)
150 #else
151 #define XFS_DIR2_LEAF_BESTS_P_ARCH(ltp,arch) \
152 ((xfs_dir2_data_off_t *)(ltp) - INT_GET((ltp)->bestcount, arch))
153 #endif
154
155 /*
156 * Convert dataptr to byte in file space
157 */
158 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_BYTE)
159 xfs_dir2_off_t
160 xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp);
161 #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) xfs_dir2_dataptr_to_byte(mp, dp)
162 #else
163 #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) \
164 ((xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG)
165 #endif
166
167 /*
168 * Convert byte in file space to dataptr. It had better be aligned.
169 */
170 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DATAPTR)
171 xfs_dir2_dataptr_t
172 xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by);
173 #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) xfs_dir2_byte_to_dataptr(mp,by)
174 #else
175 #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) \
176 ((xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG))
177 #endif
178
179 /*
180 * Convert dataptr to a block number
181 */
182 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_DB)
183 xfs_dir2_db_t
184 xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp);
185 #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) xfs_dir2_dataptr_to_db(mp, dp)
186 #else
187 #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) \
188 XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
189 #endif
190
191 /*
192 * Convert dataptr to a byte offset in a block
193 */
194 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_OFF)
195 xfs_dir2_data_aoff_t
196 xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp);
197 #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) xfs_dir2_dataptr_to_off(mp, dp)
198 #else
199 #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) \
200 XFS_DIR2_BYTE_TO_OFF(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
201 #endif
202
203 /*
204 * Convert block and offset to byte in space
205 */
206 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_BYTE)
207 xfs_dir2_off_t
208 xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db,
209 xfs_dir2_data_aoff_t o);
210 #define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
211 xfs_dir2_db_off_to_byte(mp, db, o)
212 #else
213 #define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
214 (((xfs_dir2_off_t)(db) << \
215 ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o))
216 #endif
217
218 /*
219 * Convert byte in space to (DB) block
220 */
221 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DB)
222 xfs_dir2_db_t xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by);
223 #define XFS_DIR2_BYTE_TO_DB(mp,by) xfs_dir2_byte_to_db(mp, by)
224 #else
225 #define XFS_DIR2_BYTE_TO_DB(mp,by) \
226 ((xfs_dir2_db_t)((by) >> \
227 ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)))
228 #endif
229
230 /*
231 * Convert byte in space to (DA) block
232 */
233 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DA)
234 xfs_dablk_t xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by);
235 #define XFS_DIR2_BYTE_TO_DA(mp,by) xfs_dir2_byte_to_da(mp, by)
236 #else
237 #define XFS_DIR2_BYTE_TO_DA(mp,by) \
238 XFS_DIR2_DB_TO_DA(mp, XFS_DIR2_BYTE_TO_DB(mp, by))
239 #endif
240
241 /*
242 * Convert byte in space to offset in a block
243 */
244 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_OFF)
245 xfs_dir2_data_aoff_t
246 xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by);
247 #define XFS_DIR2_BYTE_TO_OFF(mp,by) xfs_dir2_byte_to_off(mp, by)
248 #else
249 #define XFS_DIR2_BYTE_TO_OFF(mp,by) \
250 ((xfs_dir2_data_aoff_t)((by) & \
251 ((1 << ((mp)->m_sb.sb_blocklog + \
252 (mp)->m_sb.sb_dirblklog)) - 1)))
253 #endif
254
255 /*
256 * Convert block and offset to dataptr
257 */
258 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_DATAPTR)
259 xfs_dir2_dataptr_t
260 xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db,
261 xfs_dir2_data_aoff_t o);
262 #define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
263 xfs_dir2_db_off_to_dataptr(mp, db, o)
264 #else
265 #define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
266 XFS_DIR2_BYTE_TO_DATAPTR(mp, XFS_DIR2_DB_OFF_TO_BYTE(mp, db, o))
267 #endif
268
269 /*
270 * Convert block (DB) to block (dablk)
271 */
272 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_TO_DA)
273 xfs_dablk_t xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db);
274 #define XFS_DIR2_DB_TO_DA(mp,db) xfs_dir2_db_to_da(mp, db)
275 #else
276 #define XFS_DIR2_DB_TO_DA(mp,db) \
277 ((xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog))
278 #endif
279
280 /*
281 * Convert block (dablk) to block (DB)
282 */
283 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DA_TO_DB)
284 xfs_dir2_db_t xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da);
285 #define XFS_DIR2_DA_TO_DB(mp,da) xfs_dir2_da_to_db(mp, da)
286 #else
287 #define XFS_DIR2_DA_TO_DB(mp,da) \
288 ((xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog))
289 #endif
290
291 /*
292 * Convert block (dablk) to byte offset in space
293 */
294 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DA_TO_BYTE)
295 xfs_dir2_off_t xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da);
296 #define XFS_DIR2_DA_TO_BYTE(mp,da) xfs_dir2_da_to_byte(mp, da)
297 #else
298 #define XFS_DIR2_DA_TO_BYTE(mp,da) \
299 XFS_DIR2_DB_OFF_TO_BYTE(mp, XFS_DIR2_DA_TO_DB(mp, da), 0)
300 #endif
301
302 /*
303 * Function declarations.
304 */
305
306 extern int
307 xfs_dir2_block_to_leaf(struct xfs_da_args *args, struct xfs_dabuf *dbp);
308
309 extern int
310 xfs_dir2_leaf_addname(struct xfs_da_args *args);
311
312 extern void
313 xfs_dir2_leaf_compact(struct xfs_da_args *args, struct xfs_dabuf *bp);
314
315 extern void
316 xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp,
317 int *lowstalep, int *highstalep, int *lowlogp,
318 int *highlogp);
319
320 extern int
321 xfs_dir2_leaf_getdents(struct xfs_trans *tp, struct xfs_inode *dp,
322 struct uio *uio, int *eofp, struct xfs_dirent *dbp,
323 xfs_dir2_put_t put);
324
325 extern int
326 xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno,
327 struct xfs_dabuf **bpp, int magic);
328
329 extern void
330 xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp,
331 int first, int last);
332
333 extern void
334 xfs_dir2_leaf_log_bests(struct xfs_trans *tp, struct xfs_dabuf *bp,
335 int first, int last);
336
337 extern void
338 xfs_dir2_leaf_log_header(struct xfs_trans *tp, struct xfs_dabuf *bp);
339
340 extern void
341 xfs_dir2_leaf_log_tail(struct xfs_trans *tp, struct xfs_dabuf *bp);
342
343 extern int
344 xfs_dir2_leaf_lookup(struct xfs_da_args *args);
345
346 extern int
347 xfs_dir2_leaf_removename(struct xfs_da_args *args);
348
349 extern int
350 xfs_dir2_leaf_replace(struct xfs_da_args *args);
351
352 extern int
353 xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
354 struct xfs_dabuf *lbp);
355 extern int
356 xfs_dir2_leaf_trim_data(struct xfs_da_args *args, struct xfs_dabuf *lbp, xfs_dir2_db_t db);
357
358 extern int
359 xfs_dir2_node_to_leaf(struct xfs_da_state *state);
360
361 #endif /* __XFS_DIR2_LEAF_H__ */