xfs_ag.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2000-2003,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_AG_H__
  19. #define __XFS_AG_H__
  20. /*
  21. * Allocation group header
  22. * This is divided into three structures, placed in sequential 512-byte
  23. * buffers after a copy of the superblock (also in a 512-byte buffer).
  24. */
  25. struct xfs_buf;
  26. struct xfs_mount;
  27. struct xfs_trans;
  28. #define XFS_AGF_MAGIC 0x58414746 /* 'XAGF' */
  29. #define XFS_AGI_MAGIC 0x58414749 /* 'XAGI' */
  30. #define XFS_AGFL_MAGIC 0x5841464c /* 'XAFL' */
  31. #define XFS_AGF_VERSION 1
  32. #define XFS_AGI_VERSION 1
  33. #define XFS_AGF_GOOD_VERSION(v) ((v) == XFS_AGF_VERSION)
  34. #define XFS_AGI_GOOD_VERSION(v) ((v) == XFS_AGI_VERSION)
  35. /*
  36. * Btree number 0 is bno, 1 is cnt. This value gives the size of the
  37. * arrays below.
  38. */
  39. #define XFS_BTNUM_AGF ((int)XFS_BTNUM_CNTi + 1)
  40. /*
  41. * The second word of agf_levels in the first a.g. overlaps the EFS
  42. * superblock's magic number. Since the magic numbers valid for EFS
  43. * are > 64k, our value cannot be confused for an EFS superblock's.
  44. */
  45. typedef struct xfs_agf {
  46. /*
  47. * Common allocation group header information
  48. */
  49. __be32 agf_magicnum; /* magic number == XFS_AGF_MAGIC */
  50. __be32 agf_versionnum; /* header version == XFS_AGF_VERSION */
  51. __be32 agf_seqno; /* sequence # starting from 0 */
  52. __be32 agf_length; /* size in blocks of a.g. */
  53. /*
  54. * Freespace information
  55. */
  56. __be32 agf_roots[XFS_BTNUM_AGF]; /* root blocks */
  57. __be32 agf_spare0; /* spare field */
  58. __be32 agf_levels[XFS_BTNUM_AGF]; /* btree levels */
  59. __be32 agf_spare1; /* spare field */
  60. __be32 agf_flfirst; /* first freelist block's index */
  61. __be32 agf_fllast; /* last freelist block's index */
  62. __be32 agf_flcount; /* count of blocks in freelist */
  63. __be32 agf_freeblks; /* total free blocks */
  64. __be32 agf_longest; /* longest free space */
  65. __be32 agf_btreeblks; /* # of blocks held in AGF btrees */
  66. uuid_t agf_uuid; /* uuid of filesystem */
  67. /*
  68. * reserve some contiguous space for future logged fields before we add
  69. * the unlogged fields. This makes the range logging via flags and
  70. * structure offsets much simpler.
  71. */
  72. __be64 agf_spare64[16];
  73. /* unlogged fields, written during buffer writeback. */
  74. __be64 agf_lsn; /* last write sequence */
  75. __be32 agf_crc; /* crc of agf sector */
  76. __be32 agf_spare2;
  77. /* structure must be padded to 64 bit alignment */
  78. } xfs_agf_t;
  79. #define XFS_AGF_MAGICNUM 0x00000001
  80. #define XFS_AGF_VERSIONNUM 0x00000002
  81. #define XFS_AGF_SEQNO 0x00000004
  82. #define XFS_AGF_LENGTH 0x00000008
  83. #define XFS_AGF_ROOTS 0x00000010
  84. #define XFS_AGF_LEVELS 0x00000020
  85. #define XFS_AGF_FLFIRST 0x00000040
  86. #define XFS_AGF_FLLAST 0x00000080
  87. #define XFS_AGF_FLCOUNT 0x00000100
  88. #define XFS_AGF_FREEBLKS 0x00000200
  89. #define XFS_AGF_LONGEST 0x00000400
  90. #define XFS_AGF_BTREEBLKS 0x00000800
  91. #define XFS_AGF_UUID 0x00001000
  92. #define XFS_AGF_NUM_BITS 13
  93. #define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
  94. #define XFS_AGF_FLAGS \
  95. { XFS_AGF_MAGICNUM, "MAGICNUM" }, \
  96. { XFS_AGF_VERSIONNUM, "VERSIONNUM" }, \
  97. { XFS_AGF_SEQNO, "SEQNO" }, \
  98. { XFS_AGF_LENGTH, "LENGTH" }, \
  99. { XFS_AGF_ROOTS, "ROOTS" }, \
  100. { XFS_AGF_LEVELS, "LEVELS" }, \
  101. { XFS_AGF_FLFIRST, "FLFIRST" }, \
  102. { XFS_AGF_FLLAST, "FLLAST" }, \
  103. { XFS_AGF_FLCOUNT, "FLCOUNT" }, \
  104. { XFS_AGF_FREEBLKS, "FREEBLKS" }, \
  105. { XFS_AGF_LONGEST, "LONGEST" }, \
  106. { XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \
  107. { XFS_AGF_UUID, "UUID" }
  108. /* disk block (xfs_daddr_t) in the AG */
  109. #define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
  110. #define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
  111. #define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)((bp)->b_addr))
  112. extern int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
  113. xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);
  114. extern const struct xfs_buf_ops xfs_agf_buf_ops;
  115. /*
  116. * Size of the unlinked inode hash table in the agi.
  117. */
  118. #define XFS_AGI_UNLINKED_BUCKETS 64
  119. typedef struct xfs_agi {
  120. /*
  121. * Common allocation group header information
  122. */
  123. __be32 agi_magicnum; /* magic number == XFS_AGI_MAGIC */
  124. __be32 agi_versionnum; /* header version == XFS_AGI_VERSION */
  125. __be32 agi_seqno; /* sequence # starting from 0 */
  126. __be32 agi_length; /* size in blocks of a.g. */
  127. /*
  128. * Inode information
  129. * Inodes are mapped by interpreting the inode number, so no
  130. * mapping data is needed here.
  131. */
  132. __be32 agi_count; /* count of allocated inodes */
  133. __be32 agi_root; /* root of inode btree */
  134. __be32 agi_level; /* levels in inode btree */
  135. __be32 agi_freecount; /* number of free inodes */
  136. __be32 agi_newino; /* new inode just allocated */
  137. __be32 agi_dirino; /* last directory inode chunk */
  138. /*
  139. * Hash table of inodes which have been unlinked but are
  140. * still being referenced.
  141. */
  142. __be32 agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
  143. uuid_t agi_uuid; /* uuid of filesystem */
  144. __be32 agi_crc; /* crc of agi sector */
  145. __be32 agi_pad32;
  146. __be64 agi_lsn; /* last write sequence */
  147. /* structure must be padded to 64 bit alignment */
  148. } xfs_agi_t;
  149. #define XFS_AGI_MAGICNUM 0x00000001
  150. #define XFS_AGI_VERSIONNUM 0x00000002
  151. #define XFS_AGI_SEQNO 0x00000004
  152. #define XFS_AGI_LENGTH 0x00000008
  153. #define XFS_AGI_COUNT 0x00000010
  154. #define XFS_AGI_ROOT 0x00000020
  155. #define XFS_AGI_LEVEL 0x00000040
  156. #define XFS_AGI_FREECOUNT 0x00000080
  157. #define XFS_AGI_NEWINO 0x00000100
  158. #define XFS_AGI_DIRINO 0x00000200
  159. #define XFS_AGI_UNLINKED 0x00000400
  160. #define XFS_AGI_NUM_BITS 11
  161. #define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1)
  162. /* disk block (xfs_daddr_t) in the AG */
  163. #define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
  164. #define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
  165. #define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)((bp)->b_addr))
  166. extern int xfs_read_agi(struct xfs_mount *mp, struct xfs_trans *tp,
  167. xfs_agnumber_t agno, struct xfs_buf **bpp);
  168. extern const struct xfs_buf_ops xfs_agi_buf_ops;
  169. /*
  170. * The third a.g. block contains the a.g. freelist, an array
  171. * of block pointers to blocks owned by the allocation btree code.
  172. */
  173. #define XFS_AGFL_DADDR(mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
  174. #define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
  175. #define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)((bp)->b_addr))
  176. #define XFS_BUF_TO_AGFL_BNO(mp, bp) \
  177. (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
  178. &(XFS_BUF_TO_AGFL(bp)->agfl_bno[0]) : \
  179. (__be32 *)(bp)->b_addr)
  180. /*
  181. * Size of the AGFL. For CRC-enabled filesystes we steal a couple of
  182. * slots in the beginning of the block for a proper header with the
  183. * location information and CRC.
  184. */
  185. #define XFS_AGFL_SIZE(mp) \
  186. (((mp)->m_sb.sb_sectsize - \
  187. (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
  188. sizeof(struct xfs_agfl) : 0)) / \
  189. sizeof(xfs_agblock_t))
  190. typedef struct xfs_agfl {
  191. __be32 agfl_magicnum;
  192. __be32 agfl_seqno;
  193. uuid_t agfl_uuid;
  194. __be64 agfl_lsn;
  195. __be32 agfl_crc;
  196. __be32 agfl_bno[]; /* actually XFS_AGFL_SIZE(mp) */
  197. } xfs_agfl_t;
  198. /*
  199. * tags for inode radix tree
  200. */
  201. #define XFS_ICI_NO_TAG (-1) /* special flag for an untagged lookup
  202. in xfs_inode_ag_iterator */
  203. #define XFS_ICI_RECLAIM_TAG 0 /* inode is to be reclaimed */
  204. #define XFS_ICI_EOFBLOCKS_TAG 1 /* inode has blocks beyond EOF */
  205. #define XFS_AG_MAXLEVELS(mp) ((mp)->m_ag_maxlevels)
  206. #define XFS_MIN_FREELIST_RAW(bl,cl,mp) \
  207. (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
  208. #define XFS_MIN_FREELIST(a,mp) \
  209. (XFS_MIN_FREELIST_RAW( \
  210. be32_to_cpu((a)->agf_levels[XFS_BTNUM_BNOi]), \
  211. be32_to_cpu((a)->agf_levels[XFS_BTNUM_CNTi]), mp))
  212. #define XFS_MIN_FREELIST_PAG(pag,mp) \
  213. (XFS_MIN_FREELIST_RAW( \
  214. (unsigned int)(pag)->pagf_levels[XFS_BTNUM_BNOi], \
  215. (unsigned int)(pag)->pagf_levels[XFS_BTNUM_CNTi], mp))
  216. #define XFS_AGB_TO_FSB(mp,agno,agbno) \
  217. (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
  218. #define XFS_FSB_TO_AGNO(mp,fsbno) \
  219. ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
  220. #define XFS_FSB_TO_AGBNO(mp,fsbno) \
  221. ((xfs_agblock_t)((fsbno) & xfs_mask32lo((mp)->m_sb.sb_agblklog)))
  222. #define XFS_AGB_TO_DADDR(mp,agno,agbno) \
  223. ((xfs_daddr_t)XFS_FSB_TO_BB(mp, \
  224. (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno)))
  225. #define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
  226. /*
  227. * For checking for bad ranges of xfs_daddr_t's, covering multiple
  228. * allocation groups or a single xfs_daddr_t that's a superblock copy.
  229. */
  230. #define XFS_AG_CHECK_DADDR(mp,d,len) \
  231. ((len) == 1 ? \
  232. ASSERT((d) == XFS_SB_DADDR || \
  233. xfs_daddr_to_agbno(mp, d) != XFS_SB_DADDR) : \
  234. ASSERT(xfs_daddr_to_agno(mp, d) == \
  235. xfs_daddr_to_agno(mp, (d) + (len) - 1)))
  236. #endif /* __XFS_AG_H__ */