2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_DIR2_LEAF_H__
33 #define __XFS_DIR2_LEAF_H__
36 * Directory version 2, leaf block structures.
51 * Offset of the leaf/node space. First block in this space
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)
64 * Offset in data space of a data entry.
66 typedef __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)
77 typedef 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
;
86 typedef 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
;
94 typedef struct xfs_dir2_leaf_tail
{
96 } xfs_dir2_leaf_tail_t
;
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).
103 typedef struct xfs_dir2_leaf
{
104 xfs_dir2_leaf_hdr_t hdr
; /* leaf header */
105 xfs_dir2_leaf_entry_t ents
[1]; /* entries */
107 xfs_dir2_data_off_t bests
[1]; /* best free counts */
108 xfs_dir2_leaf_tail_t tail
; /* leaf tail */
113 * The DB blocks are logical directory block numbers, not filesystem blocks.
116 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_MAX_LEAF_ENTS)
118 xfs_dir2_max_leaf_ents(struct xfs_mount
*mp
);
119 #define XFS_DIR2_MAX_LEAF_ENTS(mp) \
120 xfs_dir2_max_leaf_ents(mp)
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)))
128 * Get address of the bestcount field in the single-leaf block.
130 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_LEAF_TAIL_P)
131 xfs_dir2_leaf_tail_t
*
132 xfs_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)
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)))
143 * Get address of the bests array in the single-leaf block.
145 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_LEAF_BESTS_P)
146 xfs_dir2_data_off_t
*
147 xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t
*ltp
);
148 #define XFS_DIR2_LEAF_BESTS_P(ltp) xfs_dir2_leaf_bests_p(ltp)
150 #define XFS_DIR2_LEAF_BESTS_P(ltp) \
151 ((xfs_dir2_data_off_t *)(ltp) - INT_GET((ltp)->bestcount, ARCH_CONVERT))
155 * Convert dataptr to byte in file space
157 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_BYTE)
159 xfs_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)
162 #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) \
163 ((xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG)
167 * Convert byte in file space to dataptr. It had better be aligned.
169 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DATAPTR)
171 xfs_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)
174 #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) \
175 ((xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG))
179 * Convert dataptr to a block number
181 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_DB)
183 xfs_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)
186 #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) \
187 XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
191 * Convert dataptr to a byte offset in a block
193 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_OFF)
195 xfs_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)
198 #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) \
199 XFS_DIR2_BYTE_TO_OFF(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
203 * Convert block and offset to byte in space
205 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_BYTE)
207 xfs_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)
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))
218 * Convert byte in space to (DB) block
220 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DB)
221 xfs_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)
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)))
230 * Convert byte in space to (DA) block
232 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DA)
233 xfs_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)
236 #define XFS_DIR2_BYTE_TO_DA(mp,by) \
237 XFS_DIR2_DB_TO_DA(mp, XFS_DIR2_BYTE_TO_DB(mp, by))
241 * Convert byte in space to offset in a block
243 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_OFF)
245 xfs_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)
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)))
255 * Convert block and offset to dataptr
257 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_DATAPTR)
259 xfs_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)
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))
269 * Convert block (DB) to block (dablk)
271 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_TO_DA)
272 xfs_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)
275 #define XFS_DIR2_DB_TO_DA(mp,db) \
276 ((xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog))
280 * Convert block (dablk) to block (DB)
282 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DA_TO_DB)
283 xfs_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)
286 #define XFS_DIR2_DA_TO_DB(mp,da) \
287 ((xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog))
291 * Convert block (dablk) to byte offset in space
293 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DA_TO_BYTE)
294 xfs_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)
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)
302 * Function declarations.
306 xfs_dir2_block_to_leaf(struct xfs_da_args
*args
, struct xfs_dabuf
*dbp
);
309 xfs_dir2_leaf_addname(struct xfs_da_args
*args
);
312 xfs_dir2_leaf_compact(struct xfs_da_args
*args
, struct xfs_dabuf
*bp
);
315 xfs_dir2_leaf_compact_x1(struct xfs_dabuf
*bp
, int *indexp
,
316 int *lowstalep
, int *highstalep
, int *lowlogp
,
320 xfs_dir2_leaf_getdents(struct xfs_trans
*tp
, struct xfs_inode
*dp
,
321 struct uio
*uio
, int *eofp
, struct xfs_dirent
*dbp
,
325 xfs_dir2_leaf_init(struct xfs_da_args
*args
, xfs_dir2_db_t bno
,
326 struct xfs_dabuf
**bpp
, int magic
);
329 xfs_dir2_leaf_log_ents(struct xfs_trans
*tp
, struct xfs_dabuf
*bp
,
330 int first
, int last
);
333 xfs_dir2_leaf_log_header(struct xfs_trans
*tp
, struct xfs_dabuf
*bp
);
336 xfs_dir2_leaf_lookup(struct xfs_da_args
*args
);
339 xfs_dir2_leaf_removename(struct xfs_da_args
*args
);
342 xfs_dir2_leaf_replace(struct xfs_da_args
*args
);
345 xfs_dir2_leaf_search_hash(struct xfs_da_args
*args
,
346 struct xfs_dabuf
*lbp
);
348 xfs_dir2_leaf_trim_data(struct xfs_da_args
*args
, struct xfs_dabuf
*lbp
, xfs_dir2_db_t db
);
351 xfs_dir2_node_to_leaf(struct xfs_da_state
*state
);
353 #endif /* __XFS_DIR2_LEAF_H__ */