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_ALLOC_BTREE_H__
33 #define __XFS_ALLOC_BTREE_H__
36 * Freespace on-disk structures
41 struct xfs_btree_sblock
;
45 * There are two on-disk btrees, one sorted by blockno and one sorted
46 * by blockcount and blockno. All blocks look the same to make the code
47 * simpler; if we have time later, we'll make the optimizations.
49 #define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
50 #define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
53 * Data record/key structure
55 typedef struct xfs_alloc_rec
57 xfs_agblock_t ar_startblock
; /* starting block number */
58 xfs_extlen_t ar_blockcount
; /* count of free blocks */
59 } xfs_alloc_rec_t
, xfs_alloc_key_t
;
61 typedef xfs_agblock_t xfs_alloc_ptr_t
; /* btree pointer type */
62 /* btree block header type */
63 typedef struct xfs_btree_sblock xfs_alloc_block_t
;
65 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_ALLOC_BLOCK)
66 xfs_alloc_block_t
*xfs_buf_to_alloc_block(struct xfs_buf
*bp
);
67 #define XFS_BUF_TO_ALLOC_BLOCK(bp) xfs_buf_to_alloc_block(bp)
69 #define XFS_BUF_TO_ALLOC_BLOCK(bp) ((xfs_alloc_block_t *)(XFS_BUF_PTR(bp)))
73 * Real block structures have a size equal to the disk block size.
76 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_BLOCK_SIZE)
77 int xfs_alloc_block_size(int lev
, struct xfs_btree_cur
*cur
);
78 #define XFS_ALLOC_BLOCK_SIZE(lev,cur) xfs_alloc_block_size(lev,cur)
80 #define XFS_ALLOC_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
83 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_BLOCK_MAXRECS)
84 int xfs_alloc_block_maxrecs(int lev
, struct xfs_btree_cur
*cur
);
85 #define XFS_ALLOC_BLOCK_MAXRECS(lev,cur) xfs_alloc_block_maxrecs(lev,cur)
87 #define XFS_ALLOC_BLOCK_MAXRECS(lev,cur) \
88 ((cur)->bc_mp->m_alloc_mxr[lev != 0])
90 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_BLOCK_MINRECS)
91 int xfs_alloc_block_minrecs(int lev
, struct xfs_btree_cur
*cur
);
92 #define XFS_ALLOC_BLOCK_MINRECS(lev,cur) xfs_alloc_block_minrecs(lev,cur)
94 #define XFS_ALLOC_BLOCK_MINRECS(lev,cur) \
95 ((cur)->bc_mp->m_alloc_mnr[lev != 0])
99 * Minimum and maximum blocksize and sectorsize.
100 * The blocksize upper limit is pretty much arbitrary.
101 * The sectorsize upper limit is due to sizeof(sb_sectsize).
103 #define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
104 #define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
105 #define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
106 #define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
107 #define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
108 #define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
109 #define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
110 #define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
113 * Block numbers in the AG:
114 * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
116 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BNO_BLOCK)
117 xfs_agblock_t
xfs_bno_block(struct xfs_mount
*mp
);
118 #define XFS_BNO_BLOCK(mp) xfs_bno_block(mp)
120 #define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
122 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CNT_BLOCK)
123 xfs_agblock_t
xfs_cnt_block(struct xfs_mount
*mp
);
124 #define XFS_CNT_BLOCK(mp) xfs_cnt_block(mp)
126 #define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
130 * Record, key, and pointer address macros for btree blocks.
132 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_REC_ADDR)
133 xfs_alloc_rec_t
*xfs_alloc_rec_addr(xfs_alloc_block_t
*bb
, int i
,
134 struct xfs_btree_cur
*cur
);
135 #define XFS_ALLOC_REC_ADDR(bb,i,cur) xfs_alloc_rec_addr(bb,i,cur)
137 #define XFS_ALLOC_REC_ADDR(bb,i,cur) \
138 XFS_BTREE_REC_ADDR(XFS_ALLOC_BLOCK_SIZE(0,cur), xfs_alloc, bb, i, \
139 XFS_ALLOC_BLOCK_MAXRECS(0, cur))
142 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_KEY_ADDR)
143 xfs_alloc_key_t
*xfs_alloc_key_addr(xfs_alloc_block_t
*bb
, int i
,
144 struct xfs_btree_cur
*cur
);
145 #define XFS_ALLOC_KEY_ADDR(bb,i,cur) xfs_alloc_key_addr(bb,i,cur)
147 #define XFS_ALLOC_KEY_ADDR(bb,i,cur) \
148 XFS_BTREE_KEY_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, bb, i, \
149 XFS_ALLOC_BLOCK_MAXRECS(1, cur))
152 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_PTR_ADDR)
153 xfs_alloc_ptr_t
*xfs_alloc_ptr_addr(xfs_alloc_block_t
*bb
, int i
,
154 struct xfs_btree_cur
*cur
);
155 #define XFS_ALLOC_PTR_ADDR(bb,i,cur) xfs_alloc_ptr_addr(bb,i,cur)
157 #define XFS_ALLOC_PTR_ADDR(bb,i,cur) \
158 XFS_BTREE_PTR_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, bb, i, \
159 XFS_ALLOC_BLOCK_MAXRECS(1, cur))
163 * Prototypes for externally visible routines.
167 * Decrement cursor by one record at the level.
168 * For nonzero levels the leaf-ward information is untouched.
172 struct xfs_btree_cur
*cur
, /* btree cursor */
173 int level
, /* level in btree, 0 is leaf */
174 int *stat
); /* success/failure */
177 * Delete the record pointed to by cur.
178 * The cursor refers to the place where the record was (could be inserted)
179 * when the operation returns.
183 struct xfs_btree_cur
*cur
, /* btree cursor */
184 int *stat
); /* success/failure */
187 * Get the data from the pointed-to record.
191 struct xfs_btree_cur
*cur
, /* btree cursor */
192 xfs_agblock_t
*bno
, /* output: starting block of extent */
193 xfs_extlen_t
*len
, /* output: length of extent */
194 int *stat
); /* output: success/failure */
197 * Increment cursor by one record at the level.
198 * For nonzero levels the leaf-ward information is untouched.
202 struct xfs_btree_cur
*cur
, /* btree cursor */
203 int level
, /* level in btree, 0 is leaf */
204 int *stat
); /* success/failure */
207 * Insert the current record at the point referenced by cur.
208 * The cursor may be inconsistent on return if splits have been done.
212 struct xfs_btree_cur
*cur
, /* btree cursor */
213 int *stat
); /* success/failure */
216 * Lookup the record equal to [bno, len] in the btree given by cur.
220 struct xfs_btree_cur
*cur
, /* btree cursor */
221 xfs_agblock_t bno
, /* starting block of extent */
222 xfs_extlen_t len
, /* length of extent */
223 int *stat
); /* success/failure */
226 * Lookup the first record greater than or equal to [bno, len]
227 * in the btree given by cur.
231 struct xfs_btree_cur
*cur
, /* btree cursor */
232 xfs_agblock_t bno
, /* starting block of extent */
233 xfs_extlen_t len
, /* length of extent */
234 int *stat
); /* success/failure */
237 * Lookup the first record less than or equal to [bno, len]
238 * in the btree given by cur.
242 struct xfs_btree_cur
*cur
, /* btree cursor */
243 xfs_agblock_t bno
, /* starting block of extent */
244 xfs_extlen_t len
, /* length of extent */
245 int *stat
); /* success/failure */
248 * Update the record referred to by cur, to the value given by [bno, len].
249 * This either works (return 0) or gets an EFSCORRUPTED error.
253 struct xfs_btree_cur
*cur
, /* btree cursor */
254 xfs_agblock_t bno
, /* starting block of extent */
255 xfs_extlen_t len
); /* length of extent */
257 #endif /* __XFS_ALLOC_BTREE_H__ */