xfs_ialloc_btree.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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_IALLOC_BTREE_H__
  33. #define __XFS_IALLOC_BTREE_H__
  34. /*
  35. * Inode map 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 is a btree for the inode map per allocation group.
  43. */
  44. #define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
  45. typedef __uint64_t xfs_inofree_t;
  46. #define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
  47. #define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3)
  48. #define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1)
  49. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_MASKN)
  50. xfs_inofree_t xfs_inobt_maskn(int i, int n);
  51. #define XFS_INOBT_MASKN(i,n) xfs_inobt_maskn(i,n)
  52. #else
  53. #define XFS_INOBT_MASKN(i,n) \
  54. ((((n) >= XFS_INODES_PER_CHUNK ? \
  55. (xfs_inofree_t)0 : ((xfs_inofree_t)1 << (n))) - 1) << (i))
  56. #endif
  57. /*
  58. * Data record structure
  59. */
  60. typedef struct xfs_inobt_rec
  61. {
  62. xfs_agino_t ir_startino; /* starting inode number */
  63. __int32_t ir_freecount; /* count of free inodes (set bits) */
  64. xfs_inofree_t ir_free; /* free inode mask */
  65. } xfs_inobt_rec_t;
  66. /*
  67. * Key structure
  68. */
  69. typedef struct xfs_inobt_key
  70. {
  71. xfs_agino_t ir_startino; /* starting inode number */
  72. } xfs_inobt_key_t;
  73. typedef xfs_agblock_t xfs_inobt_ptr_t; /* btree pointer type */
  74. /* btree block header type */
  75. typedef struct xfs_btree_sblock xfs_inobt_block_t;
  76. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_INOBT_BLOCK)
  77. xfs_inobt_block_t *xfs_buf_to_inobt_block(struct xfs_buf *bp);
  78. #define XFS_BUF_TO_INOBT_BLOCK(bp) xfs_buf_to_inobt_block(bp)
  79. #else
  80. #define XFS_BUF_TO_INOBT_BLOCK(bp) ((xfs_inobt_block_t *)(XFS_BUF_PTR(bp)))
  81. #endif
  82. /*
  83. * Bit manipulations for ir_free.
  84. */
  85. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_MASK)
  86. xfs_inofree_t xfs_inobt_mask(int i);
  87. #define XFS_INOBT_MASK(i) xfs_inobt_mask(i)
  88. #else
  89. #define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i))
  90. #endif
  91. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_IS_FREE)
  92. int xfs_inobt_is_free(xfs_inobt_rec_t *rp, int i);
  93. #define XFS_INOBT_IS_FREE(rp,i) xfs_inobt_is_free(rp,i)
  94. #else
  95. #define XFS_INOBT_IS_FREE(rp,i) (((rp)->ir_free & XFS_INOBT_MASK(i)) != 0)
  96. #endif
  97. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_SET_FREE)
  98. void xfs_inobt_set_free(xfs_inobt_rec_t *rp, int i);
  99. #define XFS_INOBT_SET_FREE(rp,i) xfs_inobt_set_free(rp,i)
  100. #else
  101. #define XFS_INOBT_SET_FREE(rp,i) ((rp)->ir_free |= XFS_INOBT_MASK(i))
  102. #endif
  103. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_CLR_FREE)
  104. void xfs_inobt_clr_free(xfs_inobt_rec_t *rp, int i);
  105. #define XFS_INOBT_CLR_FREE(rp,i) xfs_inobt_clr_free(rp,i)
  106. #else
  107. #define XFS_INOBT_CLR_FREE(rp,i) ((rp)->ir_free &= ~XFS_INOBT_MASK(i))
  108. #endif
  109. /*
  110. * Real block structures have a size equal to the disk block size.
  111. */
  112. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_SIZE)
  113. int xfs_inobt_block_size(int lev, struct xfs_btree_cur *cur);
  114. #define XFS_INOBT_BLOCK_SIZE(lev,cur) xfs_inobt_block_size(lev,cur)
  115. #else
  116. #define XFS_INOBT_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
  117. #endif
  118. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MAXRECS)
  119. int xfs_inobt_block_maxrecs(int lev, struct xfs_btree_cur *cur);
  120. #define XFS_INOBT_BLOCK_MAXRECS(lev,cur) xfs_inobt_block_maxrecs(lev,cur)
  121. #else
  122. #define XFS_INOBT_BLOCK_MAXRECS(lev,cur) \
  123. ((cur)->bc_mp->m_inobt_mxr[lev != 0])
  124. #endif
  125. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MINRECS)
  126. int xfs_inobt_block_minrecs(int lev, struct xfs_btree_cur *cur);
  127. #define XFS_INOBT_BLOCK_MINRECS(lev,cur) xfs_inobt_block_minrecs(lev,cur)
  128. #else
  129. #define XFS_INOBT_BLOCK_MINRECS(lev,cur) \
  130. ((cur)->bc_mp->m_inobt_mnr[lev != 0])
  131. #endif
  132. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_IS_LAST_REC)
  133. int xfs_inobt_is_last_rec(struct xfs_btree_cur *cur);
  134. #define XFS_INOBT_IS_LAST_REC(cur) xfs_inobt_is_last_rec(cur)
  135. #else
  136. #define XFS_INOBT_IS_LAST_REC(cur) \
  137. ((cur)->bc_ptrs[0] == \
  138. INT_GET(XFS_BUF_TO_INOBT_BLOCK((cur)->bc_bufs[0])->bb_numrecs, ARCH_CONVERT))
  139. #endif
  140. /*
  141. * Maximum number of inode btree levels.
  142. */
  143. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IN_MAXLEVELS)
  144. int xfs_in_maxlevels(struct xfs_mount *mp);
  145. #define XFS_IN_MAXLEVELS(mp) xfs_in_maxlevels(mp)
  146. #else
  147. #define XFS_IN_MAXLEVELS(mp) ((mp)->m_in_maxlevels)
  148. #endif
  149. /*
  150. * block numbers in the AG.
  151. */
  152. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IBT_BLOCK)
  153. xfs_agblock_t xfs_ibt_block(struct xfs_mount *mp);
  154. #define XFS_IBT_BLOCK(mp) xfs_ibt_block(mp)
  155. #else
  156. #define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
  157. #endif
  158. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_PREALLOC_BLOCKS)
  159. xfs_agblock_t xfs_prealloc_blocks(struct xfs_mount *mp);
  160. #define XFS_PREALLOC_BLOCKS(mp) xfs_prealloc_blocks(mp)
  161. #else
  162. #define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
  163. #endif
  164. /*
  165. * Record, key, and pointer address macros for btree blocks.
  166. */
  167. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_REC_ADDR)
  168. xfs_inobt_rec_t *
  169. xfs_inobt_rec_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
  170. #define XFS_INOBT_REC_ADDR(bb,i,cur) xfs_inobt_rec_addr(bb,i,cur)
  171. #else
  172. #define XFS_INOBT_REC_ADDR(bb,i,cur) \
  173. XFS_BTREE_REC_ADDR(XFS_INOBT_BLOCK_SIZE(0,cur), xfs_inobt, bb, i, \
  174. XFS_INOBT_BLOCK_MAXRECS(0, cur))
  175. #endif
  176. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_KEY_ADDR)
  177. xfs_inobt_key_t *
  178. xfs_inobt_key_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
  179. #define XFS_INOBT_KEY_ADDR(bb,i,cur) xfs_inobt_key_addr(bb,i,cur)
  180. #else
  181. #define XFS_INOBT_KEY_ADDR(bb,i,cur) \
  182. XFS_BTREE_KEY_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
  183. XFS_INOBT_BLOCK_MAXRECS(1, cur))
  184. #endif
  185. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_PTR_ADDR)
  186. xfs_inobt_ptr_t *
  187. xfs_inobt_ptr_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
  188. #define XFS_INOBT_PTR_ADDR(bb,i,cur) xfs_inobt_ptr_addr(bb,i,cur)
  189. #else
  190. #define XFS_INOBT_PTR_ADDR(bb,i,cur) \
  191. XFS_BTREE_PTR_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
  192. XFS_INOBT_BLOCK_MAXRECS(1, cur))
  193. #endif
  194. /*
  195. * Prototypes for externally visible routines.
  196. */
  197. /*
  198. * Decrement cursor by one record at the level.
  199. * For nonzero levels the leaf-ward information is untouched.
  200. */
  201. int /* error */
  202. xfs_inobt_decrement(
  203. struct xfs_btree_cur *cur, /* btree cursor */
  204. int level, /* level in btree, 0 is leaf */
  205. int *stat); /* success/failure */
  206. /*
  207. * Delete the record pointed to by cur.
  208. * The cursor refers to the place where the record was (could be inserted)
  209. * when the operation returns.
  210. */
  211. int /* error */
  212. xfs_inobt_delete(
  213. struct xfs_btree_cur *cur, /* btree cursor */
  214. int *stat); /* success/failure */
  215. /*
  216. * Get the data from the pointed-to record.
  217. */
  218. int /* error */
  219. xfs_inobt_get_rec(
  220. struct xfs_btree_cur *cur, /* btree cursor */
  221. xfs_agino_t *ino, /* output: starting inode of chunk */
  222. __int32_t *fcnt, /* output: number of free inodes */
  223. xfs_inofree_t *free, /* output: free inode mask */
  224. int *stat); /* output: success/failure */
  225. /*
  226. * Increment cursor by one record at the level.
  227. * For nonzero levels the leaf-ward information is untouched.
  228. */
  229. int /* error */
  230. xfs_inobt_increment(
  231. struct xfs_btree_cur *cur, /* btree cursor */
  232. int level, /* level in btree, 0 is leaf */
  233. int *stat); /* success/failure */
  234. /*
  235. * Insert the current record at the point referenced by cur.
  236. * The cursor may be inconsistent on return if splits have been done.
  237. */
  238. int /* error */
  239. xfs_inobt_insert(
  240. struct xfs_btree_cur *cur, /* btree cursor */
  241. int *stat); /* success/failure */
  242. /*
  243. * Lookup the record equal to ino in the btree given by cur.
  244. */
  245. int /* error */
  246. xfs_inobt_lookup_eq(
  247. struct xfs_btree_cur *cur, /* btree cursor */
  248. xfs_agino_t ino, /* starting inode of chunk */
  249. __int32_t fcnt, /* free inode count */
  250. xfs_inofree_t free, /* free inode mask */
  251. int *stat); /* success/failure */
  252. /*
  253. * Lookup the first record greater than or equal to ino
  254. * in the btree given by cur.
  255. */
  256. int /* error */
  257. xfs_inobt_lookup_ge(
  258. struct xfs_btree_cur *cur, /* btree cursor */
  259. xfs_agino_t ino, /* starting inode of chunk */
  260. __int32_t fcnt, /* free inode count */
  261. xfs_inofree_t free, /* free inode mask */
  262. int *stat); /* success/failure */
  263. /*
  264. * Lookup the first record less than or equal to ino
  265. * in the btree given by cur.
  266. */
  267. int /* error */
  268. xfs_inobt_lookup_le(
  269. struct xfs_btree_cur *cur, /* btree cursor */
  270. xfs_agino_t ino, /* starting inode of chunk */
  271. __int32_t fcnt, /* free inode count */
  272. xfs_inofree_t free, /* free inode mask */
  273. int *stat); /* success/failure */
  274. /*
  275. * Update the record referred to by cur, to the value given
  276. * by [ino, fcnt, free].
  277. * This either works (return 0) or gets an EFSCORRUPTED error.
  278. */
  279. int /* error */
  280. xfs_inobt_update(
  281. struct xfs_btree_cur *cur, /* btree cursor */
  282. xfs_agino_t ino, /* starting inode of chunk */
  283. __int32_t fcnt, /* free inode count */
  284. xfs_inofree_t free); /* free inode mask */
  285. #endif /* __XFS_IALLOC_BTREE_H__ */