xfs_format.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. #define XFS_SYMLINK_CRC_OFF offsetof(struct xfs_dsymlink_hdr, sl_crc)
  131. /*
  132. * The maximum pathlen is 1024 bytes. Since the minimum file system
  133. * blocksize is 512 bytes, we can get a max of 3 extents back from
  134. * bmapi when crc headers are taken into account.
  135. */
  136. #define XFS_SYMLINK_MAPS 3
  137. #define XFS_SYMLINK_BUF_SPACE(mp, bufsize) \
  138. ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
  139. sizeof(struct xfs_dsymlink_hdr) : 0))
  140. /*
  141. * Allocation Btree format definitions
  142. *
  143. * There are two on-disk btrees, one sorted by blockno and one sorted
  144. * by blockcount and blockno. All blocks look the same to make the code
  145. * simpler; if we have time later, we'll make the optimizations.
  146. */
  147. #define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
  148. #define XFS_ABTB_CRC_MAGIC 0x41423342 /* 'AB3B' */
  149. #define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
  150. #define XFS_ABTC_CRC_MAGIC 0x41423343 /* 'AB3C' */
  151. /*
  152. * Data record/key structure
  153. */
  154. typedef struct xfs_alloc_rec {
  155. __be32 ar_startblock; /* starting block number */
  156. __be32 ar_blockcount; /* count of free blocks */
  157. } xfs_alloc_rec_t, xfs_alloc_key_t;
  158. typedef struct xfs_alloc_rec_incore {
  159. xfs_agblock_t ar_startblock; /* starting block number */
  160. xfs_extlen_t ar_blockcount; /* count of free blocks */
  161. } xfs_alloc_rec_incore_t;
  162. /* btree pointer type */
  163. typedef __be32 xfs_alloc_ptr_t;
  164. /*
  165. * Block numbers in the AG:
  166. * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
  167. */
  168. #define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
  169. #define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
  170. /*
  171. * Inode Allocation Btree format definitions
  172. *
  173. * There is a btree for the inode map per allocation group.
  174. */
  175. #define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
  176. #define XFS_IBT_CRC_MAGIC 0x49414233 /* 'IAB3' */
  177. #define XFS_FIBT_MAGIC 0x46494254 /* 'FIBT' */
  178. #define XFS_FIBT_CRC_MAGIC 0x46494233 /* 'FIB3' */
  179. typedef __uint64_t xfs_inofree_t;
  180. #define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
  181. #define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3)
  182. #define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1)
  183. #define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i))
  184. static inline xfs_inofree_t xfs_inobt_maskn(int i, int n)
  185. {
  186. return ((n >= XFS_INODES_PER_CHUNK ? 0 : XFS_INOBT_MASK(n)) - 1) << i;
  187. }
  188. /*
  189. * Data record structure
  190. */
  191. typedef struct xfs_inobt_rec {
  192. __be32 ir_startino; /* starting inode number */
  193. __be32 ir_freecount; /* count of free inodes (set bits) */
  194. __be64 ir_free; /* free inode mask */
  195. } xfs_inobt_rec_t;
  196. typedef struct xfs_inobt_rec_incore {
  197. xfs_agino_t ir_startino; /* starting inode number */
  198. __int32_t ir_freecount; /* count of free inodes (set bits) */
  199. xfs_inofree_t ir_free; /* free inode mask */
  200. } xfs_inobt_rec_incore_t;
  201. /*
  202. * Key structure
  203. */
  204. typedef struct xfs_inobt_key {
  205. __be32 ir_startino; /* starting inode number */
  206. } xfs_inobt_key_t;
  207. /* btree pointer type */
  208. typedef __be32 xfs_inobt_ptr_t;
  209. /*
  210. * block numbers in the AG.
  211. */
  212. #define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
  213. #define XFS_FIBT_BLOCK(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
  214. /*
  215. * The first data block of an AG depends on whether the filesystem was formatted
  216. * with the finobt feature. If so, account for the finobt reserved root btree
  217. * block.
  218. */
  219. #define XFS_PREALLOC_BLOCKS(mp) \
  220. (xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \
  221. XFS_FIBT_BLOCK(mp) + 1 : \
  222. XFS_IBT_BLOCK(mp) + 1)
  223. /*
  224. * BMAP Btree format definitions
  225. *
  226. * This includes both the root block definition that sits inside an inode fork
  227. * and the record/pointer formats for the leaf/node in the blocks.
  228. */
  229. #define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */
  230. #define XFS_BMAP_CRC_MAGIC 0x424d4133 /* 'BMA3' */
  231. /*
  232. * Bmap root header, on-disk form only.
  233. */
  234. typedef struct xfs_bmdr_block {
  235. __be16 bb_level; /* 0 is a leaf */
  236. __be16 bb_numrecs; /* current # of data records */
  237. } xfs_bmdr_block_t;
  238. /*
  239. * Bmap btree record and extent descriptor.
  240. * l0:63 is an extent flag (value 1 indicates non-normal).
  241. * l0:9-62 are startoff.
  242. * l0:0-8 and l1:21-63 are startblock.
  243. * l1:0-20 are blockcount.
  244. */
  245. #define BMBT_EXNTFLAG_BITLEN 1
  246. #define BMBT_STARTOFF_BITLEN 54
  247. #define BMBT_STARTBLOCK_BITLEN 52
  248. #define BMBT_BLOCKCOUNT_BITLEN 21
  249. typedef struct xfs_bmbt_rec {
  250. __be64 l0, l1;
  251. } xfs_bmbt_rec_t;
  252. typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */
  253. typedef xfs_bmbt_rec_t xfs_bmdr_rec_t;
  254. typedef struct xfs_bmbt_rec_host {
  255. __uint64_t l0, l1;
  256. } xfs_bmbt_rec_host_t;
  257. /*
  258. * Values and macros for delayed-allocation startblock fields.
  259. */
  260. #define STARTBLOCKVALBITS 17
  261. #define STARTBLOCKMASKBITS (15 + XFS_BIG_BLKNOS * 20)
  262. #define DSTARTBLOCKMASKBITS (15 + 20)
  263. #define STARTBLOCKMASK \
  264. (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
  265. #define DSTARTBLOCKMASK \
  266. (((((xfs_dfsbno_t)1) << DSTARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
  267. static inline int isnullstartblock(xfs_fsblock_t x)
  268. {
  269. return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
  270. }
  271. static inline int isnulldstartblock(xfs_dfsbno_t x)
  272. {
  273. return ((x) & DSTARTBLOCKMASK) == DSTARTBLOCKMASK;
  274. }
  275. static inline xfs_fsblock_t nullstartblock(int k)
  276. {
  277. ASSERT(k < (1 << STARTBLOCKVALBITS));
  278. return STARTBLOCKMASK | (k);
  279. }
  280. static inline xfs_filblks_t startblockval(xfs_fsblock_t x)
  281. {
  282. return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
  283. }
  284. /*
  285. * Possible extent formats.
  286. */
  287. typedef enum {
  288. XFS_EXTFMT_NOSTATE = 0,
  289. XFS_EXTFMT_HASSTATE
  290. } xfs_exntfmt_t;
  291. /*
  292. * Possible extent states.
  293. */
  294. typedef enum {
  295. XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
  296. XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID
  297. } xfs_exntst_t;
  298. /*
  299. * Incore version of above.
  300. */
  301. typedef struct xfs_bmbt_irec
  302. {
  303. xfs_fileoff_t br_startoff; /* starting file offset */
  304. xfs_fsblock_t br_startblock; /* starting block number */
  305. xfs_filblks_t br_blockcount; /* number of blocks */
  306. xfs_exntst_t br_state; /* extent state */
  307. } xfs_bmbt_irec_t;
  308. /*
  309. * Key structure for non-leaf levels of the tree.
  310. */
  311. typedef struct xfs_bmbt_key {
  312. __be64 br_startoff; /* starting file offset */
  313. } xfs_bmbt_key_t, xfs_bmdr_key_t;
  314. /* btree pointer type */
  315. typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
  316. /*
  317. * Generic Btree block format definitions
  318. *
  319. * This is a combination of the actual format used on disk for short and long
  320. * format btrees. The first three fields are shared by both format, but the
  321. * pointers are different and should be used with care.
  322. *
  323. * To get the size of the actual short or long form headers please use the size
  324. * macros below. Never use sizeof(xfs_btree_block).
  325. *
  326. * The blkno, crc, lsn, owner and uuid fields are only available in filesystems
  327. * with the crc feature bit, and all accesses to them must be conditional on
  328. * that flag.
  329. */
  330. struct xfs_btree_block {
  331. __be32 bb_magic; /* magic number for block type */
  332. __be16 bb_level; /* 0 is a leaf */
  333. __be16 bb_numrecs; /* current # of data records */
  334. union {
  335. struct {
  336. __be32 bb_leftsib;
  337. __be32 bb_rightsib;
  338. __be64 bb_blkno;
  339. __be64 bb_lsn;
  340. uuid_t bb_uuid;
  341. __be32 bb_owner;
  342. __le32 bb_crc;
  343. } s; /* short form pointers */
  344. struct {
  345. __be64 bb_leftsib;
  346. __be64 bb_rightsib;
  347. __be64 bb_blkno;
  348. __be64 bb_lsn;
  349. uuid_t bb_uuid;
  350. __be64 bb_owner;
  351. __le32 bb_crc;
  352. __be32 bb_pad; /* padding for alignment */
  353. } l; /* long form pointers */
  354. } bb_u; /* rest */
  355. };
  356. #define XFS_BTREE_SBLOCK_LEN 16 /* size of a short form block */
  357. #define XFS_BTREE_LBLOCK_LEN 24 /* size of a long form block */
  358. /* sizes of CRC enabled btree blocks */
  359. #define XFS_BTREE_SBLOCK_CRC_LEN (XFS_BTREE_SBLOCK_LEN + 40)
  360. #define XFS_BTREE_LBLOCK_CRC_LEN (XFS_BTREE_LBLOCK_LEN + 48)
  361. #define XFS_BTREE_SBLOCK_CRC_OFF \
  362. offsetof(struct xfs_btree_block, bb_u.s.bb_crc)
  363. #define XFS_BTREE_LBLOCK_CRC_OFF \
  364. offsetof(struct xfs_btree_block, bb_u.l.bb_crc)
  365. #endif /* __XFS_FORMAT_H__ */