xfs_ialloc_btree.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. #define XFS_INOBT_IS_FREE_DISK(rp,i) xfs_inobt_is_free_disk(rp,i)
  95. #else
  96. #define XFS_INOBT_IS_FREE(rp,i) \
  97. (((rp)->ir_free & XFS_INOBT_MASK(i)) != 0)
  98. #define XFS_INOBT_IS_FREE_DISK(rp,i) \
  99. ((INT_GET((rp)->ir_free, ARCH_CONVERT) & XFS_INOBT_MASK(i)) != 0)
  100. #endif
  101. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_SET_FREE)
  102. void xfs_inobt_set_free(xfs_inobt_rec_t *rp, int i);
  103. #define XFS_INOBT_SET_FREE(rp,i) xfs_inobt_set_free(rp,i)
  104. #else
  105. #define XFS_INOBT_SET_FREE(rp,i) ((rp)->ir_free |= XFS_INOBT_MASK(i))
  106. #endif
  107. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_CLR_FREE)
  108. void xfs_inobt_clr_free(xfs_inobt_rec_t *rp, int i);
  109. #define XFS_INOBT_CLR_FREE(rp,i) xfs_inobt_clr_free(rp,i)
  110. #else
  111. #define XFS_INOBT_CLR_FREE(rp,i) ((rp)->ir_free &= ~XFS_INOBT_MASK(i))
  112. #endif
  113. /*
  114. * Real block structures have a size equal to the disk block size.
  115. */
  116. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_SIZE)
  117. int xfs_inobt_block_size(int lev, struct xfs_btree_cur *cur);
  118. #define XFS_INOBT_BLOCK_SIZE(lev,cur) xfs_inobt_block_size(lev,cur)
  119. #else
  120. #define XFS_INOBT_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
  121. #endif
  122. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MAXRECS)
  123. int xfs_inobt_block_maxrecs(int lev, struct xfs_btree_cur *cur);
  124. #define XFS_INOBT_BLOCK_MAXRECS(lev,cur) xfs_inobt_block_maxrecs(lev,cur)
  125. #else
  126. #define XFS_INOBT_BLOCK_MAXRECS(lev,cur) \
  127. ((cur)->bc_mp->m_inobt_mxr[lev != 0])
  128. #endif
  129. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_BLOCK_MINRECS)
  130. int xfs_inobt_block_minrecs(int lev, struct xfs_btree_cur *cur);
  131. #define XFS_INOBT_BLOCK_MINRECS(lev,cur) xfs_inobt_block_minrecs(lev,cur)
  132. #else
  133. #define XFS_INOBT_BLOCK_MINRECS(lev,cur) \
  134. ((cur)->bc_mp->m_inobt_mnr[lev != 0])
  135. #endif
  136. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_IS_LAST_REC)
  137. int xfs_inobt_is_last_rec(struct xfs_btree_cur *cur);
  138. #define XFS_INOBT_IS_LAST_REC(cur) xfs_inobt_is_last_rec(cur)
  139. #else
  140. #define XFS_INOBT_IS_LAST_REC(cur) \
  141. ((cur)->bc_ptrs[0] == \
  142. INT_GET(XFS_BUF_TO_INOBT_BLOCK((cur)->bc_bufs[0])->bb_numrecs, ARCH_CONVERT))
  143. #endif
  144. /*
  145. * Maximum number of inode btree levels.
  146. */
  147. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IN_MAXLEVELS)
  148. int xfs_in_maxlevels(struct xfs_mount *mp);
  149. #define XFS_IN_MAXLEVELS(mp) xfs_in_maxlevels(mp)
  150. #else
  151. #define XFS_IN_MAXLEVELS(mp) ((mp)->m_in_maxlevels)
  152. #endif
  153. /*
  154. * block numbers in the AG.
  155. */
  156. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_IBT_BLOCK)
  157. xfs_agblock_t xfs_ibt_block(struct xfs_mount *mp);
  158. #define XFS_IBT_BLOCK(mp) xfs_ibt_block(mp)
  159. #else
  160. #define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
  161. #endif
  162. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_PREALLOC_BLOCKS)
  163. xfs_agblock_t xfs_prealloc_blocks(struct xfs_mount *mp);
  164. #define XFS_PREALLOC_BLOCKS(mp) xfs_prealloc_blocks(mp)
  165. #else
  166. #define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
  167. #endif
  168. /*
  169. * Record, key, and pointer address macros for btree blocks.
  170. */
  171. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_REC_ADDR)
  172. xfs_inobt_rec_t *
  173. xfs_inobt_rec_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
  174. #define XFS_INOBT_REC_ADDR(bb,i,cur) xfs_inobt_rec_addr(bb,i,cur)
  175. #else
  176. #define XFS_INOBT_REC_ADDR(bb,i,cur) \
  177. XFS_BTREE_REC_ADDR(XFS_INOBT_BLOCK_SIZE(0,cur), xfs_inobt, bb, i, \
  178. XFS_INOBT_BLOCK_MAXRECS(0, cur))
  179. #endif
  180. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_KEY_ADDR)
  181. xfs_inobt_key_t *
  182. xfs_inobt_key_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
  183. #define XFS_INOBT_KEY_ADDR(bb,i,cur) xfs_inobt_key_addr(bb,i,cur)
  184. #else
  185. #define XFS_INOBT_KEY_ADDR(bb,i,cur) \
  186. XFS_BTREE_KEY_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
  187. XFS_INOBT_BLOCK_MAXRECS(1, cur))
  188. #endif
  189. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_INOBT_PTR_ADDR)
  190. xfs_inobt_ptr_t *
  191. xfs_inobt_ptr_addr(xfs_inobt_block_t *bb, int i, struct xfs_btree_cur *cur);
  192. #define XFS_INOBT_PTR_ADDR(bb,i,cur) xfs_inobt_ptr_addr(bb,i,cur)
  193. #else
  194. #define XFS_INOBT_PTR_ADDR(bb,i,cur) \
  195. XFS_BTREE_PTR_ADDR(XFS_INOBT_BLOCK_SIZE(1,cur), xfs_inobt, bb, i, \
  196. XFS_INOBT_BLOCK_MAXRECS(1, cur))
  197. #endif
  198. /*
  199. * Prototypes for externally visible routines.
  200. */
  201. /*
  202. * Decrement cursor by one record at the level.
  203. * For nonzero levels the leaf-ward information is untouched.
  204. */
  205. int /* error */
  206. xfs_inobt_decrement(
  207. struct xfs_btree_cur *cur, /* btree cursor */
  208. int level, /* level in btree, 0 is leaf */
  209. int *stat); /* success/failure */
  210. /*
  211. * Delete the record pointed to by cur.
  212. * The cursor refers to the place where the record was (could be inserted)
  213. * when the operation returns.
  214. */
  215. int /* error */
  216. xfs_inobt_delete(
  217. struct xfs_btree_cur *cur, /* btree cursor */
  218. int *stat); /* success/failure */
  219. /*
  220. * Get the data from the pointed-to record.
  221. */
  222. int /* error */
  223. xfs_inobt_get_rec(
  224. struct xfs_btree_cur *cur, /* btree cursor */
  225. xfs_agino_t *ino, /* output: starting inode of chunk */
  226. __int32_t *fcnt, /* output: number of free inodes */
  227. xfs_inofree_t *free, /* output: free inode mask */
  228. int *stat); /* output: success/failure */
  229. /*
  230. * Increment cursor by one record at the level.
  231. * For nonzero levels the leaf-ward information is untouched.
  232. */
  233. int /* error */
  234. xfs_inobt_increment(
  235. struct xfs_btree_cur *cur, /* btree cursor */
  236. int level, /* level in btree, 0 is leaf */
  237. int *stat); /* success/failure */
  238. /*
  239. * Insert the current record at the point referenced by cur.
  240. * The cursor may be inconsistent on return if splits have been done.
  241. */
  242. int /* error */
  243. xfs_inobt_insert(
  244. struct xfs_btree_cur *cur, /* btree cursor */
  245. int *stat); /* success/failure */
  246. /*
  247. * Lookup the record equal to ino in the btree given by cur.
  248. */
  249. int /* error */
  250. xfs_inobt_lookup_eq(
  251. struct xfs_btree_cur *cur, /* btree cursor */
  252. xfs_agino_t ino, /* starting inode of chunk */
  253. __int32_t fcnt, /* free inode count */
  254. xfs_inofree_t free, /* free inode mask */
  255. int *stat); /* success/failure */
  256. /*
  257. * Lookup the first record greater than or equal to ino
  258. * in the btree given by cur.
  259. */
  260. int /* error */
  261. xfs_inobt_lookup_ge(
  262. struct xfs_btree_cur *cur, /* btree cursor */
  263. xfs_agino_t ino, /* starting inode of chunk */
  264. __int32_t fcnt, /* free inode count */
  265. xfs_inofree_t free, /* free inode mask */
  266. int *stat); /* success/failure */
  267. /*
  268. * Lookup the first record less than or equal to ino
  269. * in the btree given by cur.
  270. */
  271. int /* error */
  272. xfs_inobt_lookup_le(
  273. struct xfs_btree_cur *cur, /* btree cursor */
  274. xfs_agino_t ino, /* starting inode of chunk */
  275. __int32_t fcnt, /* free inode count */
  276. xfs_inofree_t free, /* free inode mask */
  277. int *stat); /* success/failure */
  278. /*
  279. * Update the record referred to by cur, to the value given
  280. * by [ino, fcnt, free].
  281. * This either works (return 0) or gets an EFSCORRUPTED error.
  282. */
  283. int /* error */
  284. xfs_inobt_update(
  285. struct xfs_btree_cur *cur, /* btree cursor */
  286. xfs_agino_t ino, /* starting inode of chunk */
  287. __int32_t fcnt, /* free inode count */
  288. xfs_inofree_t free); /* free inode mask */
  289. #endif /* __XFS_IALLOC_BTREE_H__ */