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