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_BTREE_H__
33 #define __XFS_BTREE_H__
42 * This nonsense is to make -wlint happy.
44 #define XFS_LOOKUP_EQ ((xfs_lookup_t)XFS_LOOKUP_EQi)
45 #define XFS_LOOKUP_LE ((xfs_lookup_t)XFS_LOOKUP_LEi)
46 #define XFS_LOOKUP_GE ((xfs_lookup_t)XFS_LOOKUP_GEi)
48 #define XFS_BTNUM_BNO ((xfs_btnum_t)XFS_BTNUM_BNOi)
49 #define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi)
50 #define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi)
51 #define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi)
54 * Short form header: space allocation btrees.
56 typedef struct xfs_btree_sblock
58 __uint32_t bb_magic; /* magic number for block type */
59 __uint16_t bb_level; /* 0 is a leaf */
60 __uint16_t bb_numrecs; /* current # of data records */
61 xfs_agblock_t bb_leftsib; /* left sibling block or NULLAGBLOCK */
62 xfs_agblock_t bb_rightsib; /* right sibling block or NULLAGBLOCK */
66 * Long form header: bmap btrees.
68 typedef struct xfs_btree_lblock
70 __uint32_t bb_magic; /* magic number for block type */
71 __uint16_t bb_level; /* 0 is a leaf */
72 __uint16_t bb_numrecs; /* current # of data records */
73 xfs_dfsbno_t bb_leftsib; /* left sibling block or NULLDFSBNO */
74 xfs_dfsbno_t bb_rightsib; /* right sibling block or NULLDFSBNO */
78 * Combined header and structure, used by common code.
80 typedef struct xfs_btree_hdr
82 __uint32_t bb_magic; /* magic number for block type */
83 __uint16_t bb_level; /* 0 is a leaf */
84 __uint16_t bb_numrecs; /* current # of data records */
87 typedef struct xfs_btree_block
89 xfs_btree_hdr_t bb_h; /* header */
92 xfs_agblock_t bb_leftsib;
93 xfs_agblock_t bb_rightsib;
94 } s; /* short form pointers */
96 xfs_dfsbno_t bb_leftsib;
97 xfs_dfsbno_t bb_rightsib;
98 } l; /* long form pointers */
103 * For logging record fields.
105 #define XFS_BB_MAGIC 0x01
106 #define XFS_BB_LEVEL 0x02
107 #define XFS_BB_NUMRECS 0x04
108 #define XFS_BB_LEFTSIB 0x08
109 #define XFS_BB_RIGHTSIB 0x10
110 #define XFS_BB_NUM_BITS 5
111 #define XFS_BB_ALL_BITS ((1 << XFS_BB_NUM_BITS) - 1)
114 * Boolean to select which form of xfs_btree_block_t.bb_u to use.
116 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_BTREE_LONG_PTRS)
117 int xfs_btree_long_ptrs(xfs_btnum_t btnum);
120 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BTREE_LONG_PTRS)
121 #define XFS_BTREE_LONG_PTRS(btnum) ((btnum) == XFS_BTNUM_BMAP)
123 #define XFS_BTREE_LONG_PTRS(btnum) ((btnum) == XFS_BTNUM_BMAP)
127 * Magic numbers for btree blocks.
129 extern const __uint32_t xfs_magics[];
132 * Maximum and minimum records in a btree block.
133 * Given block size, type prefix, and leaf flag (0 or 1).
134 * The divisor below is equivalent to lf ? (e1) : (e2) but that produces
137 #define XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf) \
138 ((int)(((bsz) - (uint)sizeof(t ## _block_t)) / \
139 (((lf) * (uint)sizeof(t ## _rec_t)) + \
141 ((uint)sizeof(t ## _key_t) + (uint)sizeof(t ## _ptr_t))))))
142 #define XFS_BTREE_BLOCK_MINRECS(bsz,t,lf) \
143 (XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf) / 2)
146 * Record, key, and pointer address calculation macros.
147 * Given block size, type prefix, block pointer, and index of requested entry
148 * (first entry numbered 1).
150 #define XFS_BTREE_REC_ADDR(bsz,t,bb,i,mxr) \
151 ((t ## _rec_t *)((char *)(bb) + sizeof(t ## _block_t) + \
152 ((i) - 1) * sizeof(t ## _rec_t)))
153 #define XFS_BTREE_KEY_ADDR(bsz,t,bb,i,mxr) \
154 ((t ## _key_t *)((char *)(bb) + sizeof(t ## _block_t) + \
155 ((i) - 1) * sizeof(t ## _key_t)))
156 #define XFS_BTREE_PTR_ADDR(bsz,t,bb,i,mxr) \
157 ((t ## _ptr_t *)((char *)(bb) + sizeof(t ## _block_t) + \
158 (mxr) * sizeof(t ## _key_t) + ((i) - 1) * sizeof(t ## _ptr_t)))
160 #define XFS_BTREE_MAXLEVELS 8 /* max of all btrees */
163 * Btree cursor structure.
164 * This collects all information needed by the btree code in one place.
166 typedef struct xfs_btree_cur
168 struct xfs_trans *bc_tp; /* transaction we're in, if any */
169 struct xfs_mount *bc_mp; /* file system mount struct */
174 } bc_rec; /* current insert/search record value */
175 struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS]; /* buf ptr per level */
176 int bc_ptrs[XFS_BTREE_MAXLEVELS]; /* key/record # */
177 __uint8_t bc_ra[XFS_BTREE_MAXLEVELS]; /* readahead bits */
178 #define XFS_BTCUR_LEFTRA 1 /* left sibling has been read-ahead */
179 #define XFS_BTCUR_RIGHTRA 2 /* right sibling has been read-ahead */
180 __uint8_t bc_nlevels; /* number of levels in the tree */
181 __uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */
182 xfs_btnum_t bc_btnum; /* identifies which btree type */
184 struct { /* needed for BNO, CNT */
185 struct xfs_buf *agbp; /* agf buffer pointer */
186 xfs_agnumber_t agno; /* ag number */
188 struct { /* needed for BMAP */
189 struct xfs_inode *ip; /* pointer to our inode */
190 struct xfs_bmap_free *flist; /* list to free after */
191 xfs_fsblock_t firstblock; /* 1st blk allocated */
192 int allocated; /* count of alloced */
193 short forksize; /* fork's inode space */
194 char whichfork; /* data or attr fork */
195 char flags; /* flags */
196 #define XFS_BTCUR_BPRV_WASDEL 1 /* was delayed */
198 struct { /* needed for INO */
199 struct xfs_buf *agbp; /* agi buffer pointer */
200 xfs_agnumber_t agno; /* ag number */
202 } bc_private; /* per-btree type data */
205 #define XFS_BTREE_NOERROR 0
206 #define XFS_BTREE_ERROR 1
209 * Convert from buffer to btree block header.
211 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_BLOCK)
212 xfs_btree_block_t *xfs_buf_to_block(struct xfs_buf *bp);
215 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_BLOCK)
216 #define XFS_BUF_TO_BLOCK(bp) xfs_buf_to_block(bp)
218 #define XFS_BUF_TO_BLOCK(bp) ((xfs_btree_block_t *)(XFS_BUF_PTR(bp)))
221 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_LBLOCK)
222 xfs_btree_lblock_t *xfs_buf_to_lblock(struct xfs_buf *bp);
225 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_LBLOCK)
226 #define XFS_BUF_TO_LBLOCK(bp) xfs_buf_to_lblock(bp)
228 #define XFS_BUF_TO_LBLOCK(bp) ((xfs_btree_lblock_t *)(XFS_BUF_PTR(bp)))
231 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_SBLOCK)
232 xfs_btree_sblock_t *xfs_buf_to_sblock(struct xfs_buf *bp);
235 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_SBLOCK)
236 #define XFS_BUF_TO_SBLOCK(bp) xfs_buf_to_sblock(bp)
238 #define XFS_BUF_TO_SBLOCK(bp) ((xfs_btree_sblock_t *)(XFS_BUF_PTR(bp)))
245 * Debug routine: check that block header is ok.
248 xfs_btree_check_block(
249 xfs_btree_cur_t *cur, /* btree cursor */
250 xfs_btree_block_t *block, /* generic btree block pointer */
251 int level, /* level of the btree block */
252 struct xfs_buf *bp); /* buffer containing block, if any */
255 * Debug routine: check that keys are in the right order.
259 xfs_btnum_t btnum, /* btree identifier */
260 void *ak1, /* pointer to left (lower) key */
261 void *ak2); /* pointer to right (higher) key */
264 * Debug routine: check that records are in the right order.
268 xfs_btnum_t btnum, /* btree identifier */
269 void *ar1, /* pointer to left (lower) record */
270 void *ar2); /* pointer to right (higher) record */
272 #define xfs_btree_check_block(a,b,c,d)
273 #define xfs_btree_check_key(a,b,c)
274 #define xfs_btree_check_rec(a,b,c)
278 * Checking routine: check that long form block header is ok.
280 int /* error (0 or EFSCORRUPTED) */
281 xfs_btree_check_lblock(
282 xfs_btree_cur_t *cur, /* btree cursor */
283 xfs_btree_lblock_t *block, /* btree long form block pointer */
284 int level, /* level of the btree block */
285 struct xfs_buf *bp); /* buffer containing block, if any */
288 * Checking routine: check that (long) pointer is ok.
290 int /* error (0 or EFSCORRUPTED) */
291 xfs_btree_check_lptr(
292 xfs_btree_cur_t *cur, /* btree cursor */
293 xfs_dfsbno_t ptr, /* btree block disk address */
294 int level); /* btree block level */
297 * Checking routine: check that short form block header is ok.
299 int /* error (0 or EFSCORRUPTED) */
300 xfs_btree_check_sblock(
301 xfs_btree_cur_t *cur, /* btree cursor */
302 xfs_btree_sblock_t *block, /* btree short form block pointer */
303 int level, /* level of the btree block */
304 struct xfs_buf *bp); /* buffer containing block */
307 * Checking routine: check that (short) pointer is ok.
309 int /* error (0 or EFSCORRUPTED) */
310 xfs_btree_check_sptr(
311 xfs_btree_cur_t *cur, /* btree cursor */
312 xfs_agblock_t ptr, /* btree block disk address */
313 int level); /* btree block level */
316 * Delete the btree cursor.
319 xfs_btree_del_cursor(
320 xfs_btree_cur_t *cur, /* btree cursor */
321 int error); /* del because of error */
324 * Duplicate the btree cursor.
325 * Allocate a new one, copy the record, re-get the buffers.
328 xfs_btree_dup_cursor(
329 xfs_btree_cur_t *cur, /* input cursor */
330 xfs_btree_cur_t **ncur);/* output cursor */
333 * Change the cursor to point to the first record in the current block
334 * at the given level. Other levels are unaffected.
336 int /* success=1, failure=0 */
338 xfs_btree_cur_t *cur, /* btree cursor */
339 int level); /* level to change */
342 * Retrieve the block pointer from the cursor at the given level.
343 * This may be a bmap btree root or from a buffer.
345 xfs_btree_block_t * /* generic btree block pointer */
347 xfs_btree_cur_t *cur, /* btree cursor */
348 int level, /* level in btree */
349 struct xfs_buf **bpp); /* buffer containing the block */
352 * Get a buffer for the block, return it with no data read.
353 * Long-form addressing.
355 struct xfs_buf * /* buffer for fsbno */
357 struct xfs_mount *mp, /* file system mount point */
358 struct xfs_trans *tp, /* transaction pointer */
359 xfs_fsblock_t fsbno, /* file system block number */
360 uint lock); /* lock flags for get_buf */
363 * Get a buffer for the block, return it with no data read.
364 * Short-form addressing.
366 struct xfs_buf * /* buffer for agno/agbno */
368 struct xfs_mount *mp, /* file system mount point */
369 struct xfs_trans *tp, /* transaction pointer */
370 xfs_agnumber_t agno, /* allocation group number */
371 xfs_agblock_t agbno, /* allocation group block number */
372 uint lock); /* lock flags for get_buf */
375 * Allocate a new btree cursor.
376 * The cursor is either for allocation (A) or bmap (B).
378 xfs_btree_cur_t * /* new btree cursor */
379 xfs_btree_init_cursor(
380 struct xfs_mount *mp, /* file system mount point */
381 struct xfs_trans *tp, /* transaction pointer */
382 struct xfs_buf *agbp, /* (A only) buffer for agf structure */
383 xfs_agnumber_t agno, /* (A only) allocation group number */
384 xfs_btnum_t btnum, /* btree identifier */
385 struct xfs_inode *ip, /* (B only) inode owning the btree */
386 int whichfork); /* (B only) data/attr fork */
389 * Check for the cursor referring to the last block at the given level.
391 int /* 1=is last block, 0=not last block */
392 xfs_btree_islastblock(
393 xfs_btree_cur_t *cur, /* btree cursor */
394 int level); /* level to check */
397 * Change the cursor to point to the last record in the current block
398 * at the given level. Other levels are unaffected.
400 int /* success=1, failure=0 */
402 xfs_btree_cur_t *cur, /* btree cursor */
403 int level); /* level to change */
406 * Compute first and last byte offsets for the fields given.
407 * Interprets the offsets table, which contains struct field offsets.
411 __int64_t fields, /* bitmask of fields */
412 const short *offsets,/* table of field offsets */
413 int nbits, /* number of bits to inspect */
414 int *first, /* output: first byte offset */
415 int *last); /* output: last byte offset */
418 * Get a buffer for the block, return it read in.
419 * Long-form addressing.
423 struct xfs_mount *mp, /* file system mount point */
424 struct xfs_trans *tp, /* transaction pointer */
425 xfs_fsblock_t fsbno, /* file system block number */
426 uint lock, /* lock flags for read_buf */
427 struct xfs_buf **bpp, /* buffer for fsbno */
428 int refval);/* ref count value for buffer */
431 * Get a buffer for the block, return it read in.
432 * Short-form addressing.
436 struct xfs_mount *mp, /* file system mount point */
437 struct xfs_trans *tp, /* transaction pointer */
438 xfs_agnumber_t agno, /* allocation group number */
439 xfs_agblock_t agbno, /* allocation group block number */
440 uint lock, /* lock flags for read_buf */
441 struct xfs_buf **bpp, /* buffer for agno/agbno */
442 int refval);/* ref count value for buffer */
445 * Read-ahead the block, don't wait for it, don't return a buffer.
446 * Long-form addressing.
449 xfs_btree_reada_bufl(
450 struct xfs_mount *mp, /* file system mount point */
451 xfs_fsblock_t fsbno, /* file system block number */
452 xfs_extlen_t count); /* count of filesystem blocks */
455 * Read-ahead the block, don't wait for it, don't return a buffer.
456 * Short-form addressing.
459 xfs_btree_reada_bufs(
460 struct xfs_mount *mp, /* file system mount point */
461 xfs_agnumber_t agno, /* allocation group number */
462 xfs_agblock_t agbno, /* allocation group block number */
463 xfs_extlen_t count); /* count of filesystem blocks */
466 * Read-ahead btree blocks, at the given level.
467 * Bits in lr are set from XFS_BTCUR_{LEFT,RIGHT}RA.
469 int /* readahead block count */
470 xfs_btree_readahead_core(
471 xfs_btree_cur_t *cur, /* btree cursor */
472 int lev, /* level in btree */
473 int lr); /* left/right bits */
475 static inline int /* readahead block count */
477 xfs_btree_cur_t *cur, /* btree cursor */
478 int lev, /* level in btree */
479 int lr) /* left/right bits */
481 if ((cur->bc_ra[lev] | lr) == cur->bc_ra[lev])
484 return xfs_btree_readahead_core(cur, lev, lr);
489 * Set the buffer for level "lev" in the cursor to bp, releasing
490 * any previous buffer.
494 xfs_btree_cur_t *cur, /* btree cursor */
495 int lev, /* level in btree */
496 struct xfs_buf *bp); /* new buffer to set */
498 #endif /* __KERNEL__ */
502 * Min and max functions for extlen, agblock, fileoff, and filblks types.
504 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MIN)
505 xfs_extlen_t xfs_extlen_min(xfs_extlen_t a, xfs_extlen_t b);
508 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MIN)
509 #define XFS_EXTLEN_MIN(a,b) xfs_extlen_min(a,b)
511 #define XFS_EXTLEN_MIN(a,b) \
512 ((xfs_extlen_t)(a) < (xfs_extlen_t)(b) ? \
513 (xfs_extlen_t)(a) : (xfs_extlen_t)(b))
516 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MAX)
517 xfs_extlen_t xfs_extlen_max(xfs_extlen_t a, xfs_extlen_t b);
520 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MAX)
521 #define XFS_EXTLEN_MAX(a,b) xfs_extlen_max(a,b)
523 #define XFS_EXTLEN_MAX(a,b) \
524 ((xfs_extlen_t)(a) > (xfs_extlen_t)(b) ? \
525 (xfs_extlen_t)(a) : (xfs_extlen_t)(b))
528 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MIN)
529 xfs_agblock_t xfs_agblock_min(xfs_agblock_t a, xfs_agblock_t b);
532 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MIN)
533 #define XFS_AGBLOCK_MIN(a,b) xfs_agblock_min(a,b)
535 #define XFS_AGBLOCK_MIN(a,b) \
536 ((xfs_agblock_t)(a) < (xfs_agblock_t)(b) ? \
537 (xfs_agblock_t)(a) : (xfs_agblock_t)(b))
540 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MAX)
541 xfs_agblock_t xfs_agblock_max(xfs_agblock_t a, xfs_agblock_t b);
544 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MAX)
545 #define XFS_AGBLOCK_MAX(a,b) xfs_agblock_max(a,b)
547 #define XFS_AGBLOCK_MAX(a,b) \
548 ((xfs_agblock_t)(a) > (xfs_agblock_t)(b) ? \
549 (xfs_agblock_t)(a) : (xfs_agblock_t)(b))
552 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MIN)
553 xfs_fileoff_t xfs_fileoff_min(xfs_fileoff_t a, xfs_fileoff_t b);
556 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MIN)
557 #define XFS_FILEOFF_MIN(a,b) xfs_fileoff_min(a,b)
559 #define XFS_FILEOFF_MIN(a,b) \
560 ((xfs_fileoff_t)(a) < (xfs_fileoff_t)(b) ? \
561 (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b))
564 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MAX)
565 xfs_fileoff_t xfs_fileoff_max(xfs_fileoff_t a, xfs_fileoff_t b);
568 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MAX)
569 #define XFS_FILEOFF_MAX(a,b) xfs_fileoff_max(a,b)
571 #define XFS_FILEOFF_MAX(a,b) \
572 ((xfs_fileoff_t)(a) > (xfs_fileoff_t)(b) ? \
573 (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b))
576 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MIN)
577 xfs_filblks_t xfs_filblks_min(xfs_filblks_t a, xfs_filblks_t b);
580 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MIN)
581 #define XFS_FILBLKS_MIN(a,b) xfs_filblks_min(a,b)
583 #define XFS_FILBLKS_MIN(a,b) \
584 ((xfs_filblks_t)(a) < (xfs_filblks_t)(b) ? \
585 (xfs_filblks_t)(a) : (xfs_filblks_t)(b))
588 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MAX)
589 xfs_filblks_t xfs_filblks_max(xfs_filblks_t a, xfs_filblks_t b);
592 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MAX)
593 #define XFS_FILBLKS_MAX(a,b) xfs_filblks_max(a,b)
595 #define XFS_FILBLKS_MAX(a,b) \
596 ((xfs_filblks_t)(a) > (xfs_filblks_t)(b) ? \
597 (xfs_filblks_t)(a) : (xfs_filblks_t)(b))
600 #if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_FSB_SANITY_CHECK)
601 int xfs_fsb_sanity_check(struct xfs_mount *mp, xfs_fsblock_t fsb);
604 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_SANITY_CHECK)
605 #define XFS_FSB_SANITY_CHECK(mp,fsb) xfs_fsb_sanity_check(mp,fsb)
607 #define XFS_FSB_SANITY_CHECK(mp,fsb) \
608 (XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \
609 XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks)
613 * Macros to set EFSCORRUPTED & return/branch.
615 #define XFS_WANT_CORRUPTED_GOTO(x,l) \
617 int fs_is_ok = (x); \
619 if (unlikely(!fs_is_ok)) { \
620 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \
621 XFS_ERRLEVEL_LOW, NULL); \
622 error = XFS_ERROR(EFSCORRUPTED); \
627 #define XFS_WANT_CORRUPTED_RETURN(x) \
629 int fs_is_ok = (x); \
631 if (unlikely(!fs_is_ok)) { \
632 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \
633 XFS_ERRLEVEL_LOW, NULL); \
634 return XFS_ERROR(EFSCORRUPTED); \
638 #endif /* __XFS_BTREE_H__ */