blob: 3303cd6f4c0045362b4b1e87fa27918a2baf470d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2001 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
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 */
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) \
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 */
66typedef __uint32_t xfs_dir2_dataptr_t;
67#define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
68#define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
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);
119#define XFS_DIR2_MAX_LEAF_ENTS(mp) \
120 xfs_dir2_max_leaf_ents(mp)
121#else
122#define XFS_DIR2_MAX_LEAF_ENTS(mp) \
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);
133#define XFS_DIR2_LEAF_TAIL_P(mp,lp) \
134 xfs_dir2_leaf_tail_p(mp, lp)
135#else
136#define XFS_DIR2_LEAF_TAIL_P(mp,lp) \
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(xfs_dir2_leaf_tail_t *ltp);
148#define XFS_DIR2_LEAF_BESTS_P(ltp) xfs_dir2_leaf_bests_p(ltp)
149#else
150#define XFS_DIR2_LEAF_BESTS_P(ltp) \
151 ((xfs_dir2_data_off_t *)(ltp) - INT_GET((ltp)->bestcount, ARCH_CONVERT))
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);
160#define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) xfs_dir2_dataptr_to_byte(mp, dp)
161#else
162#define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) \
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);
172#define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) xfs_dir2_byte_to_dataptr(mp,by)
173#else
174#define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) \
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);
184#define XFS_DIR2_DATAPTR_TO_DB(mp,dp) xfs_dir2_dataptr_to_db(mp, dp)
185#else
186#define XFS_DIR2_DATAPTR_TO_DB(mp,dp) \
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);
196#define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) xfs_dir2_dataptr_to_off(mp, dp)
197#else
198#define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) \
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);
209#define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
210 xfs_dir2_db_off_to_byte(mp, db, o)
211#else
212#define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
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);
222#define XFS_DIR2_BYTE_TO_DB(mp,by) xfs_dir2_byte_to_db(mp, by)
223#else
224#define XFS_DIR2_BYTE_TO_DB(mp,by) \
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);
234#define XFS_DIR2_BYTE_TO_DA(mp,by) xfs_dir2_byte_to_da(mp, by)
235#else
236#define XFS_DIR2_BYTE_TO_DA(mp,by) \
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);
246#define XFS_DIR2_BYTE_TO_OFF(mp,by) xfs_dir2_byte_to_off(mp, by)
247#else
248#define XFS_DIR2_BYTE_TO_OFF(mp,by) \
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);
261#define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
262 xfs_dir2_db_off_to_dataptr(mp, db, o)
263#else
264#define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
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);
273#define XFS_DIR2_DB_TO_DA(mp,db) xfs_dir2_db_to_da(mp, db)
274#else
275#define XFS_DIR2_DB_TO_DA(mp,db) \
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);
284#define XFS_DIR2_DA_TO_DB(mp,da) xfs_dir2_da_to_db(mp, da)
285#else
286#define XFS_DIR2_DA_TO_DB(mp,da) \
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
297#define XFS_DIR2_DA_TO_BYTE(mp,da) \
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,
321 struct uio *uio, int *eofp, struct xfs_dirent *dbp,
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 xfs_dir2_leaf_log_header(struct xfs_trans *tp, struct xfs_dabuf *bp);
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335extern int
336 xfs_dir2_leaf_lookup(struct xfs_da_args *args);
337
338extern int
339 xfs_dir2_leaf_removename(struct xfs_da_args *args);
340
341extern int
342 xfs_dir2_leaf_replace(struct xfs_da_args *args);
343
344extern int
345 xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
346 struct xfs_dabuf *lbp);
347extern int
348 xfs_dir2_leaf_trim_data(struct xfs_da_args *args, struct xfs_dabuf *lbp, xfs_dir2_db_t db);
349
350extern int
351 xfs_dir2_node_to_leaf(struct xfs_da_state *state);
352
353#endif /* __XFS_DIR2_LEAF_H__ */