xfs_btree.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_BTREE_H__
  19. #define __XFS_BTREE_H__
  20. struct xfs_buf;
  21. struct xfs_bmap_free;
  22. struct xfs_inode;
  23. struct xfs_mount;
  24. struct xfs_trans;
  25. extern kmem_zone_t *xfs_btree_cur_zone;
  26. /*
  27. * This nonsense is to make -wlint happy.
  28. */
  29. #define XFS_LOOKUP_EQ ((xfs_lookup_t)XFS_LOOKUP_EQi)
  30. #define XFS_LOOKUP_LE ((xfs_lookup_t)XFS_LOOKUP_LEi)
  31. #define XFS_LOOKUP_GE ((xfs_lookup_t)XFS_LOOKUP_GEi)
  32. #define XFS_BTNUM_BNO ((xfs_btnum_t)XFS_BTNUM_BNOi)
  33. #define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi)
  34. #define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi)
  35. #define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi)
  36. /*
  37. * Short form header: space allocation btrees.
  38. */
  39. typedef struct xfs_btree_sblock {
  40. __be32 bb_magic; /* magic number for block type */
  41. __be16 bb_level; /* 0 is a leaf */
  42. __be16 bb_numrecs; /* current # of data records */
  43. __be32 bb_leftsib; /* left sibling block or NULLAGBLOCK */
  44. __be32 bb_rightsib; /* right sibling block or NULLAGBLOCK */
  45. } xfs_btree_sblock_t;
  46. /*
  47. * Long form header: bmap btrees.
  48. */
  49. typedef struct xfs_btree_lblock {
  50. __be32 bb_magic; /* magic number for block type */
  51. __be16 bb_level; /* 0 is a leaf */
  52. __be16 bb_numrecs; /* current # of data records */
  53. __be64 bb_leftsib; /* left sibling block or NULLDFSBNO */
  54. __be64 bb_rightsib; /* right sibling block or NULLDFSBNO */
  55. } xfs_btree_lblock_t;
  56. /*
  57. * Combined header and structure, used by common code.
  58. */
  59. typedef struct xfs_btree_block {
  60. __be32 bb_magic; /* magic number for block type */
  61. __be16 bb_level; /* 0 is a leaf */
  62. __be16 bb_numrecs; /* current # of data records */
  63. union {
  64. struct {
  65. __be32 bb_leftsib;
  66. __be32 bb_rightsib;
  67. } s; /* short form pointers */
  68. struct {
  69. __be64 bb_leftsib;
  70. __be64 bb_rightsib;
  71. } l; /* long form pointers */
  72. } bb_u; /* rest */
  73. } xfs_btree_block_t;
  74. /*
  75. * Generic key, ptr and record wrapper structures.
  76. *
  77. * These are disk format structures, and are converted where necessary
  78. * by the btree specific code that needs to interpret them.
  79. */
  80. union xfs_btree_ptr {
  81. __be32 s; /* short form ptr */
  82. __be64 l; /* long form ptr */
  83. };
  84. union xfs_btree_key {
  85. xfs_bmbt_key_t bmbt;
  86. xfs_bmdr_key_t bmbr; /* bmbt root block */
  87. xfs_alloc_key_t alloc;
  88. xfs_inobt_key_t inobt;
  89. };
  90. union xfs_btree_rec {
  91. xfs_bmbt_rec_t bmbt;
  92. xfs_bmdr_rec_t bmbr; /* bmbt root block */
  93. xfs_alloc_rec_t alloc;
  94. xfs_inobt_rec_t inobt;
  95. };
  96. /*
  97. * For logging record fields.
  98. */
  99. #define XFS_BB_MAGIC 0x01
  100. #define XFS_BB_LEVEL 0x02
  101. #define XFS_BB_NUMRECS 0x04
  102. #define XFS_BB_LEFTSIB 0x08
  103. #define XFS_BB_RIGHTSIB 0x10
  104. #define XFS_BB_NUM_BITS 5
  105. #define XFS_BB_ALL_BITS ((1 << XFS_BB_NUM_BITS) - 1)
  106. /*
  107. * Magic numbers for btree blocks.
  108. */
  109. extern const __uint32_t xfs_magics[];
  110. /*
  111. * Generic stats interface
  112. */
  113. #define __XFS_BTREE_STATS_INC(type, stat) \
  114. XFS_STATS_INC(xs_ ## type ## _2_ ## stat)
  115. #define XFS_BTREE_STATS_INC(cur, stat) \
  116. do { \
  117. switch (cur->bc_btnum) { \
  118. case XFS_BTNUM_BNO: __XFS_BTREE_STATS_INC(abtb, stat); break; \
  119. case XFS_BTNUM_CNT: __XFS_BTREE_STATS_INC(abtc, stat); break; \
  120. case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_INC(bmbt, stat); break; \
  121. case XFS_BTNUM_INO: __XFS_BTREE_STATS_INC(ibt, stat); break; \
  122. case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
  123. } \
  124. } while (0)
  125. #define __XFS_BTREE_STATS_ADD(type, stat, val) \
  126. XFS_STATS_ADD(xs_ ## type ## _2_ ## stat, val)
  127. #define XFS_BTREE_STATS_ADD(cur, stat, val) \
  128. do { \
  129. switch (cur->bc_btnum) { \
  130. case XFS_BTNUM_BNO: __XFS_BTREE_STATS_ADD(abtb, stat, val); break; \
  131. case XFS_BTNUM_CNT: __XFS_BTREE_STATS_ADD(abtc, stat, val); break; \
  132. case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_ADD(bmbt, stat, val); break; \
  133. case XFS_BTNUM_INO: __XFS_BTREE_STATS_ADD(ibt, stat, val); break; \
  134. case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
  135. } \
  136. } while (0)
  137. /*
  138. * Maximum and minimum records in a btree block.
  139. * Given block size, type prefix, and leaf flag (0 or 1).
  140. * The divisor below is equivalent to lf ? (e1) : (e2) but that produces
  141. * compiler warnings.
  142. */
  143. #define XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf) \
  144. ((int)(((bsz) - (uint)sizeof(t ## _block_t)) / \
  145. (((lf) * (uint)sizeof(t ## _rec_t)) + \
  146. ((1 - (lf)) * \
  147. ((uint)sizeof(t ## _key_t) + (uint)sizeof(t ## _ptr_t))))))
  148. #define XFS_BTREE_BLOCK_MINRECS(bsz,t,lf) \
  149. (XFS_BTREE_BLOCK_MAXRECS(bsz,t,lf) / 2)
  150. /*
  151. * Record, key, and pointer address calculation macros.
  152. * Given block size, type prefix, block pointer, and index of requested entry
  153. * (first entry numbered 1).
  154. */
  155. #define XFS_BTREE_REC_ADDR(t,bb,i) \
  156. ((t ## _rec_t *)((char *)(bb) + sizeof(t ## _block_t) + \
  157. ((i) - 1) * sizeof(t ## _rec_t)))
  158. #define XFS_BTREE_KEY_ADDR(t,bb,i) \
  159. ((t ## _key_t *)((char *)(bb) + sizeof(t ## _block_t) + \
  160. ((i) - 1) * sizeof(t ## _key_t)))
  161. #define XFS_BTREE_PTR_ADDR(t,bb,i,mxr) \
  162. ((t ## _ptr_t *)((char *)(bb) + sizeof(t ## _block_t) + \
  163. (mxr) * sizeof(t ## _key_t) + ((i) - 1) * sizeof(t ## _ptr_t)))
  164. #define XFS_BTREE_MAXLEVELS 8 /* max of all btrees */
  165. struct xfs_btree_ops {
  166. /* size of the key and record structures */
  167. size_t key_len;
  168. size_t rec_len;
  169. /* cursor operations */
  170. struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *);
  171. void (*update_cursor)(struct xfs_btree_cur *src,
  172. struct xfs_btree_cur *dst);
  173. /* update btree root pointer */
  174. void (*set_root)(struct xfs_btree_cur *cur,
  175. union xfs_btree_ptr *nptr, int level_change);
  176. int (*kill_root)(struct xfs_btree_cur *cur, struct xfs_buf *bp,
  177. int level, union xfs_btree_ptr *newroot);
  178. /* block allocation / freeing */
  179. int (*alloc_block)(struct xfs_btree_cur *cur,
  180. union xfs_btree_ptr *start_bno,
  181. union xfs_btree_ptr *new_bno,
  182. int length, int *stat);
  183. int (*free_block)(struct xfs_btree_cur *cur, struct xfs_buf *bp);
  184. /* update last record information */
  185. void (*update_lastrec)(struct xfs_btree_cur *cur,
  186. struct xfs_btree_block *block,
  187. union xfs_btree_rec *rec,
  188. int ptr, int reason);
  189. /* records in block/level */
  190. int (*get_minrecs)(struct xfs_btree_cur *cur, int level);
  191. int (*get_maxrecs)(struct xfs_btree_cur *cur, int level);
  192. /* records on disk. Matter for the root in inode case. */
  193. int (*get_dmaxrecs)(struct xfs_btree_cur *cur, int level);
  194. /* init values of btree structures */
  195. void (*init_key_from_rec)(union xfs_btree_key *key,
  196. union xfs_btree_rec *rec);
  197. void (*init_rec_from_key)(union xfs_btree_key *key,
  198. union xfs_btree_rec *rec);
  199. void (*init_rec_from_cur)(struct xfs_btree_cur *cur,
  200. union xfs_btree_rec *rec);
  201. void (*init_ptr_from_cur)(struct xfs_btree_cur *cur,
  202. union xfs_btree_ptr *ptr);
  203. /* difference between key value and cursor value */
  204. __int64_t (*key_diff)(struct xfs_btree_cur *cur,
  205. union xfs_btree_key *key);
  206. /* btree tracing */
  207. #ifdef XFS_BTREE_TRACE
  208. void (*trace_enter)(struct xfs_btree_cur *, const char *,
  209. char *, int, int, __psunsigned_t,
  210. __psunsigned_t, __psunsigned_t,
  211. __psunsigned_t, __psunsigned_t,
  212. __psunsigned_t, __psunsigned_t,
  213. __psunsigned_t, __psunsigned_t,
  214. __psunsigned_t, __psunsigned_t);
  215. void (*trace_cursor)(struct xfs_btree_cur *, __uint32_t *,
  216. __uint64_t *, __uint64_t *);
  217. void (*trace_key)(struct xfs_btree_cur *,
  218. union xfs_btree_key *, __uint64_t *,
  219. __uint64_t *);
  220. void (*trace_record)(struct xfs_btree_cur *,
  221. union xfs_btree_rec *, __uint64_t *,
  222. __uint64_t *, __uint64_t *);
  223. #endif
  224. };
  225. /*
  226. * Reasons for the update_lastrec method to be called.
  227. */
  228. #define LASTREC_UPDATE 0
  229. #define LASTREC_INSREC 1
  230. #define LASTREC_DELREC 2
  231. /*
  232. * Btree cursor structure.
  233. * This collects all information needed by the btree code in one place.
  234. */
  235. typedef struct xfs_btree_cur
  236. {
  237. struct xfs_trans *bc_tp; /* transaction we're in, if any */
  238. struct xfs_mount *bc_mp; /* file system mount struct */
  239. const struct xfs_btree_ops *bc_ops;
  240. uint bc_flags; /* btree features - below */
  241. union {
  242. xfs_alloc_rec_incore_t a;
  243. xfs_bmbt_irec_t b;
  244. xfs_inobt_rec_incore_t i;
  245. } bc_rec; /* current insert/search record value */
  246. struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS]; /* buf ptr per level */
  247. int bc_ptrs[XFS_BTREE_MAXLEVELS]; /* key/record # */
  248. __uint8_t bc_ra[XFS_BTREE_MAXLEVELS]; /* readahead bits */
  249. #define XFS_BTCUR_LEFTRA 1 /* left sibling has been read-ahead */
  250. #define XFS_BTCUR_RIGHTRA 2 /* right sibling has been read-ahead */
  251. __uint8_t bc_nlevels; /* number of levels in the tree */
  252. __uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */
  253. xfs_btnum_t bc_btnum; /* identifies which btree type */
  254. union {
  255. struct { /* needed for BNO, CNT, INO */
  256. struct xfs_buf *agbp; /* agf/agi buffer pointer */
  257. xfs_agnumber_t agno; /* ag number */
  258. } a;
  259. struct { /* needed for BMAP */
  260. struct xfs_inode *ip; /* pointer to our inode */
  261. struct xfs_bmap_free *flist; /* list to free after */
  262. xfs_fsblock_t firstblock; /* 1st blk allocated */
  263. int allocated; /* count of alloced */
  264. short forksize; /* fork's inode space */
  265. char whichfork; /* data or attr fork */
  266. char flags; /* flags */
  267. #define XFS_BTCUR_BPRV_WASDEL 1 /* was delayed */
  268. } b;
  269. } bc_private; /* per-btree type data */
  270. } xfs_btree_cur_t;
  271. /* cursor flags */
  272. #define XFS_BTREE_LONG_PTRS (1<<0) /* pointers are 64bits long */
  273. #define XFS_BTREE_ROOT_IN_INODE (1<<1) /* root may be variable size */
  274. #define XFS_BTREE_LASTREC_UPDATE (1<<2) /* track last rec externally */
  275. #define XFS_BTREE_NOERROR 0
  276. #define XFS_BTREE_ERROR 1
  277. /*
  278. * Convert from buffer to btree block header.
  279. */
  280. #define XFS_BUF_TO_BLOCK(bp) ((xfs_btree_block_t *)XFS_BUF_PTR(bp))
  281. #define XFS_BUF_TO_LBLOCK(bp) ((xfs_btree_lblock_t *)XFS_BUF_PTR(bp))
  282. #define XFS_BUF_TO_SBLOCK(bp) ((xfs_btree_sblock_t *)XFS_BUF_PTR(bp))
  283. #ifdef __KERNEL__
  284. /*
  285. * Check that long form block header is ok.
  286. */
  287. int /* error (0 or EFSCORRUPTED) */
  288. xfs_btree_check_lblock(
  289. struct xfs_btree_cur *cur, /* btree cursor */
  290. struct xfs_btree_lblock *block, /* btree long form block pointer */
  291. int level, /* level of the btree block */
  292. struct xfs_buf *bp); /* buffer containing block, if any */
  293. /*
  294. * Check that short form block header is ok.
  295. */
  296. int /* error (0 or EFSCORRUPTED) */
  297. xfs_btree_check_sblock(
  298. struct xfs_btree_cur *cur, /* btree cursor */
  299. struct xfs_btree_sblock *block, /* btree short form block pointer */
  300. int level, /* level of the btree block */
  301. struct xfs_buf *bp); /* buffer containing block */
  302. /*
  303. * Check that block header is ok.
  304. */
  305. int
  306. xfs_btree_check_block(
  307. struct xfs_btree_cur *cur, /* btree cursor */
  308. struct xfs_btree_block *block, /* generic btree block pointer */
  309. int level, /* level of the btree block */
  310. struct xfs_buf *bp); /* buffer containing block, if any */
  311. /*
  312. * Check that (long) pointer is ok.
  313. */
  314. int /* error (0 or EFSCORRUPTED) */
  315. xfs_btree_check_lptr(
  316. struct xfs_btree_cur *cur, /* btree cursor */
  317. xfs_dfsbno_t ptr, /* btree block disk address */
  318. int level); /* btree block level */
  319. #define xfs_btree_check_lptr_disk(cur, ptr, level) \
  320. xfs_btree_check_lptr(cur, be64_to_cpu(ptr), level)
  321. /*
  322. * Check that (short) pointer is ok.
  323. */
  324. int /* error (0 or EFSCORRUPTED) */
  325. xfs_btree_check_sptr(
  326. struct xfs_btree_cur *cur, /* btree cursor */
  327. xfs_agblock_t ptr, /* btree block disk address */
  328. int level); /* btree block level */
  329. /*
  330. * Check that (short) pointer is ok.
  331. */
  332. int /* error (0 or EFSCORRUPTED) */
  333. xfs_btree_check_ptr(
  334. struct xfs_btree_cur *cur, /* btree cursor */
  335. union xfs_btree_ptr *ptr, /* btree block disk address */
  336. int index, /* offset from ptr to check */
  337. int level); /* btree block level */
  338. #ifdef DEBUG
  339. /*
  340. * Debug routine: check that keys are in the right order.
  341. */
  342. void
  343. xfs_btree_check_key(
  344. xfs_btnum_t btnum, /* btree identifier */
  345. void *ak1, /* pointer to left (lower) key */
  346. void *ak2); /* pointer to right (higher) key */
  347. /*
  348. * Debug routine: check that records are in the right order.
  349. */
  350. void
  351. xfs_btree_check_rec(
  352. xfs_btnum_t btnum, /* btree identifier */
  353. void *ar1, /* pointer to left (lower) record */
  354. void *ar2); /* pointer to right (higher) record */
  355. #else
  356. #define xfs_btree_check_key(a, b, c)
  357. #define xfs_btree_check_rec(a, b, c)
  358. #endif /* DEBUG */
  359. /*
  360. * Delete the btree cursor.
  361. */
  362. void
  363. xfs_btree_del_cursor(
  364. xfs_btree_cur_t *cur, /* btree cursor */
  365. int error); /* del because of error */
  366. /*
  367. * Duplicate the btree cursor.
  368. * Allocate a new one, copy the record, re-get the buffers.
  369. */
  370. int /* error */
  371. xfs_btree_dup_cursor(
  372. xfs_btree_cur_t *cur, /* input cursor */
  373. xfs_btree_cur_t **ncur);/* output cursor */
  374. /*
  375. * Change the cursor to point to the first record in the current block
  376. * at the given level. Other levels are unaffected.
  377. */
  378. int /* success=1, failure=0 */
  379. xfs_btree_firstrec(
  380. xfs_btree_cur_t *cur, /* btree cursor */
  381. int level); /* level to change */
  382. /*
  383. * Get a buffer for the block, return it with no data read.
  384. * Long-form addressing.
  385. */
  386. struct xfs_buf * /* buffer for fsbno */
  387. xfs_btree_get_bufl(
  388. struct xfs_mount *mp, /* file system mount point */
  389. struct xfs_trans *tp, /* transaction pointer */
  390. xfs_fsblock_t fsbno, /* file system block number */
  391. uint lock); /* lock flags for get_buf */
  392. /*
  393. * Get a buffer for the block, return it with no data read.
  394. * Short-form addressing.
  395. */
  396. struct xfs_buf * /* buffer for agno/agbno */
  397. xfs_btree_get_bufs(
  398. struct xfs_mount *mp, /* file system mount point */
  399. struct xfs_trans *tp, /* transaction pointer */
  400. xfs_agnumber_t agno, /* allocation group number */
  401. xfs_agblock_t agbno, /* allocation group block number */
  402. uint lock); /* lock flags for get_buf */
  403. /*
  404. * Check for the cursor referring to the last block at the given level.
  405. */
  406. int /* 1=is last block, 0=not last block */
  407. xfs_btree_islastblock(
  408. xfs_btree_cur_t *cur, /* btree cursor */
  409. int level); /* level to check */
  410. /*
  411. * Change the cursor to point to the last record in the current block
  412. * at the given level. Other levels are unaffected.
  413. */
  414. int /* success=1, failure=0 */
  415. xfs_btree_lastrec(
  416. xfs_btree_cur_t *cur, /* btree cursor */
  417. int level); /* level to change */
  418. /*
  419. * Compute first and last byte offsets for the fields given.
  420. * Interprets the offsets table, which contains struct field offsets.
  421. */
  422. void
  423. xfs_btree_offsets(
  424. __int64_t fields, /* bitmask of fields */
  425. const short *offsets,/* table of field offsets */
  426. int nbits, /* number of bits to inspect */
  427. int *first, /* output: first byte offset */
  428. int *last); /* output: last byte offset */
  429. /*
  430. * Get a buffer for the block, return it read in.
  431. * Long-form addressing.
  432. */
  433. int /* error */
  434. xfs_btree_read_bufl(
  435. struct xfs_mount *mp, /* file system mount point */
  436. struct xfs_trans *tp, /* transaction pointer */
  437. xfs_fsblock_t fsbno, /* file system block number */
  438. uint lock, /* lock flags for read_buf */
  439. struct xfs_buf **bpp, /* buffer for fsbno */
  440. int refval);/* ref count value for buffer */
  441. /*
  442. * Get a buffer for the block, return it read in.
  443. * Short-form addressing.
  444. */
  445. int /* error */
  446. xfs_btree_read_bufs(
  447. struct xfs_mount *mp, /* file system mount point */
  448. struct xfs_trans *tp, /* transaction pointer */
  449. xfs_agnumber_t agno, /* allocation group number */
  450. xfs_agblock_t agbno, /* allocation group block number */
  451. uint lock, /* lock flags for read_buf */
  452. struct xfs_buf **bpp, /* buffer for agno/agbno */
  453. int refval);/* ref count value for buffer */
  454. /*
  455. * Read-ahead the block, don't wait for it, don't return a buffer.
  456. * Long-form addressing.
  457. */
  458. void /* error */
  459. xfs_btree_reada_bufl(
  460. struct xfs_mount *mp, /* file system mount point */
  461. xfs_fsblock_t fsbno, /* file system block number */
  462. xfs_extlen_t count); /* count of filesystem blocks */
  463. /*
  464. * Read-ahead the block, don't wait for it, don't return a buffer.
  465. * Short-form addressing.
  466. */
  467. void /* error */
  468. xfs_btree_reada_bufs(
  469. struct xfs_mount *mp, /* file system mount point */
  470. xfs_agnumber_t agno, /* allocation group number */
  471. xfs_agblock_t agbno, /* allocation group block number */
  472. xfs_extlen_t count); /* count of filesystem blocks */
  473. /*
  474. * Read-ahead btree blocks, at the given level.
  475. * Bits in lr are set from XFS_BTCUR_{LEFT,RIGHT}RA.
  476. */
  477. int /* readahead block count */
  478. xfs_btree_readahead(
  479. xfs_btree_cur_t *cur, /* btree cursor */
  480. int lev, /* level in btree */
  481. int lr); /* left/right bits */
  482. /*
  483. * Set the buffer for level "lev" in the cursor to bp, releasing
  484. * any previous buffer.
  485. */
  486. void
  487. xfs_btree_setbuf(
  488. xfs_btree_cur_t *cur, /* btree cursor */
  489. int lev, /* level in btree */
  490. struct xfs_buf *bp); /* new buffer to set */
  491. /*
  492. * Common btree core entry points.
  493. */
  494. int xfs_btree_increment(struct xfs_btree_cur *, int, int *);
  495. int xfs_btree_decrement(struct xfs_btree_cur *, int, int *);
  496. int xfs_btree_lookup(struct xfs_btree_cur *, xfs_lookup_t, int *);
  497. int xfs_btree_updkey(struct xfs_btree_cur *, union xfs_btree_key *, int);
  498. int xfs_btree_update(struct xfs_btree_cur *, union xfs_btree_rec *);
  499. int xfs_btree_lshift(struct xfs_btree_cur *, int, int *);
  500. int xfs_btree_rshift(struct xfs_btree_cur *, int, int *);
  501. int xfs_btree_split(struct xfs_btree_cur *, int, union xfs_btree_ptr *,
  502. union xfs_btree_key *, struct xfs_btree_cur **, int *);
  503. int xfs_btree_new_root(struct xfs_btree_cur *, int *);
  504. int xfs_btree_new_iroot(struct xfs_btree_cur *, int *, int *);
  505. int xfs_btree_kill_iroot(struct xfs_btree_cur *);
  506. int xfs_btree_insert(struct xfs_btree_cur *, int *);
  507. int xfs_btree_delete(struct xfs_btree_cur *, int *);
  508. int xfs_btree_get_rec(struct xfs_btree_cur *, union xfs_btree_rec **, int *);
  509. /*
  510. * Internal btree helpers also used by xfs_bmap.c.
  511. */
  512. void xfs_btree_log_block(struct xfs_btree_cur *, struct xfs_buf *, int);
  513. void xfs_btree_log_recs(struct xfs_btree_cur *, struct xfs_buf *, int, int);
  514. /*
  515. * Helpers.
  516. */
  517. static inline int xfs_btree_get_numrecs(struct xfs_btree_block *block)
  518. {
  519. return be16_to_cpu(block->bb_numrecs);
  520. }
  521. static inline void xfs_btree_set_numrecs(struct xfs_btree_block *block,
  522. __uint16_t numrecs)
  523. {
  524. block->bb_numrecs = cpu_to_be16(numrecs);
  525. }
  526. static inline int xfs_btree_get_level(struct xfs_btree_block *block)
  527. {
  528. return be16_to_cpu(block->bb_level);
  529. }
  530. #endif /* __KERNEL__ */
  531. /*
  532. * Min and max functions for extlen, agblock, fileoff, and filblks types.
  533. */
  534. #define XFS_EXTLEN_MIN(a,b) min_t(xfs_extlen_t, (a), (b))
  535. #define XFS_EXTLEN_MAX(a,b) max_t(xfs_extlen_t, (a), (b))
  536. #define XFS_AGBLOCK_MIN(a,b) min_t(xfs_agblock_t, (a), (b))
  537. #define XFS_AGBLOCK_MAX(a,b) max_t(xfs_agblock_t, (a), (b))
  538. #define XFS_FILEOFF_MIN(a,b) min_t(xfs_fileoff_t, (a), (b))
  539. #define XFS_FILEOFF_MAX(a,b) max_t(xfs_fileoff_t, (a), (b))
  540. #define XFS_FILBLKS_MIN(a,b) min_t(xfs_filblks_t, (a), (b))
  541. #define XFS_FILBLKS_MAX(a,b) max_t(xfs_filblks_t, (a), (b))
  542. #define XFS_FSB_SANITY_CHECK(mp,fsb) \
  543. (XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \
  544. XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks)
  545. #endif /* __XFS_BTREE_H__ */