1 /*
2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
3 *
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.
7 *
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.
11 *
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.
18 *
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.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32 #ifndef __XFS_BTREE_H__
33 #define __XFS_BTREE_H__
34
35 struct xfs_buf;
36 struct xfs_bmap_free;
37 struct xfs_inode;
38 struct xfs_mount;
39 struct xfs_trans;
40
41 /*
42 * This nonsense is to make -wlint happy.
43 */
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)
47
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)
52
53 /*
54 * Short form header: space allocation btrees.
55 */
56 typedef struct xfs_btree_sblock
57 {
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 */
63 } xfs_btree_sblock_t;
64
65 /*
66 * Long form header: bmap btrees.
67 */
68 typedef struct xfs_btree_lblock
69 {
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 */
75 } xfs_btree_lblock_t;
76
77 /*
78 * Combined header and structure, used by common code.
79 */
80 typedef struct xfs_btree_hdr
81 {
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 */
85 } xfs_btree_hdr_t;
86
87 typedef struct xfs_btree_block
88 {
89 xfs_btree_hdr_t bb_h; /* header */
90 union {
91 struct {
92 xfs_agblock_t bb_leftsib;
93 xfs_agblock_t bb_rightsib;
94 } s; /* short form pointers */
95 struct {
96 xfs_dfsbno_t bb_leftsib;
97 xfs_dfsbno_t bb_rightsib;
98 } l; /* long form pointers */
99 } bb_u; /* rest */
100 } xfs_btree_block_t;
101
102 /*
103 * For logging record fields.
104 */
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)
112
113 /*
114 * Boolean to select which form of xfs_btree_block_t.bb_u to use.
115 */
116 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BTREE_LONG_PTRS)
117 int xfs_btree_long_ptrs(xfs_btnum_t btnum);
118 #define XFS_BTREE_LONG_PTRS(btnum) ((btnum) == XFS_BTNUM_BMAP)
119 #else
120 #define XFS_BTREE_LONG_PTRS(btnum) ((btnum) == XFS_BTNUM_BMAP)
121 #endif
122
123 /*
124 * Magic numbers for btree blocks.
125 */
126 extern const __uint32_t xfs_magics[];
127
128 /*
129 * Maximum and minimum records in a btree block.
130 * Given block size, type prefix, and leaf flag (0 or 1).
131 * The divisor below is equivalent to lf ? (e1) : (e2) but that produces
132 * compiler warnings.
133 */
134 #define XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf) \
135 ((int)(((bsz) - (uint)sizeof(t ## _block_t)) / \
136 (((lf) * (uint)sizeof(t ## _rec_t)) + \
137 ((1 - (lf)) * \
138 ((uint)sizeof(t ## _key_t) + (uint)sizeof(t ## _ptr_t))))))
139 #define XFS_BTREE_BLOCK_MINRECS(bsz,t,lf) \
140 (XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf) / 2)
141
142 /*
143 * Record, key, and pointer address calculation macros.
144 * Given block size, type prefix, block pointer, and index of requested entry
145 * (first entry numbered 1).
146 */
147 #define XFS_BTREE_REC_ADDR(bsz,t,bb,i,mxr) \
148 ((t ## _rec_t *)((char *)(bb) + sizeof(t ## _block_t) + \
149 ((i) - 1) * sizeof(t ## _rec_t)))
150 #define XFS_BTREE_KEY_ADDR(bsz,t,bb,i,mxr) \
151 ((t ## _key_t *)((char *)(bb) + sizeof(t ## _block_t) + \
152 ((i) - 1) * sizeof(t ## _key_t)))
153 #define XFS_BTREE_PTR_ADDR(bsz,t,bb,i,mxr) \
154 ((t ## _ptr_t *)((char *)(bb) + sizeof(t ## _block_t) + \
155 (mxr) * sizeof(t ## _key_t) + ((i) - 1) * sizeof(t ## _ptr_t)))
156
157 #define XFS_BTREE_MAXLEVELS 8 /* max of all btrees */
158
159 /*
160 * Btree cursor structure.
161 * This collects all information needed by the btree code in one place.
162 */
163 typedef struct xfs_btree_cur
164 {
165 struct xfs_trans *bc_tp; /* transaction we're in, if any */
166 struct xfs_mount *bc_mp; /* file system mount struct */
167 union {
168 xfs_alloc_rec_t a;
169 xfs_bmbt_irec_t b;
170 xfs_inobt_rec_t i;
171 } bc_rec; /* current insert/search record value */
172 struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS]; /* buf ptr per level */
173 int bc_ptrs[XFS_BTREE_MAXLEVELS]; /* key/record # */
174 __uint8_t bc_ra[XFS_BTREE_MAXLEVELS]; /* readahead bits */
175 #define XFS_BTCUR_LEFTRA 1 /* left sibling has been read-ahead */
176 #define XFS_BTCUR_RIGHTRA 2 /* right sibling has been read-ahead */
177 __uint8_t bc_nlevels; /* number of levels in the tree */
178 __uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */
179 xfs_btnum_t bc_btnum; /* identifies which btree type */
180 union {
181 struct { /* needed for BNO, CNT */
182 struct xfs_buf *agbp; /* agf buffer pointer */
183 xfs_agnumber_t agno; /* ag number */
184 } a;
185 struct { /* needed for BMAP */
186 struct xfs_inode *ip; /* pointer to our inode */
187 struct xfs_bmap_free *flist; /* list to free after */
188 xfs_fsblock_t firstblock; /* 1st blk allocated */
189 int allocated; /* count of alloced */
190 short forksize; /* fork's inode space */
191 char whichfork; /* data or attr fork */
192 char flags; /* flags */
193 #define XFS_BTCUR_BPRV_WASDEL 1 /* was delayed */
194 } b;
195 struct { /* needed for INO */
196 struct xfs_buf *agbp; /* agi buffer pointer */
197 xfs_agnumber_t agno; /* ag number */
198 } i;
199 } bc_private; /* per-btree type data */
200 } xfs_btree_cur_t;
201
202 #define XFS_BTREE_NOERROR 0
203 #define XFS_BTREE_ERROR 1
204
205 /*
206 * Convert from buffer to btree block header.
207 */
208 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_BLOCK)
209 xfs_btree_block_t *xfs_buf_to_block(struct xfs_buf *bp);
210 #define XFS_BUF_TO_BLOCK(bp) xfs_buf_to_block(bp)
211 #else
212 #define XFS_BUF_TO_BLOCK(bp) ((xfs_btree_block_t *)(XFS_BUF_PTR(bp)))
213 #endif
214 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_LBLOCK)
215 xfs_btree_lblock_t *xfs_buf_to_lblock(struct xfs_buf *bp);
216 #define XFS_BUF_TO_LBLOCK(bp) xfs_buf_to_lblock(bp)
217 #else
218 #define XFS_BUF_TO_LBLOCK(bp) ((xfs_btree_lblock_t *)(XFS_BUF_PTR(bp)))
219 #endif
220 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_SBLOCK)
221 xfs_btree_sblock_t *xfs_buf_to_sblock(struct xfs_buf *bp);
222 #define XFS_BUF_TO_SBLOCK(bp) xfs_buf_to_sblock(bp)
223 #else
224 #define XFS_BUF_TO_SBLOCK(bp) ((xfs_btree_sblock_t *)(XFS_BUF_PTR(bp)))
225 #endif
226
227 #ifdef __KERNEL__
228
229 #ifdef DEBUG
230 /*
231 * Debug routine: check that block header is ok.
232 */
233 void
234 xfs_btree_check_block(
235 xfs_btree_cur_t *cur, /* btree cursor */
236 xfs_btree_block_t *block, /* generic btree block pointer */
237 int level, /* level of the btree block */
238 struct xfs_buf *bp); /* buffer containing block, if any */
239
240 /*
241 * Debug routine: check that keys are in the right order.
242 */
243 void
244 xfs_btree_check_key(
245 xfs_btnum_t btnum, /* btree identifier */
246 void *ak1, /* pointer to left (lower) key */
247 void *ak2); /* pointer to right (higher) key */
248
249 /*
250 * Debug routine: check that records are in the right order.
251 */
252 void
253 xfs_btree_check_rec(
254 xfs_btnum_t btnum, /* btree identifier */
255 void *ar1, /* pointer to left (lower) record */
256 void *ar2); /* pointer to right (higher) record */
257 #else
258 #define xfs_btree_check_block(a,b,c,d)
259 #define xfs_btree_check_key(a,b,c)
260 #define xfs_btree_check_rec(a,b,c)
261 #endif /* DEBUG */
262
263 /*
264 * Checking routine: check that long form block header is ok.
265 */
266 int /* error (0 or EFSCORRUPTED) */
267 xfs_btree_check_lblock(
268 xfs_btree_cur_t *cur, /* btree cursor */
269 xfs_btree_lblock_t *block, /* btree long form block pointer */
270 int level, /* level of the btree block */
271 struct xfs_buf *bp); /* buffer containing block, if any */
272
273 /*
274 * Checking routine: check that (long) pointer is ok.
275 */
276 int /* error (0 or EFSCORRUPTED) */
277 xfs_btree_check_lptr(
278 xfs_btree_cur_t *cur, /* btree cursor */
279 xfs_dfsbno_t ptr, /* btree block disk address */
280 int level); /* btree block level */
281
282 /*
283 * Checking routine: check that short form block header is ok.
284 */
285 int /* error (0 or EFSCORRUPTED) */
286 xfs_btree_check_sblock(
287 xfs_btree_cur_t *cur, /* btree cursor */
288 xfs_btree_sblock_t *block, /* btree short form block pointer */
289 int level, /* level of the btree block */
290 struct xfs_buf *bp); /* buffer containing block */
291
292 /*
293 * Checking routine: check that (short) pointer is ok.
294 */
295 int /* error (0 or EFSCORRUPTED) */
296 xfs_btree_check_sptr(
297 xfs_btree_cur_t *cur, /* btree cursor */
298 xfs_agblock_t ptr, /* btree block disk address */
299 int level); /* btree block level */
300
301 /*
302 * Delete the btree cursor.
303 */
304 void
305 xfs_btree_del_cursor(
306 xfs_btree_cur_t *cur, /* btree cursor */
307 int error); /* del because of error */
308
309 /*
310 * Duplicate the btree cursor.
311 * Allocate a new one, copy the record, re-get the buffers.
312 */
313 int /* error */
314 xfs_btree_dup_cursor(
315 xfs_btree_cur_t *cur, /* input cursor */
316 xfs_btree_cur_t **ncur);/* output cursor */
317
318 /*
319 * Change the cursor to point to the first record in the current block
320 * at the given level. Other levels are unaffected.
321 */
322 int /* success=1, failure=0 */
323 xfs_btree_firstrec(
324 xfs_btree_cur_t *cur, /* btree cursor */
325 int level); /* level to change */
326
327 /*
328 * Retrieve the block pointer from the cursor at the given level.
329 * This may be a bmap btree root or from a buffer.
330 */
331 xfs_btree_block_t * /* generic btree block pointer */
332 xfs_btree_get_block(
333 xfs_btree_cur_t *cur, /* btree cursor */
334 int level, /* level in btree */
335 struct xfs_buf **bpp); /* buffer containing the block */
336
337 /*
338 * Get a buffer for the block, return it with no data read.
339 * Long-form addressing.
340 */
341 struct xfs_buf * /* buffer for fsbno */
342 xfs_btree_get_bufl(
343 struct xfs_mount *mp, /* file system mount point */
344 struct xfs_trans *tp, /* transaction pointer */
345 xfs_fsblock_t fsbno, /* file system block number */
346 uint lock); /* lock flags for get_buf */
347
348 /*
349 * Get a buffer for the block, return it with no data read.
350 * Short-form addressing.
351 */
352 struct xfs_buf * /* buffer for agno/agbno */
353 xfs_btree_get_bufs(
354 struct xfs_mount *mp, /* file system mount point */
355 struct xfs_trans *tp, /* transaction pointer */
356 xfs_agnumber_t agno, /* allocation group number */
357 xfs_agblock_t agbno, /* allocation group block number */
358 uint lock); /* lock flags for get_buf */
359
360 /*
361 * Allocate a new btree cursor.
362 * The cursor is either for allocation (A) or bmap (B).
363 */
364 xfs_btree_cur_t * /* new btree cursor */
365 xfs_btree_init_cursor(
366 struct xfs_mount *mp, /* file system mount point */
367 struct xfs_trans *tp, /* transaction pointer */
368 struct xfs_buf *agbp, /* (A only) buffer for agf structure */
369 xfs_agnumber_t agno, /* (A only) allocation group number */
370 xfs_btnum_t btnum, /* btree identifier */
371 struct xfs_inode *ip, /* (B only) inode owning the btree */
372 int whichfork); /* (B only) data/attr fork */
373
374 /*
375 * Check for the cursor referring to the last block at the given level.
376 */
377 int /* 1=is last block, 0=not last block */
378 xfs_btree_islastblock(
379 xfs_btree_cur_t *cur, /* btree cursor */
380 int level); /* level to check */
381
382 /*
383 * Change the cursor to point to the last record in the current block
384 * at the given level. Other levels are unaffected.
385 */
386 int /* success=1, failure=0 */
387 xfs_btree_lastrec(
388 xfs_btree_cur_t *cur, /* btree cursor */
389 int level); /* level to change */
390
391 /*
392 * Compute first and last byte offsets for the fields given.
393 * Interprets the offsets table, which contains struct field offsets.
394 */
395 void
396 xfs_btree_offsets(
397 __int64_t fields, /* bitmask of fields */
398 const short *offsets,/* table of field offsets */
399 int nbits, /* number of bits to inspect */
400 int *first, /* output: first byte offset */
401 int *last); /* output: last byte offset */
402
403 /*
404 * Get a buffer for the block, return it read in.
405 * Long-form addressing.
406 */
407 int /* error */
408 xfs_btree_read_bufl(
409 struct xfs_mount *mp, /* file system mount point */
410 struct xfs_trans *tp, /* transaction pointer */
411 xfs_fsblock_t fsbno, /* file system block number */
412 uint lock, /* lock flags for read_buf */
413 struct xfs_buf **bpp, /* buffer for fsbno */
414 int refval);/* ref count value for buffer */
415
416 /*
417 * Get a buffer for the block, return it read in.
418 * Short-form addressing.
419 */
420 int /* error */
421 xfs_btree_read_bufs(
422 struct xfs_mount *mp, /* file system mount point */
423 struct xfs_trans *tp, /* transaction pointer */
424 xfs_agnumber_t agno, /* allocation group number */
425 xfs_agblock_t agbno, /* allocation group block number */
426 uint lock, /* lock flags for read_buf */
427 struct xfs_buf **bpp, /* buffer for agno/agbno */
428 int refval);/* ref count value for buffer */
429
430 /*
431 * Read-ahead the block, don't wait for it, don't return a buffer.
432 * Long-form addressing.
433 */
434 void /* error */
435 xfs_btree_reada_bufl(
436 struct xfs_mount *mp, /* file system mount point */
437 xfs_fsblock_t fsbno, /* file system block number */
438 xfs_extlen_t count); /* count of filesystem blocks */
439
440 /*
441 * Read-ahead the block, don't wait for it, don't return a buffer.
442 * Short-form addressing.
443 */
444 void /* error */
445 xfs_btree_reada_bufs(
446 struct xfs_mount *mp, /* file system mount point */
447 xfs_agnumber_t agno, /* allocation group number */
448 xfs_agblock_t agbno, /* allocation group block number */
449 xfs_extlen_t count); /* count of filesystem blocks */
450
451 /*
452 * Read-ahead btree blocks, at the given level.
453 * Bits in lr are set from XFS_BTCUR_{LEFT,RIGHT}RA.
454 */
455 int /* readahead block count */
456 xfs_btree_readahead_core(
457 xfs_btree_cur_t *cur, /* btree cursor */
458 int lev, /* level in btree */
459 int lr); /* left/right bits */
460
461 static inline int /* readahead block count */
xfs_btree_readahead(xfs_btree_cur_t * cur,int lev,int lr)462 xfs_btree_readahead(
463 xfs_btree_cur_t *cur, /* btree cursor */
464 int lev, /* level in btree */
465 int lr) /* left/right bits */
466 {
467 if ((cur->bc_ra[lev] | lr) == cur->bc_ra[lev])
468 return 0;
469
470 return xfs_btree_readahead_core(cur, lev, lr);
471 }
472
473
474 /*
475 * Set the buffer for level "lev" in the cursor to bp, releasing
476 * any previous buffer.
477 */
478 void
479 xfs_btree_setbuf(
480 xfs_btree_cur_t *cur, /* btree cursor */
481 int lev, /* level in btree */
482 struct xfs_buf *bp); /* new buffer to set */
483
484 #endif /* __KERNEL__ */
485
486
487 /*
488 * Min and max functions for extlen, agblock, fileoff, and filblks types.
489 */
490 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MIN)
491 xfs_extlen_t xfs_extlen_min(xfs_extlen_t a, xfs_extlen_t b);
492 #define XFS_EXTLEN_MIN(a,b) xfs_extlen_min(a,b)
493 #else
494 #define XFS_EXTLEN_MIN(a,b) \
495 ((xfs_extlen_t)(a) < (xfs_extlen_t)(b) ? \
496 (xfs_extlen_t)(a) : (xfs_extlen_t)(b))
497 #endif
498 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MAX)
499 xfs_extlen_t xfs_extlen_max(xfs_extlen_t a, xfs_extlen_t b);
500 #define XFS_EXTLEN_MAX(a,b) xfs_extlen_max(a,b)
501 #else
502 #define XFS_EXTLEN_MAX(a,b) \
503 ((xfs_extlen_t)(a) > (xfs_extlen_t)(b) ? \
504 (xfs_extlen_t)(a) : (xfs_extlen_t)(b))
505 #endif
506
507 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MIN)
508 xfs_agblock_t xfs_agblock_min(xfs_agblock_t a, xfs_agblock_t b);
509 #define XFS_AGBLOCK_MIN(a,b) xfs_agblock_min(a,b)
510 #else
511 #define XFS_AGBLOCK_MIN(a,b) \
512 ((xfs_agblock_t)(a) < (xfs_agblock_t)(b) ? \
513 (xfs_agblock_t)(a) : (xfs_agblock_t)(b))
514 #endif
515 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MAX)
516 xfs_agblock_t xfs_agblock_max(xfs_agblock_t a, xfs_agblock_t b);
517 #define XFS_AGBLOCK_MAX(a,b) xfs_agblock_max(a,b)
518 #else
519 #define XFS_AGBLOCK_MAX(a,b) \
520 ((xfs_agblock_t)(a) > (xfs_agblock_t)(b) ? \
521 (xfs_agblock_t)(a) : (xfs_agblock_t)(b))
522 #endif
523
524 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MIN)
525 xfs_fileoff_t xfs_fileoff_min(xfs_fileoff_t a, xfs_fileoff_t b);
526 #define XFS_FILEOFF_MIN(a,b) xfs_fileoff_min(a,b)
527 #else
528 #define XFS_FILEOFF_MIN(a,b) \
529 ((xfs_fileoff_t)(a) < (xfs_fileoff_t)(b) ? \
530 (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b))
531 #endif
532 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MAX)
533 xfs_fileoff_t xfs_fileoff_max(xfs_fileoff_t a, xfs_fileoff_t b);
534 #define XFS_FILEOFF_MAX(a,b) xfs_fileoff_max(a,b)
535 #else
536 #define XFS_FILEOFF_MAX(a,b) \
537 ((xfs_fileoff_t)(a) > (xfs_fileoff_t)(b) ? \
538 (xfs_fileoff_t)(a) : (xfs_fileoff_t)(b))
539 #endif
540
541 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MIN)
542 xfs_filblks_t xfs_filblks_min(xfs_filblks_t a, xfs_filblks_t b);
543 #define XFS_FILBLKS_MIN(a,b) xfs_filblks_min(a,b)
544 #else
545 #define XFS_FILBLKS_MIN(a,b) \
546 ((xfs_filblks_t)(a) < (xfs_filblks_t)(b) ? \
547 (xfs_filblks_t)(a) : (xfs_filblks_t)(b))
548 #endif
549 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MAX)
550 xfs_filblks_t xfs_filblks_max(xfs_filblks_t a, xfs_filblks_t b);
551 #define XFS_FILBLKS_MAX(a,b) xfs_filblks_max(a,b)
552 #else
553 #define XFS_FILBLKS_MAX(a,b) \
554 ((xfs_filblks_t)(a) > (xfs_filblks_t)(b) ? \
555 (xfs_filblks_t)(a) : (xfs_filblks_t)(b))
556 #endif
557 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_SANITY_CHECK)
558 int xfs_fsb_sanity_check(struct xfs_mount *mp, xfs_fsblock_t fsb);
559 #define XFS_FSB_SANITY_CHECK(mp,fsb) xfs_fsb_sanity_check(mp,fsb)
560 #else
561 #define XFS_FSB_SANITY_CHECK(mp,fsb) \
562 (XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \
563 XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks)
564 #endif
565
566 /*
567 * Macros to set EFSCORRUPTED & return/branch.
568 */
569 #define XFS_WANT_CORRUPTED_GOTO(x,l) \
570 { \
571 int fs_is_ok = (x); \
572 ASSERT(fs_is_ok); \
573 if (unlikely(!fs_is_ok)) { \
574 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \
575 XFS_ERRLEVEL_LOW, NULL); \
576 error = XFS_ERROR(EFSCORRUPTED); \
577 goto l; \
578 } \
579 }
580
581 #define XFS_WANT_CORRUPTED_RETURN(x) \
582 { \
583 int fs_is_ok = (x); \
584 ASSERT(fs_is_ok); \
585 if (unlikely(!fs_is_ok)) { \
586 XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \
587 XFS_ERRLEVEL_LOW, NULL); \
588 return XFS_ERROR(EFSCORRUPTED); \
589 } \
590 }
591
592 #endif /* __XFS_BTREE_H__ */
593