xfs_format.h 12 KB

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