]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - include/xfs_ialloc_btree.h
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / include / xfs_ialloc_btree.h
CommitLineData
2bd0ea18 1/*
854f7c66 2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
5000d01d 3 *
2bd0ea18
NS
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.
5000d01d 7 *
2bd0ea18
NS
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.
5000d01d 11 *
2bd0ea18
NS
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
dfc130f3 14 * or the like. Any license provided herein, whether implied or
2bd0ea18
NS
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.
5000d01d 18 *
2bd0ea18
NS
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.
5000d01d 22 *
2bd0ea18
NS
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
5000d01d
SL
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
2bd0ea18
NS
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32#ifndef __XFS_IALLOC_BTREE_H__
dfc130f3 33#define __XFS_IALLOC_BTREE_H__
2bd0ea18
NS
34
35/*
36 * Inode map on-disk structures
37 */
38
39struct xfs_buf;
40struct xfs_btree_cur;
41struct xfs_btree_sblock;
42struct xfs_mount;
43
44/*
45 * There is a btree for the inode map per allocation group.
46 */
dfc130f3 47#define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
2bd0ea18 48
dfc130f3
RC
49typedef __uint64_t xfs_inofree_t;
50#define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
51#define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3)
52#define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1)
2bd0ea18
NS
53
54#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_MASKN)
55xfs_inofree_t xfs_inobt_maskn(int i, int n);
dfc130f3 56#define XFS_INOBT_MASKN(i,n) xfs_inobt_maskn(i,n)
2bd0ea18 57#else
dfc130f3 58#define XFS_INOBT_MASKN(i,n) \
2bd0ea18
NS
59 ((((n) >= XFS_INODES_PER_CHUNK ? \
60 (xfs_inofree_t)0 : ((xfs_inofree_t)1 << (n))) - 1) << (i))
61#endif
62
63/*
64 * Data record structure
65 */
66typedef struct xfs_inobt_rec
67{
68 xfs_agino_t ir_startino; /* starting inode number */
69 __int32_t ir_freecount; /* count of free inodes (set bits) */
70 xfs_inofree_t ir_free; /* free inode mask */
71} xfs_inobt_rec_t;
72
73/*
74 * Key structure
75 */
76typedef struct xfs_inobt_key
77{
78 xfs_agino_t ir_startino; /* starting inode number */
79} xfs_inobt_key_t;
80
81typedef xfs_agblock_t xfs_inobt_ptr_t; /* btree pointer type */
82 /* btree block header type */
dfc130f3 83typedef struct xfs_btree_sblock xfs_inobt_block_t;
2bd0ea18
NS
84
85#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_INOBT_BLOCK)
86xfs_inobt_block_t *xfs_buf_to_inobt_block(struct xfs_buf *bp);
dfc130f3 87#define XFS_BUF_TO_INOBT_BLOCK(bp) xfs_buf_to_inobt_block(bp)
2bd0ea18 88#else
dfc130f3 89#define XFS_BUF_TO_INOBT_BLOCK(bp) ((xfs_inobt_block_t *)(XFS_BUF_PTR(bp)))
2bd0ea18
NS
90#endif
91
92/*
93 * Bit manipulations for ir_free.
94 */
95#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_MASK)
96xfs_inofree_t xfs_inobt_mask(int i);
dfc130f3 97#define XFS_INOBT_MASK(i) xfs_inobt_mask(i)
2bd0ea18 98#else
dfc130f3 99#define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i))
2bd0ea18
NS
100#endif
101#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_IS_FREE)
102int xfs_inobt_is_free(xfs_inobt_rec_t *rp, int i, xfs_arch_t arch);
dfc130f3 103#define XFS_INOBT_IS_FREE(rp,i,arch) xfs_inobt_is_free(rp,i,arch)
2bd0ea18 104#else
dfc130f3 105#define XFS_INOBT_IS_FREE(rp,i,arch) ((INT_GET((rp)->ir_free, arch) \
5000d01d 106 & XFS_INOBT_MASK(i)) != 0)
2bd0ea18
NS
107#endif
108#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_SET_FREE)
109void xfs_inobt_set_free(xfs_inobt_rec_t *rp, int i, xfs_arch_t arch);
dfc130f3 110#define XFS_INOBT_SET_FREE(rp,i,arch) xfs_inobt_set_free(rp,i,arch)
2bd0ea18 111#else
dfc130f3 112#define XFS_INOBT_SET_FREE(rp,i,arch) (INT_MOD_EXPR((rp)->ir_free, arch, |= XFS_INOBT_MASK(i)))
2bd0ea18
NS
113#endif
114#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_CLR_FREE)
115void xfs_inobt_clr_free(xfs_inobt_rec_t *rp, int i, xfs_arch_t arch);
dfc130f3 116#define XFS_INOBT_CLR_FREE(rp,i,arch) xfs_inobt_clr_free(rp,i,arch)
2bd0ea18 117#else
dfc130f3 118#define XFS_INOBT_CLR_FREE(rp,i,arch) (INT_MOD_EXPR((rp)->ir_free, arch, &= ~XFS_INOBT_MASK(i)))
2bd0ea18
NS
119#endif
120
121/*
122 * Real block structures have a size equal to the disk block size.
123 */
124#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_SIZE)
125int xfs_inobt_block_size(int lev, struct xfs_btree_cur *cur);
dfc130f3 126#define XFS_INOBT_BLOCK_SIZE(lev,cur) xfs_inobt_block_size(lev,cur)
2bd0ea18 127#else
dfc130f3 128#define XFS_INOBT_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
2bd0ea18
NS
129#endif
130
131#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MAXRECS)
132int xfs_inobt_block_maxrecs(int lev, struct xfs_btree_cur *cur);
dfc130f3 133#define XFS_INOBT_BLOCK_MAXRECS(lev,cur) xfs_inobt_block_maxrecs(lev,cur)
2bd0ea18 134#else
dfc130f3 135#define XFS_INOBT_BLOCK_MAXRECS(lev,cur) \
2bd0ea18
NS
136 ((cur)->bc_mp->m_inobt_mxr[lev != 0])
137#endif
138#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MINRECS)
139int xfs_inobt_block_minrecs(int lev, struct xfs_btree_cur *cur);
dfc130f3 140#define XFS_INOBT_BLOCK_MINRECS(lev,cur) xfs_inobt_block_minrecs(lev,cur)
2bd0ea18 141#else
dfc130f3 142#define XFS_INOBT_BLOCK_MINRECS(lev,cur) \
2bd0ea18
NS
143 ((cur)->bc_mp->m_inobt_mnr[lev != 0])
144#endif
145
146#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_IS_LAST_REC)
147int xfs_inobt_is_last_rec(struct xfs_btree_cur *cur);
dfc130f3 148#define XFS_INOBT_IS_LAST_REC(cur) xfs_inobt_is_last_rec(cur)
2bd0ea18 149#else
dfc130f3 150#define XFS_INOBT_IS_LAST_REC(cur) \
2bd0ea18
NS
151 ((cur)->bc_ptrs[0] == \
152 INT_GET(XFS_BUF_TO_INOBT_BLOCK((cur)->bc_bufs[0])->bb_numrecs, ARCH_CONVERT))
153#endif
154
155/*
156 * Maximum number of inode btree levels.
157 */
158#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IN_MAXLEVELS)
159int xfs_in_maxlevels(struct xfs_mount *mp);
dfc130f3 160#define XFS_IN_MAXLEVELS(mp) xfs_in_maxlevels(mp)
2bd0ea18 161#else
dfc130f3 162#define XFS_IN_MAXLEVELS(mp) ((mp)->m_in_maxlevels)
2bd0ea18
NS
163#endif
164
165/*
166 * block numbers in the AG.
167 */
168#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IBT_BLOCK)
169xfs_agblock_t xfs_ibt_block(struct xfs_mount *mp);
dfc130f3 170#define XFS_IBT_BLOCK(mp) xfs_ibt_block(mp)
2bd0ea18 171#else
dfc130f3 172#define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
2bd0ea18
NS
173#endif
174#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_PREALLOC_BLOCKS)
175xfs_agblock_t xfs_prealloc_blocks(struct xfs_mount *mp);
dfc130f3 176#define XFS_PREALLOC_BLOCKS(mp) xfs_prealloc_blocks(mp)
2bd0ea18 177#else
dfc130f3 178#define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
2bd0ea18
NS
179#endif
180
181/*
182 * Record, key, and pointer address macros for btree blocks.
183 */
184#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_REC_ADDR)
185xfs_inobt_rec_t *
186xfs_inobt_rec_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
dfc130f3 187#define XFS_INOBT_REC_ADDR(bb,i,cur) xfs_inobt_rec_addr(bb,i,cur)
2bd0ea18 188#else
dfc130f3 189#define XFS_INOBT_REC_ADDR(bb,i,cur) \
2bd0ea18
NS
190 XFS_BTREE_REC_ADDR(XFS_INOBT_BLOCK_SIZE(0,cur), xfs_inobt, bb, i, \
191 XFS_INOBT_BLOCK_MAXRECS(0, cur))
192#endif
193
194#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_KEY_ADDR)
195xfs_inobt_key_t *
196xfs_inobt_key_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
dfc130f3 197#define XFS_INOBT_KEY_ADDR(bb,i,cur) xfs_inobt_key_addr(bb,i,cur)
2bd0ea18 198#else
dfc130f3 199#define XFS_INOBT_KEY_ADDR(bb,i,cur) \
2bd0ea18
NS
200 XFS_BTREE_KEY_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
201 XFS_INOBT_BLOCK_MAXRECS(1, cur))
202#endif
203
204#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_PTR_ADDR)
205xfs_inobt_ptr_t *
206xfs_inobt_ptr_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
dfc130f3 207#define XFS_INOBT_PTR_ADDR(bb,i,cur) xfs_inobt_ptr_addr(bb,i,cur)
2bd0ea18 208#else
dfc130f3 209#define XFS_INOBT_PTR_ADDR(bb,i,cur) \
2bd0ea18
NS
210 XFS_BTREE_PTR_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
211 XFS_INOBT_BLOCK_MAXRECS(1, cur))
212#endif
213
214/*
215 * Prototypes for externally visible routines.
216 */
217
218/*
219 * Decrement cursor by one record at the level.
220 * For nonzero levels the leaf-ward information is untouched.
221 */
222int /* error */
223xfs_inobt_decrement(
224 struct xfs_btree_cur *cur, /* btree cursor */
225 int level, /* level in btree, 0 is leaf */
226 int *stat); /* success/failure */
227
228#ifdef _NOTYET_
229/*
230 * Delete the record pointed to by cur.
231 * The cursor refers to the place where the record was (could be inserted)
232 * when the operation returns.
233 */
234int /* error */
235xfs_inobt_delete(
236 struct xfs_btree_cur *cur, /* btree cursor */
dfc130f3 237 int *stat); /* success/failure */
2bd0ea18
NS
238#endif /* _NOTYET_ */
239
240/*
241 * Get the data from the pointed-to record.
242 */
243int /* error */
244xfs_inobt_get_rec(
245 struct xfs_btree_cur *cur, /* btree cursor */
246 xfs_agino_t *ino, /* output: starting inode of chunk */
247 __int32_t *fcnt, /* output: number of free inodes */
248 xfs_inofree_t *free, /* output: free inode mask */
249 int *stat, /* output: success/failure */
250 xfs_arch_t arch); /* output: architecture */
251
252/*
253 * Increment cursor by one record at the level.
254 * For nonzero levels the leaf-ward information is untouched.
255 */
256int /* error */
257xfs_inobt_increment(
258 struct xfs_btree_cur *cur, /* btree cursor */
259 int level, /* level in btree, 0 is leaf */
dfc130f3 260 int *stat); /* success/failure */
2bd0ea18
NS
261
262/*
263 * Insert the current record at the point referenced by cur.
264 * The cursor may be inconsistent on return if splits have been done.
265 */
266int /* error */
267xfs_inobt_insert(
268 struct xfs_btree_cur *cur, /* btree cursor */
dfc130f3 269 int *stat); /* success/failure */
2bd0ea18
NS
270
271/*
272 * Lookup the record equal to ino in the btree given by cur.
273 */
274int /* error */
275xfs_inobt_lookup_eq(
276 struct xfs_btree_cur *cur, /* btree cursor */
277 xfs_agino_t ino, /* starting inode of chunk */
278 __int32_t fcnt, /* free inode count */
279 xfs_inofree_t free, /* free inode mask */
dfc130f3 280 int *stat); /* success/failure */
2bd0ea18
NS
281
282/*
283 * Lookup the first record greater than or equal to ino
284 * in the btree given by cur.
285 */
286int /* error */
287xfs_inobt_lookup_ge(
288 struct xfs_btree_cur *cur, /* btree cursor */
289 xfs_agino_t ino, /* starting inode of chunk */
290 __int32_t fcnt, /* free inode count */
291 xfs_inofree_t free, /* free inode mask */
dfc130f3 292 int *stat); /* success/failure */
2bd0ea18
NS
293
294/*
295 * Lookup the first record less than or equal to ino
296 * in the btree given by cur.
297 */
298int /* error */
299xfs_inobt_lookup_le(
300 struct xfs_btree_cur *cur, /* btree cursor */
301 xfs_agino_t ino, /* starting inode of chunk */
302 __int32_t fcnt, /* free inode count */
303 xfs_inofree_t free, /* free inode mask */
dfc130f3 304 int *stat); /* success/failure */
5000d01d 305
2bd0ea18
NS
306/*
307 * Update the record referred to by cur, to the value given
308 * by [ino, fcnt, free].
309 * This either works (return 0) or gets an EFSCORRUPTED error.
310 */
311int /* error */
312xfs_inobt_update(
313 struct xfs_btree_cur *cur, /* btree cursor */
314 xfs_agino_t ino, /* starting inode of chunk */
315 __int32_t fcnt, /* free inode count */
316 xfs_inofree_t free); /* free inode mask */
317
318#endif /* __XFS_IALLOC_BTREE_H__ */