2 * Copyright (c) 2000 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.
52 * Offset of the leaf/node space. First block in this space
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)
65 * Offset in data space of a data entry.
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)
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
;
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
;
95 typedef struct xfs_dir2_leaf_tail
{
97 } xfs_dir2_leaf_tail_t
;
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).
104 typedef struct xfs_dir2_leaf
{
105 xfs_dir2_leaf_hdr_t hdr
; /* leaf header */
106 xfs_dir2_leaf_entry_t ents
[1]; /* entries */
108 xfs_dir2_data_off_t bests
[1]; /* best free counts */
109 xfs_dir2_leaf_tail_t tail
; /* leaf tail */
114 * The DB blocks are logical directory block numbers, not filesystem blocks.
117 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_MAX_LEAF_ENTS)
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)
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)))
129 * Get address of the bestcount field in the single-leaf block.
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)
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)))
144 * Get address of the bests array in the single-leaf block.
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)
151 #define XFS_DIR2_LEAF_BESTS_P_ARCH(ltp,arch) \
152 ((xfs_dir2_data_off_t *)(ltp) - INT_GET((ltp)->bestcount, arch))
156 * Convert dataptr to byte in file space
158 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_BYTE)
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)
163 #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) \
164 ((xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG)
168 * Convert byte in file space to dataptr. It had better be aligned.
170 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DATAPTR)
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)
175 #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) \
176 ((xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG))
180 * Convert dataptr to a block number
182 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_DB)
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)
187 #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) \
188 XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
192 * Convert dataptr to a byte offset in a block
194 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_OFF)
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)
199 #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) \
200 XFS_DIR2_BYTE_TO_OFF(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
204 * Convert block and offset to byte in space
206 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_BYTE)
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)
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))
219 * Convert byte in space to (DB) block
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)
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)))
231 * Convert byte in space to (DA) block
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)
237 #define XFS_DIR2_BYTE_TO_DA(mp,by) \
238 XFS_DIR2_DB_TO_DA(mp, XFS_DIR2_BYTE_TO_DB(mp, by))
242 * Convert byte in space to offset in a block
244 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_OFF)
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)
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)))
256 * Convert block and offset to dataptr
258 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_DATAPTR)
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)
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))
270 * Convert block (DB) to block (dablk)
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)
276 #define XFS_DIR2_DB_TO_DA(mp,db) \
277 ((xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog))
281 * Convert block (dablk) to block (DB)
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)
287 #define XFS_DIR2_DA_TO_DB(mp,da) \
288 ((xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog))
292 * Convert block (dablk) to byte offset in space
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)
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)
303 * Function declarations.
307 xfs_dir2_block_to_leaf(struct xfs_da_args
*args
, struct xfs_dabuf
*dbp
);
310 xfs_dir2_leaf_addname(struct xfs_da_args
*args
);
313 xfs_dir2_leaf_compact(struct xfs_da_args
*args
, struct xfs_dabuf
*bp
);
316 xfs_dir2_leaf_compact_x1(struct xfs_dabuf
*bp
, int *indexp
,
317 int *lowstalep
, int *highstalep
, int *lowlogp
,
321 xfs_dir2_leaf_getdents(struct xfs_trans
*tp
, struct xfs_inode
*dp
,
322 struct uio
*uio
, int *eofp
, struct xfs_dirent
*dbp
,
326 xfs_dir2_leaf_init(struct xfs_da_args
*args
, xfs_dir2_db_t bno
,
327 struct xfs_dabuf
**bpp
, int magic
);
330 xfs_dir2_leaf_log_ents(struct xfs_trans
*tp
, struct xfs_dabuf
*bp
,
331 int first
, int last
);
334 xfs_dir2_leaf_log_bests(struct xfs_trans
*tp
, struct xfs_dabuf
*bp
,
335 int first
, int last
);
338 xfs_dir2_leaf_log_header(struct xfs_trans
*tp
, struct xfs_dabuf
*bp
);
341 xfs_dir2_leaf_log_tail(struct xfs_trans
*tp
, struct xfs_dabuf
*bp
);
344 xfs_dir2_leaf_lookup(struct xfs_da_args
*args
);
347 xfs_dir2_leaf_removename(struct xfs_da_args
*args
);
350 xfs_dir2_leaf_replace(struct xfs_da_args
*args
);
353 xfs_dir2_leaf_search_hash(struct xfs_da_args
*args
,
354 struct xfs_dabuf
*lbp
);
356 xfs_dir2_leaf_trim_data(struct xfs_da_args
*args
, struct xfs_dabuf
*lbp
, xfs_dir2_db_t db
);
359 xfs_dir2_node_to_leaf(struct xfs_da_state
*state
);
361 #endif /* __XFS_DIR2_LEAF_H__ */