xfs_alloc_btree.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Copyright (c) 2000 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_ALLOC_BTREE_H__
  33. #define __XFS_ALLOC_BTREE_H__
  34. /*
  35. * Freespace on-disk structures
  36. */
  37. struct xfs_buf;
  38. struct xfs_btree_cur;
  39. struct xfs_btree_sblock;
  40. struct xfs_mount;
  41. /*
  42. * There are two on-disk btrees, one sorted by blockno and one sorted
  43. * by blockcount and blockno. All blocks look the same to make the code
  44. * simpler; if we have time later, we'll make the optimizations.
  45. */
  46. #define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
  47. #define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
  48. /*
  49. * Data record/key structure
  50. */
  51. typedef struct xfs_alloc_rec
  52. {
  53. xfs_agblock_t ar_startblock; /* starting block number */
  54. xfs_extlen_t ar_blockcount; /* count of free blocks */
  55. } xfs_alloc_rec_t, xfs_alloc_key_t;
  56. typedef xfs_agblock_t xfs_alloc_ptr_t; /* btree pointer type */
  57. /* btree block header type */
  58. typedef struct xfs_btree_sblock xfs_alloc_block_t;
  59. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_ALLOC_BLOCK)
  60. xfs_alloc_block_t *xfs_buf_to_alloc_block(struct xfs_buf *bp);
  61. #define XFS_BUF_TO_ALLOC_BLOCK(bp) xfs_buf_to_alloc_block(bp)
  62. #else
  63. #define XFS_BUF_TO_ALLOC_BLOCK(bp) ((xfs_alloc_block_t *)(XFS_BUF_PTR(bp)))
  64. #endif
  65. /*
  66. * Real block structures have a size equal to the disk block size.
  67. */
  68. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_BLOCK_SIZE)
  69. int xfs_alloc_block_size(int lev, struct xfs_btree_cur *cur);
  70. #define XFS_ALLOC_BLOCK_SIZE(lev,cur) xfs_alloc_block_size(lev,cur)
  71. #else
  72. #define XFS_ALLOC_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
  73. #endif
  74. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_BLOCK_MAXRECS)
  75. int xfs_alloc_block_maxrecs(int lev, struct xfs_btree_cur *cur);
  76. #define XFS_ALLOC_BLOCK_MAXRECS(lev,cur) xfs_alloc_block_maxrecs(lev,cur)
  77. #else
  78. #define XFS_ALLOC_BLOCK_MAXRECS(lev,cur) \
  79. ((cur)->bc_mp->m_alloc_mxr[lev != 0])
  80. #endif
  81. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_BLOCK_MINRECS)
  82. int xfs_alloc_block_minrecs(int lev, struct xfs_btree_cur *cur);
  83. #define XFS_ALLOC_BLOCK_MINRECS(lev,cur) xfs_alloc_block_minrecs(lev,cur)
  84. #else
  85. #define XFS_ALLOC_BLOCK_MINRECS(lev,cur) \
  86. ((cur)->bc_mp->m_alloc_mnr[lev != 0])
  87. #endif
  88. /*
  89. * Minimum and maximum blocksize and sectorsize.
  90. * The blocksize upper limit is pretty much arbitrary.
  91. * The sectorsize upper limit is due to sizeof(sb_sectsize).
  92. */
  93. #define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
  94. #define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
  95. #define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
  96. #define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
  97. #define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
  98. #define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
  99. #define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
  100. #define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
  101. /*
  102. * Block numbers in the AG:
  103. * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
  104. */
  105. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BNO_BLOCK)
  106. xfs_agblock_t xfs_bno_block(struct xfs_mount *mp);
  107. #define XFS_BNO_BLOCK(mp) xfs_bno_block(mp)
  108. #else
  109. #define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
  110. #endif
  111. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CNT_BLOCK)
  112. xfs_agblock_t xfs_cnt_block(struct xfs_mount *mp);
  113. #define XFS_CNT_BLOCK(mp) xfs_cnt_block(mp)
  114. #else
  115. #define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
  116. #endif
  117. /*
  118. * Record, key, and pointer address macros for btree blocks.
  119. */
  120. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_REC_ADDR)
  121. xfs_alloc_rec_t *xfs_alloc_rec_addr(xfs_alloc_block_t *bb, int i,
  122. struct xfs_btree_cur *cur);
  123. #define XFS_ALLOC_REC_ADDR(bb,i,cur) xfs_alloc_rec_addr(bb,i,cur)
  124. #else
  125. #define XFS_ALLOC_REC_ADDR(bb,i,cur) \
  126. XFS_BTREE_REC_ADDR(XFS_ALLOC_BLOCK_SIZE(0,cur), xfs_alloc, bb, i, \
  127. XFS_ALLOC_BLOCK_MAXRECS(0, cur))
  128. #endif
  129. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_KEY_ADDR)
  130. xfs_alloc_key_t *xfs_alloc_key_addr(xfs_alloc_block_t *bb, int i,
  131. struct xfs_btree_cur *cur);
  132. #define XFS_ALLOC_KEY_ADDR(bb,i,cur) xfs_alloc_key_addr(bb,i,cur)
  133. #else
  134. #define XFS_ALLOC_KEY_ADDR(bb,i,cur) \
  135. XFS_BTREE_KEY_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, bb, i, \
  136. XFS_ALLOC_BLOCK_MAXRECS(1, cur))
  137. #endif
  138. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_ALLOC_PTR_ADDR)
  139. xfs_alloc_ptr_t *xfs_alloc_ptr_addr(xfs_alloc_block_t *bb, int i,
  140. struct xfs_btree_cur *cur);
  141. #define XFS_ALLOC_PTR_ADDR(bb,i,cur) xfs_alloc_ptr_addr(bb,i,cur)
  142. #else
  143. #define XFS_ALLOC_PTR_ADDR(bb,i,cur) \
  144. XFS_BTREE_PTR_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, bb, i, \
  145. XFS_ALLOC_BLOCK_MAXRECS(1, cur))
  146. #endif
  147. /*
  148. * Prototypes for externally visible routines.
  149. */
  150. /*
  151. * Decrement cursor by one record at the level.
  152. * For nonzero levels the leaf-ward information is untouched.
  153. */
  154. int /* error */
  155. xfs_alloc_decrement(
  156. struct xfs_btree_cur *cur, /* btree cursor */
  157. int level, /* level in btree, 0 is leaf */
  158. int *stat); /* success/failure */
  159. /*
  160. * Delete the record pointed to by cur.
  161. * The cursor refers to the place where the record was (could be inserted)
  162. * when the operation returns.
  163. */
  164. int /* error */
  165. xfs_alloc_delete(
  166. struct xfs_btree_cur *cur, /* btree cursor */
  167. int *stat); /* success/failure */
  168. /*
  169. * Get the data from the pointed-to record.
  170. */
  171. int /* error */
  172. xfs_alloc_get_rec(
  173. struct xfs_btree_cur *cur, /* btree cursor */
  174. xfs_agblock_t *bno, /* output: starting block of extent */
  175. xfs_extlen_t *len, /* output: length of extent */
  176. int *stat); /* output: success/failure */
  177. /*
  178. * Increment cursor by one record at the level.
  179. * For nonzero levels the leaf-ward information is untouched.
  180. */
  181. int /* error */
  182. xfs_alloc_increment(
  183. struct xfs_btree_cur *cur, /* btree cursor */
  184. int level, /* level in btree, 0 is leaf */
  185. int *stat); /* success/failure */
  186. /*
  187. * Insert the current record at the point referenced by cur.
  188. * The cursor may be inconsistent on return if splits have been done.
  189. */
  190. int /* error */
  191. xfs_alloc_insert(
  192. struct xfs_btree_cur *cur, /* btree cursor */
  193. int *stat); /* success/failure */
  194. /*
  195. * Lookup the record equal to [bno, len] in the btree given by cur.
  196. */
  197. int /* error */
  198. xfs_alloc_lookup_eq(
  199. struct xfs_btree_cur *cur, /* btree cursor */
  200. xfs_agblock_t bno, /* starting block of extent */
  201. xfs_extlen_t len, /* length of extent */
  202. int *stat); /* success/failure */
  203. /*
  204. * Lookup the first record greater than or equal to [bno, len]
  205. * in the btree given by cur.
  206. */
  207. int /* error */
  208. xfs_alloc_lookup_ge(
  209. struct xfs_btree_cur *cur, /* btree cursor */
  210. xfs_agblock_t bno, /* starting block of extent */
  211. xfs_extlen_t len, /* length of extent */
  212. int *stat); /* success/failure */
  213. /*
  214. * Lookup the first record less than or equal to [bno, len]
  215. * in the btree given by cur.
  216. */
  217. int /* error */
  218. xfs_alloc_lookup_le(
  219. struct xfs_btree_cur *cur, /* btree cursor */
  220. xfs_agblock_t bno, /* starting block of extent */
  221. xfs_extlen_t len, /* length of extent */
  222. int *stat); /* success/failure */
  223. /*
  224. * Update the record referred to by cur, to the value given by [bno, len].
  225. * This either works (return 0) or gets an EFSCORRUPTED error.
  226. */
  227. int /* error */
  228. xfs_alloc_update(
  229. struct xfs_btree_cur *cur, /* btree cursor */
  230. xfs_agblock_t bno, /* starting block of extent */
  231. xfs_extlen_t len); /* length of extent */
  232. #endif /* __XFS_ALLOC_BTREE_H__ */