xfs_btree.h 18 KB

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