]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/xfs/xfs_dir2_leaf.h
xfs: cleanup struct xfs_dir2_leaf
[mirror_ubuntu-artful-kernel.git] / fs / xfs / xfs_dir2_leaf.h
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
1da177e4 13 *
7b718769
NS
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1da177e4
LT
17 */
18#ifndef __XFS_DIR2_LEAF_H__
19#define __XFS_DIR2_LEAF_H__
20
2282396d
CH
21/*
22 * Directory format 2, leaf block structures.
23 *
24 * A pure data block looks like the following drawing on disk:
25 *
26 * +---------------------------+
27 * | xfs_dir2_leaf_hdr_t |
28 * +---------------------------+
29 * | xfs_dir2_leaf_entry_t |
30 * | xfs_dir2_leaf_entry_t |
31 * | xfs_dir2_leaf_entry_t |
32 * | xfs_dir2_leaf_entry_t |
33 * | ... |
34 * +---------------------------+
35 * | xfs_dir2_data_off_t |
36 * | xfs_dir2_data_off_t |
37 * | xfs_dir2_data_off_t |
38 * | ... |
39 * +---------------------------+
40 * | xfs_dir2_leaf_tail_t |
41 * +---------------------------+
42 *
43 * The bests (xfs_dir2_data_off_t members) and tail are at the end of the
44 * block for single-leaf only (magic = XFS_DIR2_LEAF1_MAGIC not
45 * XFS_DIR2_LEAFN_MAGIC).
46 *
47 * As all the entries are variable size structures the accessors in this
48 * file should be used to iterate over them.
49 */
50
1da177e4
LT
51struct uio;
52struct xfs_dabuf;
53struct xfs_da_args;
54struct xfs_inode;
55struct xfs_mount;
56struct xfs_trans;
57
1da177e4
LT
58/*
59 * Offset of the leaf/node space. First block in this space
60 * is the btree root.
61 */
62#define XFS_DIR2_LEAF_SPACE 1
63#define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
64#define XFS_DIR2_LEAF_FIRSTDB(mp) \
bbaaf538 65 xfs_dir2_byte_to_db(mp, XFS_DIR2_LEAF_OFFSET)
1da177e4 66
1da177e4
LT
67/*
68 * Offset in data space of a data entry.
69 */
70typedef __uint32_t xfs_dir2_dataptr_t;
71#define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
72#define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
73
1da177e4
LT
74/*
75 * Leaf block header.
76 */
77typedef struct xfs_dir2_leaf_hdr {
78 xfs_da_blkinfo_t info; /* header for da routines */
a818e5de
NS
79 __be16 count; /* count of entries */
80 __be16 stale; /* count of stale entries */
1da177e4
LT
81} xfs_dir2_leaf_hdr_t;
82
83/*
84 * Leaf block entry.
85 */
86typedef struct xfs_dir2_leaf_entry {
3c1f9c15
NS
87 __be32 hashval; /* hash value of name */
88 __be32 address; /* address of data entry */
1da177e4
LT
89} xfs_dir2_leaf_entry_t;
90
91/*
92 * Leaf block tail.
93 */
94typedef struct xfs_dir2_leaf_tail {
afbcb3f9 95 __be32 bestcount;
1da177e4
LT
96} xfs_dir2_leaf_tail_t;
97
98/*
99 * Leaf block.
1da177e4
LT
100 */
101typedef struct xfs_dir2_leaf {
102 xfs_dir2_leaf_hdr_t hdr; /* leaf header */
2282396d 103 xfs_dir2_leaf_entry_t ents[]; /* entries */
1da177e4
LT
104} xfs_dir2_leaf_t;
105
106/*
a844f451 107 * DB blocks here are logical directory block numbers, not filesystem blocks.
1da177e4
LT
108 */
109
a844f451
NS
110static inline int xfs_dir2_max_leaf_ents(struct xfs_mount *mp)
111{
112 return (int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) /
113 (uint)sizeof(xfs_dir2_leaf_entry_t));
114}
1da177e4
LT
115
116/*
117 * Get address of the bestcount field in the single-leaf block.
118 */
a844f451
NS
119static inline xfs_dir2_leaf_tail_t *
120xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp)
121{
122 return (xfs_dir2_leaf_tail_t *)
123 ((char *)(lp) + (mp)->m_dirblksize -
124 (uint)sizeof(xfs_dir2_leaf_tail_t));
125}
1da177e4
LT
126
127/*
128 * Get address of the bests array in the single-leaf block.
129 */
68b3a102 130static inline __be16 *
a844f451
NS
131xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t *ltp)
132{
afbcb3f9 133 return (__be16 *)ltp - be32_to_cpu(ltp->bestcount);
a844f451 134}
1da177e4
LT
135
136/*
137 * Convert dataptr to byte in file space
138 */
a844f451
NS
139static inline xfs_dir2_off_t
140xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
141{
142 return (xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG;
143}
1da177e4
LT
144
145/*
146 * Convert byte in file space to dataptr. It had better be aligned.
147 */
a844f451
NS
148static inline xfs_dir2_dataptr_t
149xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by)
150{
151 return (xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG);
152}
153
154/*
155 * Convert byte in space to (DB) block
156 */
a844f451
NS
157static inline xfs_dir2_db_t
158xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by)
159{
160 return (xfs_dir2_db_t)((by) >> \
161 ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog));
162}
1da177e4
LT
163
164/*
165 * Convert dataptr to a block number
166 */
a844f451
NS
167static inline xfs_dir2_db_t
168xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
169{
bbaaf538 170 return xfs_dir2_byte_to_db(mp, xfs_dir2_dataptr_to_byte(mp, dp));
a844f451
NS
171}
172
173/*
174 * Convert byte in space to offset in a block
175 */
a844f451
NS
176static inline xfs_dir2_data_aoff_t
177xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by)
178{
179 return (xfs_dir2_data_aoff_t)((by) & \
180 ((1 << ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) - 1));
181}
1da177e4
LT
182
183/*
184 * Convert dataptr to a byte offset in a block
185 */
a844f451
NS
186static inline xfs_dir2_data_aoff_t
187xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
188{
bbaaf538 189 return xfs_dir2_byte_to_off(mp, xfs_dir2_dataptr_to_byte(mp, dp));
a844f451 190}
1da177e4
LT
191
192/*
193 * Convert block and offset to byte in space
194 */
a844f451
NS
195static inline xfs_dir2_off_t
196xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db,
197 xfs_dir2_data_aoff_t o)
198{
199 return ((xfs_dir2_off_t)(db) << \
200 ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o);
201}
1da177e4
LT
202
203/*
a844f451 204 * Convert block (DB) to block (dablk)
1da177e4 205 */
a844f451
NS
206static inline xfs_dablk_t
207xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db)
208{
209 return (xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog);
210}
1da177e4
LT
211
212/*
213 * Convert byte in space to (DA) block
214 */
a844f451
NS
215static inline xfs_dablk_t
216xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by)
217{
bbaaf538 218 return xfs_dir2_db_to_da(mp, xfs_dir2_byte_to_db(mp, by));
a844f451 219}
1da177e4
LT
220
221/*
222 * Convert block and offset to dataptr
223 */
a844f451
NS
224static inline xfs_dir2_dataptr_t
225xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db,
226 xfs_dir2_data_aoff_t o)
227{
bbaaf538 228 return xfs_dir2_byte_to_dataptr(mp, xfs_dir2_db_off_to_byte(mp, db, o));
a844f451 229}
1da177e4
LT
230
231/*
232 * Convert block (dablk) to block (DB)
233 */
a844f451
NS
234static inline xfs_dir2_db_t
235xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da)
236{
237 return (xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog);
238}
1da177e4
LT
239
240/*
241 * Convert block (dablk) to byte offset in space
242 */
a844f451
NS
243static inline xfs_dir2_off_t
244xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da)
245{
bbaaf538 246 return xfs_dir2_db_off_to_byte(mp, xfs_dir2_da_to_db(mp, da), 0);
a844f451 247}
1da177e4
LT
248
249/*
250 * Function declarations.
251 */
a844f451
NS
252extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args,
253 struct xfs_dabuf *dbp);
254extern int xfs_dir2_leaf_addname(struct xfs_da_args *args);
255extern void xfs_dir2_leaf_compact(struct xfs_da_args *args,
256 struct xfs_dabuf *bp);
257extern void xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp,
258 int *lowstalep, int *highstalep,
259 int *lowlogp, int *highlogp);
051e7cd4
CH
260extern int xfs_dir2_leaf_getdents(struct xfs_inode *dp, void *dirent,
261 size_t bufsize, xfs_off_t *offset,
262 filldir_t filldir);
a844f451
NS
263extern int xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno,
264 struct xfs_dabuf **bpp, int magic);
265extern void xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp,
266 int first, int last);
267extern void xfs_dir2_leaf_log_header(struct xfs_trans *tp,
268 struct xfs_dabuf *bp);
269extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
270extern int xfs_dir2_leaf_removename(struct xfs_da_args *args);
271extern int xfs_dir2_leaf_replace(struct xfs_da_args *args);
272extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
273 struct xfs_dabuf *lbp);
274extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args,
275 struct xfs_dabuf *lbp, xfs_dir2_db_t db);
4fb44c82
CH
276extern xfs_dir2_leaf_entry_t *xfs_dir2_leaf_find_entry(xfs_dir2_leaf_t *, int,
277 int, int, int,
278 int *, int *);
a844f451 279extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state);
1da177e4
LT
280
281#endif /* __XFS_DIR2_LEAF_H__ */