xfs_format.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * Copyright (c) 2000-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_FORMAT_H__
  19. #define __XFS_FORMAT_H__
  20. /*
  21. * XFS On Disk Format Definitions
  22. *
  23. * This header file defines all the on-disk format definitions for
  24. * general XFS objects. Directory and attribute related objects are defined in
  25. * xfs_da_format.h, which log and log item formats are defined in
  26. * xfs_log_format.h. Everything else goes here.
  27. */
  28. struct xfs_mount;
  29. struct xfs_trans;
  30. struct xfs_inode;
  31. struct xfs_buf;
  32. struct xfs_ifork;
  33. /*
  34. * RealTime Device format definitions
  35. */
  36. /* Min and max rt extent sizes, specified in bytes */
  37. #define XFS_MAX_RTEXTSIZE (1024 * 1024 * 1024) /* 1GB */
  38. #define XFS_DFL_RTEXTSIZE (64 * 1024) /* 64kB */
  39. #define XFS_MIN_RTEXTSIZE (4 * 1024) /* 4kB */
  40. #define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize)
  41. #define XFS_BLOCKMASK(mp) ((mp)->m_blockmask)
  42. #define XFS_BLOCKWSIZE(mp) ((mp)->m_blockwsize)
  43. #define XFS_BLOCKWMASK(mp) ((mp)->m_blockwmask)
  44. /*
  45. * RT Summary and bit manipulation macros.
  46. */
  47. #define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
  48. #define XFS_SUMOFFSTOBLOCK(mp,s) \
  49. (((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
  50. #define XFS_SUMPTR(mp,bp,so) \
  51. ((xfs_suminfo_t *)((bp)->b_addr + \
  52. (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
  53. #define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log)
  54. #define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log)
  55. #define XFS_BITTOWORD(mp,bi) \
  56. ((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
  57. #define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
  58. #define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b))
  59. #define XFS_RTLOBIT(w) xfs_lowbit32(w)
  60. #define XFS_RTHIBIT(w) xfs_highbit32(w)
  61. #if XFS_BIG_BLKNOS
  62. #define XFS_RTBLOCKLOG(b) xfs_highbit64(b)
  63. #else
  64. #define XFS_RTBLOCKLOG(b) xfs_highbit32(b)
  65. #endif
  66. /*
  67. * Dquot and dquot block format definitions
  68. */
  69. #define XFS_DQUOT_MAGIC 0x4451 /* 'DQ' */
  70. #define XFS_DQUOT_VERSION (u_int8_t)0x01 /* latest version number */
  71. /*
  72. * This is the main portion of the on-disk representation of quota
  73. * information for a user. This is the q_core of the xfs_dquot_t that
  74. * is kept in kernel memory. We pad this with some more expansion room
  75. * to construct the on disk structure.
  76. */
  77. typedef struct xfs_disk_dquot {
  78. __be16 d_magic; /* dquot magic = XFS_DQUOT_MAGIC */
  79. __u8 d_version; /* dquot version */
  80. __u8 d_flags; /* XFS_DQ_USER/PROJ/GROUP */
  81. __be32 d_id; /* user,project,group id */
  82. __be64 d_blk_hardlimit;/* absolute limit on disk blks */
  83. __be64 d_blk_softlimit;/* preferred limit on disk blks */
  84. __be64 d_ino_hardlimit;/* maximum # allocated inodes */
  85. __be64 d_ino_softlimit;/* preferred inode limit */
  86. __be64 d_bcount; /* disk blocks owned by the user */
  87. __be64 d_icount; /* inodes owned by the user */
  88. __be32 d_itimer; /* zero if within inode limits if not,
  89. this is when we refuse service */
  90. __be32 d_btimer; /* similar to above; for disk blocks */
  91. __be16 d_iwarns; /* warnings issued wrt num inodes */
  92. __be16 d_bwarns; /* warnings issued wrt disk blocks */
  93. __be32 d_pad0; /* 64 bit align */
  94. __be64 d_rtb_hardlimit;/* absolute limit on realtime blks */
  95. __be64 d_rtb_softlimit;/* preferred limit on RT disk blks */
  96. __be64 d_rtbcount; /* realtime blocks owned */
  97. __be32 d_rtbtimer; /* similar to above; for RT disk blocks */
  98. __be16 d_rtbwarns; /* warnings issued wrt RT disk blocks */
  99. __be16 d_pad;
  100. } xfs_disk_dquot_t;
  101. /*
  102. * This is what goes on disk. This is separated from the xfs_disk_dquot because
  103. * carrying the unnecessary padding would be a waste of memory.
  104. */
  105. typedef struct xfs_dqblk {
  106. xfs_disk_dquot_t dd_diskdq; /* portion that lives incore as well */
  107. char dd_fill[4]; /* filling for posterity */
  108. /*
  109. * These two are only present on filesystems with the CRC bits set.
  110. */
  111. __be32 dd_crc; /* checksum */
  112. __be64 dd_lsn; /* last modification in log */
  113. uuid_t dd_uuid; /* location information */
  114. } xfs_dqblk_t;
  115. #define XFS_DQUOT_CRC_OFF offsetof(struct xfs_dqblk, dd_crc)
  116. /*
  117. * Remote symlink format and access functions.
  118. */
  119. #define XFS_SYMLINK_MAGIC 0x58534c4d /* XSLM */
  120. struct xfs_dsymlink_hdr {
  121. __be32 sl_magic;
  122. __be32 sl_offset;
  123. __be32 sl_bytes;
  124. __be32 sl_crc;
  125. uuid_t sl_uuid;
  126. __be64 sl_owner;
  127. __be64 sl_blkno;
  128. __be64 sl_lsn;
  129. };
  130. /*
  131. * The maximum pathlen is 1024 bytes. Since the minimum file system
  132. * blocksize is 512 bytes, we can get a max of 3 extents back from
  133. * bmapi when crc headers are taken into account.
  134. */
  135. #define XFS_SYMLINK_MAPS 3
  136. #define XFS_SYMLINK_BUF_SPACE(mp, bufsize) \
  137. ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
  138. sizeof(struct xfs_dsymlink_hdr) : 0))
  139. /*
  140. * Allocation Btree format definitions
  141. *
  142. * There are two on-disk btrees, one sorted by blockno and one sorted
  143. * by blockcount and blockno. All blocks look the same to make the code
  144. * simpler; if we have time later, we'll make the optimizations.
  145. */
  146. #define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
  147. #define XFS_ABTB_CRC_MAGIC 0x41423342 /* 'AB3B' */
  148. #define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
  149. #define XFS_ABTC_CRC_MAGIC 0x41423343 /* 'AB3C' */
  150. /*
  151. * Data record/key structure
  152. */
  153. typedef struct xfs_alloc_rec {
  154. __be32 ar_startblock; /* starting block number */
  155. __be32 ar_blockcount; /* count of free blocks */
  156. } xfs_alloc_rec_t, xfs_alloc_key_t;
  157. typedef struct xfs_alloc_rec_incore {
  158. xfs_agblock_t ar_startblock; /* starting block number */
  159. xfs_extlen_t ar_blockcount; /* count of free blocks */
  160. } xfs_alloc_rec_incore_t;
  161. /* btree pointer type */
  162. typedef __be32 xfs_alloc_ptr_t;
  163. /*
  164. * Block numbers in the AG:
  165. * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
  166. */
  167. #define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
  168. #define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
  169. /*
  170. * Inode Allocation Btree format definitions
  171. *
  172. * There is a btree for the inode map per allocation group.
  173. */
  174. #define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
  175. #define XFS_IBT_CRC_MAGIC 0x49414233 /* 'IAB3' */
  176. typedef __uint64_t xfs_inofree_t;
  177. #define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
  178. #define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3)
  179. #define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1)
  180. #define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i))
  181. static inline xfs_inofree_t xfs_inobt_maskn(int i, int n)
  182. {
  183. return ((n >= XFS_INODES_PER_CHUNK ? 0 : XFS_INOBT_MASK(n)) - 1) << i;
  184. }
  185. /*
  186. * Data record structure
  187. */
  188. typedef struct xfs_inobt_rec {
  189. __be32 ir_startino; /* starting inode number */
  190. __be32 ir_freecount; /* count of free inodes (set bits) */
  191. __be64 ir_free; /* free inode mask */
  192. } xfs_inobt_rec_t;
  193. typedef struct xfs_inobt_rec_incore {
  194. xfs_agino_t ir_startino; /* starting inode number */
  195. __int32_t ir_freecount; /* count of free inodes (set bits) */
  196. xfs_inofree_t ir_free; /* free inode mask */
  197. } xfs_inobt_rec_incore_t;
  198. /*
  199. * Key structure
  200. */
  201. typedef struct xfs_inobt_key {
  202. __be32 ir_startino; /* starting inode number */
  203. } xfs_inobt_key_t;
  204. /* btree pointer type */
  205. typedef __be32 xfs_inobt_ptr_t;
  206. /*
  207. * block numbers in the AG.
  208. */
  209. #define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
  210. #define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
  211. /*
  212. * BMAP Btree format definitions
  213. *
  214. * This includes both the root block definition that sits inside an inode fork
  215. * and the record/pointer formats for the leaf/node in the blocks.
  216. */
  217. #define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */
  218. #define XFS_BMAP_CRC_MAGIC 0x424d4133 /* 'BMA3' */
  219. /*
  220. * Bmap root header, on-disk form only.
  221. */
  222. typedef struct xfs_bmdr_block {
  223. __be16 bb_level; /* 0 is a leaf */
  224. __be16 bb_numrecs; /* current # of data records */
  225. } xfs_bmdr_block_t;
  226. /*
  227. * Bmap btree record and extent descriptor.
  228. * l0:63 is an extent flag (value 1 indicates non-normal).
  229. * l0:9-62 are startoff.
  230. * l0:0-8 and l1:21-63 are startblock.
  231. * l1:0-20 are blockcount.
  232. */
  233. #define BMBT_EXNTFLAG_BITLEN 1
  234. #define BMBT_STARTOFF_BITLEN 54
  235. #define BMBT_STARTBLOCK_BITLEN 52
  236. #define BMBT_BLOCKCOUNT_BITLEN 21
  237. typedef struct xfs_bmbt_rec {
  238. __be64 l0, l1;
  239. } xfs_bmbt_rec_t;
  240. typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */
  241. typedef xfs_bmbt_rec_t xfs_bmdr_rec_t;
  242. typedef struct xfs_bmbt_rec_host {
  243. __uint64_t l0, l1;
  244. } xfs_bmbt_rec_host_t;
  245. /*
  246. * Values and macros for delayed-allocation startblock fields.
  247. */
  248. #define STARTBLOCKVALBITS 17
  249. #define STARTBLOCKMASKBITS (15 + XFS_BIG_BLKNOS * 20)
  250. #define DSTARTBLOCKMASKBITS (15 + 20)
  251. #define STARTBLOCKMASK \
  252. (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
  253. #define DSTARTBLOCKMASK \
  254. (((((xfs_dfsbno_t)1) << DSTARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
  255. static inline int isnullstartblock(xfs_fsblock_t x)
  256. {
  257. return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
  258. }
  259. static inline int isnulldstartblock(xfs_dfsbno_t x)
  260. {
  261. return ((x) & DSTARTBLOCKMASK) == DSTARTBLOCKMASK;
  262. }
  263. static inline xfs_fsblock_t nullstartblock(int k)
  264. {
  265. ASSERT(k < (1 << STARTBLOCKVALBITS));
  266. return STARTBLOCKMASK | (k);
  267. }
  268. static inline xfs_filblks_t startblockval(xfs_fsblock_t x)
  269. {
  270. return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
  271. }
  272. /*
  273. * Possible extent formats.
  274. */
  275. typedef enum {
  276. XFS_EXTFMT_NOSTATE = 0,
  277. XFS_EXTFMT_HASSTATE
  278. } xfs_exntfmt_t;
  279. /*
  280. * Possible extent states.
  281. */
  282. typedef enum {
  283. XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
  284. XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID
  285. } xfs_exntst_t;
  286. /*
  287. * Incore version of above.
  288. */
  289. typedef struct xfs_bmbt_irec
  290. {
  291. xfs_fileoff_t br_startoff; /* starting file offset */
  292. xfs_fsblock_t br_startblock; /* starting block number */
  293. xfs_filblks_t br_blockcount; /* number of blocks */
  294. xfs_exntst_t br_state; /* extent state */
  295. } xfs_bmbt_irec_t;
  296. /*
  297. * Key structure for non-leaf levels of the tree.
  298. */
  299. typedef struct xfs_bmbt_key {
  300. __be64 br_startoff; /* starting file offset */
  301. } xfs_bmbt_key_t, xfs_bmdr_key_t;
  302. /* btree pointer type */
  303. typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
  304. /*
  305. * Generic Btree block format definitions
  306. *
  307. * This is a combination of the actual format used on disk for short and long
  308. * format btrees. The first three fields are shared by both format, but the
  309. * pointers are different and should be used with care.
  310. *
  311. * To get the size of the actual short or long form headers please use the size
  312. * macros below. Never use sizeof(xfs_btree_block).
  313. *
  314. * The blkno, crc, lsn, owner and uuid fields are only available in filesystems
  315. * with the crc feature bit, and all accesses to them must be conditional on
  316. * that flag.
  317. */
  318. struct xfs_btree_block {
  319. __be32 bb_magic; /* magic number for block type */
  320. __be16 bb_level; /* 0 is a leaf */
  321. __be16 bb_numrecs; /* current # of data records */
  322. union {
  323. struct {
  324. __be32 bb_leftsib;
  325. __be32 bb_rightsib;
  326. __be64 bb_blkno;
  327. __be64 bb_lsn;
  328. uuid_t bb_uuid;
  329. __be32 bb_owner;
  330. __le32 bb_crc;
  331. } s; /* short form pointers */
  332. struct {
  333. __be64 bb_leftsib;
  334. __be64 bb_rightsib;
  335. __be64 bb_blkno;
  336. __be64 bb_lsn;
  337. uuid_t bb_uuid;
  338. __be64 bb_owner;
  339. __le32 bb_crc;
  340. __be32 bb_pad; /* padding for alignment */
  341. } l; /* long form pointers */
  342. } bb_u; /* rest */
  343. };
  344. #define XFS_BTREE_SBLOCK_LEN 16 /* size of a short form block */
  345. #define XFS_BTREE_LBLOCK_LEN 24 /* size of a long form block */
  346. /* sizes of CRC enabled btree blocks */
  347. #define XFS_BTREE_SBLOCK_CRC_LEN (XFS_BTREE_SBLOCK_LEN + 40)
  348. #define XFS_BTREE_LBLOCK_CRC_LEN (XFS_BTREE_LBLOCK_LEN + 48)
  349. #define XFS_BTREE_SBLOCK_CRC_OFF \
  350. offsetof(struct xfs_btree_block, bb_u.s.bb_crc)
  351. #define XFS_BTREE_LBLOCK_CRC_OFF \
  352. offsetof(struct xfs_btree_block, bb_u.l.bb_crc)
  353. #endif /* __XFS_FORMAT_H__ */