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.
47 * Offset of the leaf/node space. First block in this space
50 #define XFS_DIR2_LEAF_SPACE 1
51 #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
52 #define XFS_DIR2_LEAF_FIRSTDB(mp) \
53 XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_LEAF_OFFSET)
56 * Offset in data space of a data entry.
58 typedef __uint32_t xfs_dir2_dataptr_t;
59 #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
60 #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
65 typedef struct xfs_dir2_leaf_hdr {
66 xfs_da_blkinfo_t info; /* header for da routines */
67 __uint16_t count; /* count of entries */
68 __uint16_t stale; /* count of stale entries */
69 } xfs_dir2_leaf_hdr_t;
74 typedef struct xfs_dir2_leaf_entry {
75 xfs_dahash_t hashval; /* hash value of name */
76 xfs_dir2_dataptr_t address; /* address of data entry */
77 } xfs_dir2_leaf_entry_t;
82 typedef struct xfs_dir2_leaf_tail {
84 } xfs_dir2_leaf_tail_t;
88 * bests and tail are at the end of the block for single-leaf only
89 * (magic = XFS_DIR2_LEAF1_MAGIC not XFS_DIR2_LEAFN_MAGIC).
91 typedef struct xfs_dir2_leaf {
92 xfs_dir2_leaf_hdr_t hdr; /* leaf header */
93 xfs_dir2_leaf_entry_t ents[1]; /* entries */
95 xfs_dir2_data_off_t bests[1]; /* best free counts */
96 xfs_dir2_leaf_tail_t tail; /* leaf tail */
100 * DB blocks here are logical directory block numbers, not filesystem blocks.
103 #define XFS_DIR2_MAX_LEAF_ENTS(mp) xfs_dir2_max_leaf_ents(mp)
104 static inline int xfs_dir2_max_leaf_ents(struct xfs_mount *mp)
106 return (int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) /
107 (uint)sizeof(xfs_dir2_leaf_entry_t));
111 * Get address of the bestcount field in the single-leaf block.
113 #define XFS_DIR2_LEAF_TAIL_P(mp,lp) xfs_dir2_leaf_tail_p(mp, lp)
114 static inline xfs_dir2_leaf_tail_t *
115 xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp)
117 return (xfs_dir2_leaf_tail_t *)
118 ((char *)(lp) + (mp)->m_dirblksize -
119 (uint)sizeof(xfs_dir2_leaf_tail_t));
123 * Get address of the bests array in the single-leaf block.
125 #define XFS_DIR2_LEAF_BESTS_P(ltp) xfs_dir2_leaf_bests_p(ltp)
126 static inline xfs_dir2_data_off_t *
127 xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t *ltp)
129 return (xfs_dir2_data_off_t *)
130 (ltp) - INT_GET((ltp)->bestcount, ARCH_CONVERT);
134 * Convert dataptr to byte in file space
136 #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) xfs_dir2_dataptr_to_byte(mp, dp)
137 static inline xfs_dir2_off_t
138 xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
140 return (xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG;
144 * Convert byte in file space to dataptr. It had better be aligned.
146 #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) xfs_dir2_byte_to_dataptr(mp,by)
147 static inline xfs_dir2_dataptr_t
148 xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by)
150 return (xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG);
154 * Convert byte in space to (DB) block
156 #define XFS_DIR2_BYTE_TO_DB(mp,by) xfs_dir2_byte_to_db(mp, by)
157 static inline xfs_dir2_db_t
158 xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by)
160 return (xfs_dir2_db_t)((by) >> \
161 ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog));
165 * Convert dataptr to a block number
167 #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) xfs_dir2_dataptr_to_db(mp, dp)
168 static inline xfs_dir2_db_t
169 xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
171 return XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp));
175 * Convert byte in space to offset in a block
177 #define XFS_DIR2_BYTE_TO_OFF(mp,by) xfs_dir2_byte_to_off(mp, by)
178 static inline xfs_dir2_data_aoff_t
179 xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by)
181 return (xfs_dir2_data_aoff_t)((by) & \
182 ((1 << ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) - 1));
186 * Convert dataptr to a byte offset in a block
188 #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) xfs_dir2_dataptr_to_off(mp, dp)
189 static inline xfs_dir2_data_aoff_t
190 xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
192 return XFS_DIR2_BYTE_TO_OFF(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp));
196 * Convert block and offset to byte in space
198 #define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
199 xfs_dir2_db_off_to_byte(mp, db, o)
200 static inline xfs_dir2_off_t
201 xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db,
202 xfs_dir2_data_aoff_t o)
204 return ((xfs_dir2_off_t)(db) << \
205 ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o);
209 * Convert block (DB) to block (dablk)
211 #define XFS_DIR2_DB_TO_DA(mp,db) xfs_dir2_db_to_da(mp, db)
212 static inline xfs_dablk_t
213 xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db)
215 return (xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog);
219 * Convert byte in space to (DA) block
221 #define XFS_DIR2_BYTE_TO_DA(mp,by) xfs_dir2_byte_to_da(mp, by)
222 static inline xfs_dablk_t
223 xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by)
225 return XFS_DIR2_DB_TO_DA(mp, XFS_DIR2_BYTE_TO_DB(mp, by));
229 * Convert block and offset to dataptr
231 #define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
232 xfs_dir2_db_off_to_dataptr(mp, db, o)
233 static inline xfs_dir2_dataptr_t
234 xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db,
235 xfs_dir2_data_aoff_t o)
237 return XFS_DIR2_BYTE_TO_DATAPTR(mp, XFS_DIR2_DB_OFF_TO_BYTE(mp, db, o));
241 * Convert block (dablk) to block (DB)
243 #define XFS_DIR2_DA_TO_DB(mp,da) xfs_dir2_da_to_db(mp, da)
244 static inline xfs_dir2_db_t
245 xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da)
247 return (xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog);
251 * Convert block (dablk) to byte offset in space
253 #define XFS_DIR2_DA_TO_BYTE(mp,da) xfs_dir2_da_to_byte(mp, da)
254 static inline xfs_dir2_off_t
255 xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da)
257 return XFS_DIR2_DB_OFF_TO_BYTE(mp, XFS_DIR2_DA_TO_DB(mp, da), 0);
261 * Function declarations.
263 extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args,
264 struct xfs_dabuf *dbp);
265 extern int xfs_dir2_leaf_addname(struct xfs_da_args *args);
266 extern void xfs_dir2_leaf_compact(struct xfs_da_args *args,
267 struct xfs_dabuf *bp);
268 extern void xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp,
269 int *lowstalep, int *highstalep,
270 int *lowlogp, int *highlogp);
271 extern int xfs_dir2_leaf_getdents(struct xfs_trans *tp, struct xfs_inode *dp,
272 struct uio *uio, int *eofp,
273 struct xfs_dirent *dbp, xfs_dir2_put_t put);
274 extern int xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno,
275 struct xfs_dabuf **bpp, int magic);
276 extern void xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp,
277 int first, int last);
278 extern void xfs_dir2_leaf_log_header(struct xfs_trans *tp,
279 struct xfs_dabuf *bp);
280 extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
281 extern int xfs_dir2_leaf_removename(struct xfs_da_args *args);
282 extern int xfs_dir2_leaf_replace(struct xfs_da_args *args);
283 extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
284 struct xfs_dabuf *lbp);
285 extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args,
286 struct xfs_dabuf *lbp, xfs_dir2_db_t db);
287 extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state);
289 #endif /* __XFS_DIR2_LEAF_H__ */