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_IALLOC_BTREE_H__
33 #define __XFS_IALLOC_BTREE_H__
36 * Inode map on-disk structures
41 struct xfs_btree_sblock
;
45 * There is a btree for the inode map per allocation group.
47 #define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
49 typedef __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)
54 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_MASKN)
55 xfs_inofree_t
xfs_inobt_maskn(int i
, int n
);
56 #define XFS_INOBT_MASKN(i,n) xfs_inobt_maskn(i,n)
58 #define XFS_INOBT_MASKN(i,n) \
59 ((((n) >= XFS_INODES_PER_CHUNK ? \
60 (xfs_inofree_t)0 : ((xfs_inofree_t)1 << (n))) - 1) << (i))
64 * Data record structure
66 typedef struct xfs_inobt_rec
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 */
76 typedef struct xfs_inobt_key
78 xfs_agino_t ir_startino
; /* starting inode number */
81 typedef xfs_agblock_t xfs_inobt_ptr_t
; /* btree pointer type */
82 /* btree block header type */
83 typedef struct xfs_btree_sblock xfs_inobt_block_t
;
85 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_INOBT_BLOCK)
86 xfs_inobt_block_t
*xfs_buf_to_inobt_block(struct xfs_buf
*bp
);
87 #define XFS_BUF_TO_INOBT_BLOCK(bp) xfs_buf_to_inobt_block(bp)
89 #define XFS_BUF_TO_INOBT_BLOCK(bp) ((xfs_inobt_block_t *)(XFS_BUF_PTR(bp)))
93 * Bit manipulations for ir_free.
95 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_MASK)
96 xfs_inofree_t
xfs_inobt_mask(int i
);
97 #define XFS_INOBT_MASK(i) xfs_inobt_mask(i)
99 #define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i))
101 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_IS_FREE)
102 int xfs_inobt_is_free(xfs_inobt_rec_t
*rp
, int i
);
103 #define XFS_INOBT_IS_FREE(rp,i) xfs_inobt_is_free(rp,i)
104 #define XFS_INOBT_IS_FREE_DISK(rp,i) xfs_inobt_is_free_disk(rp,i)
106 #define XFS_INOBT_IS_FREE(rp,i) \
107 (((rp)->ir_free & XFS_INOBT_MASK(i)) != 0)
108 #define XFS_INOBT_IS_FREE_DISK(rp,i) \
109 ((INT_GET((rp)->ir_free, ARCH_CONVERT) & XFS_INOBT_MASK(i)) != 0)
111 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_SET_FREE)
112 void xfs_inobt_set_free(xfs_inobt_rec_t
*rp
, int i
);
113 #define XFS_INOBT_SET_FREE(rp,i) xfs_inobt_set_free(rp,i)
115 #define XFS_INOBT_SET_FREE(rp,i) ((rp)->ir_free |= XFS_INOBT_MASK(i))
117 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_CLR_FREE)
118 void xfs_inobt_clr_free(xfs_inobt_rec_t
*rp
, int i
);
119 #define XFS_INOBT_CLR_FREE(rp,i) xfs_inobt_clr_free(rp,i)
121 #define XFS_INOBT_CLR_FREE(rp,i) ((rp)->ir_free &= ~XFS_INOBT_MASK(i))
125 * Real block structures have a size equal to the disk block size.
127 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_SIZE)
128 int xfs_inobt_block_size(int lev
, struct xfs_btree_cur
*cur
);
129 #define XFS_INOBT_BLOCK_SIZE(lev,cur) xfs_inobt_block_size(lev,cur)
131 #define XFS_INOBT_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
134 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MAXRECS)
135 int xfs_inobt_block_maxrecs(int lev
, struct xfs_btree_cur
*cur
);
136 #define XFS_INOBT_BLOCK_MAXRECS(lev,cur) xfs_inobt_block_maxrecs(lev,cur)
138 #define XFS_INOBT_BLOCK_MAXRECS(lev,cur) \
139 ((cur)->bc_mp->m_inobt_mxr[lev != 0])
141 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MINRECS)
142 int xfs_inobt_block_minrecs(int lev
, struct xfs_btree_cur
*cur
);
143 #define XFS_INOBT_BLOCK_MINRECS(lev,cur) xfs_inobt_block_minrecs(lev,cur)
145 #define XFS_INOBT_BLOCK_MINRECS(lev,cur) \
146 ((cur)->bc_mp->m_inobt_mnr[lev != 0])
149 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_IS_LAST_REC)
150 int xfs_inobt_is_last_rec(struct xfs_btree_cur
*cur
);
151 #define XFS_INOBT_IS_LAST_REC(cur) xfs_inobt_is_last_rec(cur)
153 #define XFS_INOBT_IS_LAST_REC(cur) \
154 ((cur)->bc_ptrs[0] == \
155 INT_GET(XFS_BUF_TO_INOBT_BLOCK((cur)->bc_bufs[0])->bb_numrecs, ARCH_CONVERT))
159 * Maximum number of inode btree levels.
161 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IN_MAXLEVELS)
162 int xfs_in_maxlevels(struct xfs_mount
*mp
);
163 #define XFS_IN_MAXLEVELS(mp) xfs_in_maxlevels(mp)
165 #define XFS_IN_MAXLEVELS(mp) ((mp)->m_in_maxlevels)
169 * block numbers in the AG.
171 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IBT_BLOCK)
172 xfs_agblock_t
xfs_ibt_block(struct xfs_mount
*mp
);
173 #define XFS_IBT_BLOCK(mp) xfs_ibt_block(mp)
175 #define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
177 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_PREALLOC_BLOCKS)
178 xfs_agblock_t
xfs_prealloc_blocks(struct xfs_mount
*mp
);
179 #define XFS_PREALLOC_BLOCKS(mp) xfs_prealloc_blocks(mp)
181 #define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
185 * Record, key, and pointer address macros for btree blocks.
187 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_REC_ADDR)
189 xfs_inobt_rec_addr(xfs_inobt_block_t
*bb
, int i
, struct xfs_btree_cur
*cur
);
190 #define XFS_INOBT_REC_ADDR(bb,i,cur) xfs_inobt_rec_addr(bb,i,cur)
192 #define XFS_INOBT_REC_ADDR(bb,i,cur) \
193 XFS_BTREE_REC_ADDR(XFS_INOBT_BLOCK_SIZE(0,cur), xfs_inobt, bb, i, \
194 XFS_INOBT_BLOCK_MAXRECS(0, cur))
197 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_KEY_ADDR)
199 xfs_inobt_key_addr(xfs_inobt_block_t
*bb
, int i
, struct xfs_btree_cur
*cur
);
200 #define XFS_INOBT_KEY_ADDR(bb,i,cur) xfs_inobt_key_addr(bb,i,cur)
202 #define XFS_INOBT_KEY_ADDR(bb,i,cur) \
203 XFS_BTREE_KEY_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
204 XFS_INOBT_BLOCK_MAXRECS(1, cur))
207 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_PTR_ADDR)
209 xfs_inobt_ptr_addr(xfs_inobt_block_t
*bb
, int i
, struct xfs_btree_cur
*cur
);
210 #define XFS_INOBT_PTR_ADDR(bb,i,cur) xfs_inobt_ptr_addr(bb,i,cur)
212 #define XFS_INOBT_PTR_ADDR(bb,i,cur) \
213 XFS_BTREE_PTR_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
214 XFS_INOBT_BLOCK_MAXRECS(1, cur))
218 * Prototypes for externally visible routines.
222 * Decrement cursor by one record at the level.
223 * For nonzero levels the leaf-ward information is untouched.
227 struct xfs_btree_cur
*cur
, /* btree cursor */
228 int level
, /* level in btree, 0 is leaf */
229 int *stat
); /* success/failure */
232 * Delete the record pointed to by cur.
233 * The cursor refers to the place where the record was (could be inserted)
234 * when the operation returns.
238 struct xfs_btree_cur
*cur
, /* btree cursor */
239 int *stat
); /* success/failure */
242 * Get the data from the pointed-to record.
246 struct xfs_btree_cur
*cur
, /* btree cursor */
247 xfs_agino_t
*ino
, /* output: starting inode of chunk */
248 __int32_t
*fcnt
, /* output: number of free inodes */
249 xfs_inofree_t
*free
, /* output: free inode mask */
250 int *stat
); /* output: success/failure */
253 * Increment cursor by one record at the level.
254 * For nonzero levels the leaf-ward information is untouched.
258 struct xfs_btree_cur
*cur
, /* btree cursor */
259 int level
, /* level in btree, 0 is leaf */
260 int *stat
); /* success/failure */
263 * Insert the current record at the point referenced by cur.
264 * The cursor may be inconsistent on return if splits have been done.
268 struct xfs_btree_cur
*cur
, /* btree cursor */
269 int *stat
); /* success/failure */
272 * Lookup the record equal to ino in the btree given by cur.
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 */
280 int *stat
); /* success/failure */
283 * Lookup the first record greater than or equal to ino
284 * in the btree given by cur.
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 */
292 int *stat
); /* success/failure */
295 * Lookup the first record less than or equal to ino
296 * in the btree given by cur.
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 */
304 int *stat
); /* success/failure */
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.
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 */
318 #endif /* __XFS_IALLOC_BTREE_H__ */