]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/gnu/fs/xfs/xfs_btree.h
This commit was generated by cvs2svn to compensate for changes in r155832,
[FreeBSD/FreeBSD.git] / sys / gnu / fs / xfs / xfs_btree.h
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_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XFS_BTREE_LONG_PTRS)
117 int xfs_btree_long_ptrs(xfs_btnum_t btnum);
118 #endif
119
120 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BTREE_LONG_PTRS)
121 #define XFS_BTREE_LONG_PTRS(btnum)      ((btnum) == XFS_BTNUM_BMAP)
122 #else
123 #define XFS_BTREE_LONG_PTRS(btnum)      ((btnum) == XFS_BTNUM_BMAP)
124 #endif
125
126 /*
127  * Magic numbers for btree blocks.
128  */
129 extern const __uint32_t xfs_magics[];
130
131 /*
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
135  * compiler warnings.
136  */
137 #define XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf)       \
138         ((int)(((bsz) - (uint)sizeof(t ## _block_t)) / \
139          (((lf) * (uint)sizeof(t ## _rec_t)) + \
140           ((1 - (lf)) * \
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)
144
145 /*
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).
149  */
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)))
159
160 #define XFS_BTREE_MAXLEVELS     8       /* max of all btrees */
161
162 /*
163  * Btree cursor structure.
164  * This collects all information needed by the btree code in one place.
165  */
166 typedef struct xfs_btree_cur
167 {
168         struct xfs_trans        *bc_tp; /* transaction we're in, if any */
169         struct xfs_mount        *bc_mp; /* file system mount struct */
170         union {
171                 xfs_alloc_rec_t         a;
172                 xfs_bmbt_irec_t         b;
173                 xfs_inobt_rec_t         i;
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 */
183         union {
184                 struct {                        /* needed for BNO, CNT */
185                         struct xfs_buf  *agbp;  /* agf buffer pointer */
186                         xfs_agnumber_t  agno;   /* ag number */
187                 } a;
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 */
197                 } b;
198                 struct {                        /* needed for INO */
199                         struct xfs_buf  *agbp;  /* agi buffer pointer */
200                         xfs_agnumber_t  agno;   /* ag number */
201                 } i;
202         }               bc_private;     /* per-btree type data */
203 } xfs_btree_cur_t;
204
205 #define XFS_BTREE_NOERROR       0
206 #define XFS_BTREE_ERROR         1
207
208 /*
209  * Convert from buffer to btree block header.
210  */
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);
213 #endif
214
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)
217 #else
218 #define XFS_BUF_TO_BLOCK(bp)    ((xfs_btree_block_t *)(XFS_BUF_PTR(bp)))
219 #endif
220
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);
223 #endif
224
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)
227 #else
228 #define XFS_BUF_TO_LBLOCK(bp)   ((xfs_btree_lblock_t *)(XFS_BUF_PTR(bp)))
229 #endif
230
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);
233 #endif
234
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)
237 #else
238 #define XFS_BUF_TO_SBLOCK(bp)   ((xfs_btree_sblock_t *)(XFS_BUF_PTR(bp)))
239 #endif
240
241 #ifdef __KERNEL__
242
243 #ifdef DEBUG
244 /*
245  * Debug routine: check that block header is ok.
246  */
247 void
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 */
253
254 /*
255  * Debug routine: check that keys are in the right order.
256  */
257 void
258 xfs_btree_check_key(
259         xfs_btnum_t             btnum,  /* btree identifier */
260         void                    *ak1,   /* pointer to left (lower) key */
261         void                    *ak2);  /* pointer to right (higher) key */
262
263 /*
264  * Debug routine: check that records are in the right order.
265  */
266 void
267 xfs_btree_check_rec(
268         xfs_btnum_t             btnum,  /* btree identifier */
269         void                    *ar1,   /* pointer to left (lower) record */
270         void                    *ar2);  /* pointer to right (higher) record */
271 #else
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)
275 #endif  /* DEBUG */
276
277 /*
278  * Checking routine: check that long form block header is ok.
279  */
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 */
286
287 /*
288  * Checking routine: check that (long) pointer is ok.
289  */
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 */
295
296 /*
297  * Checking routine: check that short form block header is ok.
298  */
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 */
305
306 /*
307  * Checking routine: check that (short) pointer is ok.
308  */
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 */
314
315 /*
316  * Delete the btree cursor.
317  */
318 void
319 xfs_btree_del_cursor(
320         xfs_btree_cur_t         *cur,   /* btree cursor */
321         int                     error); /* del because of error */
322
323 /*
324  * Duplicate the btree cursor.
325  * Allocate a new one, copy the record, re-get the buffers.
326  */
327 int                                     /* error */
328 xfs_btree_dup_cursor(
329         xfs_btree_cur_t         *cur,   /* input cursor */
330         xfs_btree_cur_t         **ncur);/* output cursor */
331
332 /*
333  * Change the cursor to point to the first record in the current block
334  * at the given level.  Other levels are unaffected.
335  */
336 int                                     /* success=1, failure=0 */
337 xfs_btree_firstrec(
338         xfs_btree_cur_t         *cur,   /* btree cursor */
339         int                     level); /* level to change */
340
341 /*
342  * Retrieve the block pointer from the cursor at the given level.
343  * This may be a bmap btree root or from a buffer.
344  */
345 xfs_btree_block_t *                     /* generic btree block pointer */
346 xfs_btree_get_block(
347         xfs_btree_cur_t         *cur,   /* btree cursor */
348         int                     level,  /* level in btree */
349         struct xfs_buf          **bpp); /* buffer containing the block */
350
351 /*
352  * Get a buffer for the block, return it with no data read.
353  * Long-form addressing.
354  */
355 struct xfs_buf *                                /* buffer for fsbno */
356 xfs_btree_get_bufl(
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 */
361
362 /*
363  * Get a buffer for the block, return it with no data read.
364  * Short-form addressing.
365  */
366 struct xfs_buf *                                /* buffer for agno/agbno */
367 xfs_btree_get_bufs(
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 */
373
374 /*
375  * Allocate a new btree cursor.
376  * The cursor is either for allocation (A) or bmap (B).
377  */
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 */
387
388 /*
389  * Check for the cursor referring to the last block at the given level.
390  */
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 */
395
396 /*
397  * Change the cursor to point to the last record in the current block
398  * at the given level.  Other levels are unaffected.
399  */
400 int                                     /* success=1, failure=0 */
401 xfs_btree_lastrec(
402         xfs_btree_cur_t         *cur,   /* btree cursor */
403         int                     level); /* level to change */
404
405 /*
406  * Compute first and last byte offsets for the fields given.
407  * Interprets the offsets table, which contains struct field offsets.
408  */
409 void
410 xfs_btree_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 */
416
417 /*
418  * Get a buffer for the block, return it read in.
419  * Long-form addressing.
420  */
421 int                                     /* error */
422 xfs_btree_read_bufl(
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 */
429
430 /*
431  * Get a buffer for the block, return it read in.
432  * Short-form addressing.
433  */
434 int                                     /* error */
435 xfs_btree_read_bufs(
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 */
443
444 /*
445  * Read-ahead the block, don't wait for it, don't return a buffer.
446  * Long-form addressing.
447  */
448 void                                    /* error */
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 */
453
454 /*
455  * Read-ahead the block, don't wait for it, don't return a buffer.
456  * Short-form addressing.
457  */
458 void                                    /* error */
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 */
464
465 /*
466  * Read-ahead btree blocks, at the given level.
467  * Bits in lr are set from XFS_BTCUR_{LEFT,RIGHT}RA.
468  */
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 */
474
475 static inline int                       /* readahead block count */
476 xfs_btree_readahead(
477         xfs_btree_cur_t         *cur,   /* btree cursor */
478         int                     lev,    /* level in btree */
479         int                     lr)     /* left/right bits */
480 {
481         if ((cur->bc_ra[lev] | lr) == cur->bc_ra[lev])
482                 return 0;
483
484         return xfs_btree_readahead_core(cur, lev, lr);
485 }
486
487
488 /*
489  * Set the buffer for level "lev" in the cursor to bp, releasing
490  * any previous buffer.
491  */
492 void
493 xfs_btree_setbuf(
494         xfs_btree_cur_t         *cur,   /* btree cursor */
495         int                     lev,    /* level in btree */
496         struct xfs_buf          *bp);   /* new buffer to set */
497
498 #endif  /* __KERNEL__ */
499
500
501 /*
502  * Min and max functions for extlen, agblock, fileoff, and filblks types.
503  */
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);
506 #endif
507
508 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MIN)
509 #define XFS_EXTLEN_MIN(a,b)     xfs_extlen_min(a,b)
510 #else
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))
514 #endif
515
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);
518 #endif
519
520 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_EXTLEN_MAX)
521 #define XFS_EXTLEN_MAX(a,b)     xfs_extlen_max(a,b)
522 #else
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))
526 #endif
527
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);
530 #endif
531
532 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MIN)
533 #define XFS_AGBLOCK_MIN(a,b)    xfs_agblock_min(a,b)
534 #else
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))
538 #endif
539
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);
542 #endif
543
544 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGBLOCK_MAX)
545 #define XFS_AGBLOCK_MAX(a,b)    xfs_agblock_max(a,b)
546 #else
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))
550 #endif
551
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);
554 #endif
555
556 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MIN)
557 #define XFS_FILEOFF_MIN(a,b)    xfs_fileoff_min(a,b)
558 #else
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))
562 #endif
563
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);
566 #endif
567
568 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILEOFF_MAX)
569 #define XFS_FILEOFF_MAX(a,b)    xfs_fileoff_max(a,b)
570 #else
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))
574 #endif
575
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);
578 #endif
579
580 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MIN)
581 #define XFS_FILBLKS_MIN(a,b)    xfs_filblks_min(a,b)
582 #else
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))
586 #endif
587
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);
590 #endif
591
592 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FILBLKS_MAX)
593 #define XFS_FILBLKS_MAX(a,b)    xfs_filblks_max(a,b)
594 #else
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))
598 #endif
599
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);
602 #endif
603
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)
606 #else
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)
610 #endif
611
612 /*
613  * Macros to set EFSCORRUPTED & return/branch.
614  */
615 #define XFS_WANT_CORRUPTED_GOTO(x,l)    \
616         { \
617                 int fs_is_ok = (x); \
618                 ASSERT(fs_is_ok); \
619                 if (unlikely(!fs_is_ok)) { \
620                         XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_GOTO", \
621                                          XFS_ERRLEVEL_LOW, NULL); \
622                         error = XFS_ERROR(EFSCORRUPTED); \
623                         goto l; \
624                 } \
625         }
626
627 #define XFS_WANT_CORRUPTED_RETURN(x)    \
628         { \
629                 int fs_is_ok = (x); \
630                 ASSERT(fs_is_ok); \
631                 if (unlikely(!fs_is_ok)) { \
632                         XFS_ERROR_REPORT("XFS_WANT_CORRUPTED_RETURN", \
633                                          XFS_ERRLEVEL_LOW, NULL); \
634                         return XFS_ERROR(EFSCORRUPTED); \
635                 } \
636         }
637
638 #endif  /* __XFS_BTREE_H__ */