xfs_sb.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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_SB_H__
  19. #define __XFS_SB_H__
  20. /*
  21. * Super block
  22. * Fits into a sector-sized buffer at address 0 of each allocation group.
  23. * Only the first of these is ever updated except during growfs.
  24. */
  25. struct xfs_buf;
  26. struct xfs_mount;
  27. struct xfs_trans;
  28. #define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */
  29. #define XFS_SB_VERSION_1 1 /* 5.3, 6.0.1, 6.1 */
  30. #define XFS_SB_VERSION_2 2 /* 6.2 - attributes */
  31. #define XFS_SB_VERSION_3 3 /* 6.2 - new inode version */
  32. #define XFS_SB_VERSION_4 4 /* 6.2+ - bitmask version */
  33. #define XFS_SB_VERSION_5 5 /* CRC enabled filesystem */
  34. #define XFS_SB_VERSION_NUMBITS 0x000f
  35. #define XFS_SB_VERSION_ALLFBITS 0xfff0
  36. #define XFS_SB_VERSION_ATTRBIT 0x0010
  37. #define XFS_SB_VERSION_NLINKBIT 0x0020
  38. #define XFS_SB_VERSION_QUOTABIT 0x0040
  39. #define XFS_SB_VERSION_ALIGNBIT 0x0080
  40. #define XFS_SB_VERSION_DALIGNBIT 0x0100
  41. #define XFS_SB_VERSION_SHAREDBIT 0x0200
  42. #define XFS_SB_VERSION_LOGV2BIT 0x0400
  43. #define XFS_SB_VERSION_SECTORBIT 0x0800
  44. #define XFS_SB_VERSION_EXTFLGBIT 0x1000
  45. #define XFS_SB_VERSION_DIRV2BIT 0x2000
  46. #define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
  47. #define XFS_SB_VERSION_MOREBITSBIT 0x8000
  48. /*
  49. * Supported feature bit list is just all bits in the versionnum field because
  50. * we've used them all up and understand them all. Except, of course, for the
  51. * shared superblock bit, which nobody knows what it does and so is unsupported.
  52. */
  53. #define XFS_SB_VERSION_OKBITS \
  54. ((XFS_SB_VERSION_NUMBITS | XFS_SB_VERSION_ALLFBITS) & \
  55. ~XFS_SB_VERSION_SHAREDBIT)
  56. /*
  57. * There are two words to hold XFS "feature" bits: the original
  58. * word, sb_versionnum, and sb_features2. Whenever a bit is set in
  59. * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
  60. *
  61. * These defines represent bits in sb_features2.
  62. */
  63. #define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
  64. #define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
  65. #define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
  66. #define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
  67. #define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
  68. #define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
  69. #define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */
  70. #define XFS_SB_VERSION2_FTYPE 0x00000200 /* inode type in dir */
  71. #define XFS_SB_VERSION2_OKBITS \
  72. (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
  73. XFS_SB_VERSION2_ATTR2BIT | \
  74. XFS_SB_VERSION2_PROJID32BIT | \
  75. XFS_SB_VERSION2_FTYPE)
  76. /*
  77. * Superblock - in core version. Must match the ondisk version below.
  78. * Must be padded to 64 bit alignment.
  79. */
  80. typedef struct xfs_sb {
  81. __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
  82. __uint32_t sb_blocksize; /* logical block size, bytes */
  83. xfs_drfsbno_t sb_dblocks; /* number of data blocks */
  84. xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
  85. xfs_drtbno_t sb_rextents; /* number of realtime extents */
  86. uuid_t sb_uuid; /* file system unique id */
  87. xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
  88. xfs_ino_t sb_rootino; /* root inode number */
  89. xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
  90. xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
  91. xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
  92. xfs_agblock_t sb_agblocks; /* size of an allocation group */
  93. xfs_agnumber_t sb_agcount; /* number of allocation groups */
  94. xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
  95. xfs_extlen_t sb_logblocks; /* number of log blocks */
  96. __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
  97. __uint16_t sb_sectsize; /* volume sector size, bytes */
  98. __uint16_t sb_inodesize; /* inode size, bytes */
  99. __uint16_t sb_inopblock; /* inodes per block */
  100. char sb_fname[12]; /* file system name */
  101. __uint8_t sb_blocklog; /* log2 of sb_blocksize */
  102. __uint8_t sb_sectlog; /* log2 of sb_sectsize */
  103. __uint8_t sb_inodelog; /* log2 of sb_inodesize */
  104. __uint8_t sb_inopblog; /* log2 of sb_inopblock */
  105. __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
  106. __uint8_t sb_rextslog; /* log2 of sb_rextents */
  107. __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
  108. __uint8_t sb_imax_pct; /* max % of fs for inode space */
  109. /* statistics */
  110. /*
  111. * These fields must remain contiguous. If you really
  112. * want to change their layout, make sure you fix the
  113. * code in xfs_trans_apply_sb_deltas().
  114. */
  115. __uint64_t sb_icount; /* allocated inodes */
  116. __uint64_t sb_ifree; /* free inodes */
  117. __uint64_t sb_fdblocks; /* free data blocks */
  118. __uint64_t sb_frextents; /* free realtime extents */
  119. /*
  120. * End contiguous fields.
  121. */
  122. xfs_ino_t sb_uquotino; /* user quota inode */
  123. xfs_ino_t sb_gquotino; /* group quota inode */
  124. __uint16_t sb_qflags; /* quota flags */
  125. __uint8_t sb_flags; /* misc. flags */
  126. __uint8_t sb_shared_vn; /* shared version number */
  127. xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
  128. __uint32_t sb_unit; /* stripe or raid unit */
  129. __uint32_t sb_width; /* stripe or raid width */
  130. __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
  131. __uint8_t sb_logsectlog; /* log2 of the log sector size */
  132. __uint16_t sb_logsectsize; /* sector size for the log, bytes */
  133. __uint32_t sb_logsunit; /* stripe unit size for the log */
  134. __uint32_t sb_features2; /* additional feature bits */
  135. /*
  136. * bad features2 field as a result of failing to pad the sb
  137. * structure to 64 bits. Some machines will be using this field
  138. * for features2 bits. Easiest just to mark it bad and not use
  139. * it for anything else.
  140. */
  141. __uint32_t sb_bad_features2;
  142. /* version 5 superblock fields start here */
  143. /* feature masks */
  144. __uint32_t sb_features_compat;
  145. __uint32_t sb_features_ro_compat;
  146. __uint32_t sb_features_incompat;
  147. __uint32_t sb_features_log_incompat;
  148. __uint32_t sb_crc; /* superblock crc */
  149. __uint32_t sb_pad;
  150. xfs_ino_t sb_pquotino; /* project quota inode */
  151. xfs_lsn_t sb_lsn; /* last write sequence */
  152. /* must be padded to 64 bit alignment */
  153. } xfs_sb_t;
  154. #define XFS_SB_CRC_OFF offsetof(struct xfs_sb, sb_crc)
  155. /*
  156. * Superblock - on disk version. Must match the in core version above.
  157. * Must be padded to 64 bit alignment.
  158. */
  159. typedef struct xfs_dsb {
  160. __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
  161. __be32 sb_blocksize; /* logical block size, bytes */
  162. __be64 sb_dblocks; /* number of data blocks */
  163. __be64 sb_rblocks; /* number of realtime blocks */
  164. __be64 sb_rextents; /* number of realtime extents */
  165. uuid_t sb_uuid; /* file system unique id */
  166. __be64 sb_logstart; /* starting block of log if internal */
  167. __be64 sb_rootino; /* root inode number */
  168. __be64 sb_rbmino; /* bitmap inode for realtime extents */
  169. __be64 sb_rsumino; /* summary inode for rt bitmap */
  170. __be32 sb_rextsize; /* realtime extent size, blocks */
  171. __be32 sb_agblocks; /* size of an allocation group */
  172. __be32 sb_agcount; /* number of allocation groups */
  173. __be32 sb_rbmblocks; /* number of rt bitmap blocks */
  174. __be32 sb_logblocks; /* number of log blocks */
  175. __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
  176. __be16 sb_sectsize; /* volume sector size, bytes */
  177. __be16 sb_inodesize; /* inode size, bytes */
  178. __be16 sb_inopblock; /* inodes per block */
  179. char sb_fname[12]; /* file system name */
  180. __u8 sb_blocklog; /* log2 of sb_blocksize */
  181. __u8 sb_sectlog; /* log2 of sb_sectsize */
  182. __u8 sb_inodelog; /* log2 of sb_inodesize */
  183. __u8 sb_inopblog; /* log2 of sb_inopblock */
  184. __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
  185. __u8 sb_rextslog; /* log2 of sb_rextents */
  186. __u8 sb_inprogress; /* mkfs is in progress, don't mount */
  187. __u8 sb_imax_pct; /* max % of fs for inode space */
  188. /* statistics */
  189. /*
  190. * These fields must remain contiguous. If you really
  191. * want to change their layout, make sure you fix the
  192. * code in xfs_trans_apply_sb_deltas().
  193. */
  194. __be64 sb_icount; /* allocated inodes */
  195. __be64 sb_ifree; /* free inodes */
  196. __be64 sb_fdblocks; /* free data blocks */
  197. __be64 sb_frextents; /* free realtime extents */
  198. /*
  199. * End contiguous fields.
  200. */
  201. __be64 sb_uquotino; /* user quota inode */
  202. __be64 sb_gquotino; /* group quota inode */
  203. __be16 sb_qflags; /* quota flags */
  204. __u8 sb_flags; /* misc. flags */
  205. __u8 sb_shared_vn; /* shared version number */
  206. __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
  207. __be32 sb_unit; /* stripe or raid unit */
  208. __be32 sb_width; /* stripe or raid width */
  209. __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
  210. __u8 sb_logsectlog; /* log2 of the log sector size */
  211. __be16 sb_logsectsize; /* sector size for the log, bytes */
  212. __be32 sb_logsunit; /* stripe unit size for the log */
  213. __be32 sb_features2; /* additional feature bits */
  214. /*
  215. * bad features2 field as a result of failing to pad the sb
  216. * structure to 64 bits. Some machines will be using this field
  217. * for features2 bits. Easiest just to mark it bad and not use
  218. * it for anything else.
  219. */
  220. __be32 sb_bad_features2;
  221. /* version 5 superblock fields start here */
  222. /* feature masks */
  223. __be32 sb_features_compat;
  224. __be32 sb_features_ro_compat;
  225. __be32 sb_features_incompat;
  226. __be32 sb_features_log_incompat;
  227. __le32 sb_crc; /* superblock crc */
  228. __be32 sb_pad;
  229. __be64 sb_pquotino; /* project quota inode */
  230. __be64 sb_lsn; /* last write sequence */
  231. /* must be padded to 64 bit alignment */
  232. } xfs_dsb_t;
  233. /*
  234. * Sequence number values for the fields.
  235. */
  236. typedef enum {
  237. XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
  238. XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
  239. XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
  240. XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
  241. XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
  242. XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
  243. XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
  244. XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
  245. XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
  246. XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
  247. XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
  248. XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
  249. XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2, XFS_SBS_FEATURES_COMPAT,
  250. XFS_SBS_FEATURES_RO_COMPAT, XFS_SBS_FEATURES_INCOMPAT,
  251. XFS_SBS_FEATURES_LOG_INCOMPAT, XFS_SBS_CRC, XFS_SBS_PAD,
  252. XFS_SBS_PQUOTINO, XFS_SBS_LSN,
  253. XFS_SBS_FIELDCOUNT
  254. } xfs_sb_field_t;
  255. /*
  256. * Mask values, defined based on the xfs_sb_field_t values.
  257. * Only define the ones we're using.
  258. */
  259. #define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
  260. #define XFS_SB_UUID XFS_SB_MVAL(UUID)
  261. #define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
  262. #define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
  263. #define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
  264. #define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
  265. #define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
  266. #define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
  267. #define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
  268. #define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
  269. #define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
  270. #define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
  271. #define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
  272. #define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
  273. #define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
  274. #define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
  275. #define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
  276. #define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
  277. #define XFS_SB_FEATURES_COMPAT XFS_SB_MVAL(FEATURES_COMPAT)
  278. #define XFS_SB_FEATURES_RO_COMPAT XFS_SB_MVAL(FEATURES_RO_COMPAT)
  279. #define XFS_SB_FEATURES_INCOMPAT XFS_SB_MVAL(FEATURES_INCOMPAT)
  280. #define XFS_SB_FEATURES_LOG_INCOMPAT XFS_SB_MVAL(FEATURES_LOG_INCOMPAT)
  281. #define XFS_SB_CRC XFS_SB_MVAL(CRC)
  282. #define XFS_SB_PQUOTINO XFS_SB_MVAL(PQUOTINO)
  283. #define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
  284. #define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
  285. #define XFS_SB_MOD_BITS \
  286. (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
  287. XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
  288. XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
  289. XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
  290. XFS_SB_BAD_FEATURES2 | XFS_SB_FEATURES_COMPAT | \
  291. XFS_SB_FEATURES_RO_COMPAT | XFS_SB_FEATURES_INCOMPAT | \
  292. XFS_SB_FEATURES_LOG_INCOMPAT | XFS_SB_PQUOTINO)
  293. /*
  294. * Misc. Flags - warning - these will be cleared by xfs_repair unless
  295. * a feature bit is set when the flag is used.
  296. */
  297. #define XFS_SBF_NOFLAGS 0x00 /* no flags set */
  298. #define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
  299. /*
  300. * define max. shared version we can interoperate with
  301. */
  302. #define XFS_SB_MAX_SHARED_VN 0
  303. #define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
  304. /*
  305. * The first XFS version we support is a v4 superblock with V2 directories.
  306. */
  307. static inline bool xfs_sb_good_v4_features(struct xfs_sb *sbp)
  308. {
  309. if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
  310. return false;
  311. /* check for unknown features in the fs */
  312. if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
  313. ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
  314. (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
  315. return false;
  316. return true;
  317. }
  318. static inline bool xfs_sb_good_version(struct xfs_sb *sbp)
  319. {
  320. if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
  321. return true;
  322. if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
  323. return xfs_sb_good_v4_features(sbp);
  324. return false;
  325. }
  326. /*
  327. * Detect a mismatched features2 field. Older kernels read/wrote
  328. * this into the wrong slot, so to be safe we keep them in sync.
  329. */
  330. static inline bool xfs_sb_has_mismatched_features2(struct xfs_sb *sbp)
  331. {
  332. return sbp->sb_bad_features2 != sbp->sb_features2;
  333. }
  334. static inline bool xfs_sb_version_hasattr(struct xfs_sb *sbp)
  335. {
  336. return (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT);
  337. }
  338. static inline void xfs_sb_version_addattr(struct xfs_sb *sbp)
  339. {
  340. sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
  341. }
  342. static inline bool xfs_sb_version_hasquota(struct xfs_sb *sbp)
  343. {
  344. return (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
  345. }
  346. static inline void xfs_sb_version_addquota(struct xfs_sb *sbp)
  347. {
  348. sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
  349. }
  350. static inline bool xfs_sb_version_hasalign(struct xfs_sb *sbp)
  351. {
  352. return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
  353. (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT));
  354. }
  355. static inline bool xfs_sb_version_hasdalign(struct xfs_sb *sbp)
  356. {
  357. return (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
  358. }
  359. static inline bool xfs_sb_version_haslogv2(struct xfs_sb *sbp)
  360. {
  361. return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
  362. (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
  363. }
  364. static inline bool xfs_sb_version_hasextflgbit(struct xfs_sb *sbp)
  365. {
  366. return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
  367. (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
  368. }
  369. static inline bool xfs_sb_version_hassector(struct xfs_sb *sbp)
  370. {
  371. return (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
  372. }
  373. static inline bool xfs_sb_version_hasasciici(struct xfs_sb *sbp)
  374. {
  375. return (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
  376. }
  377. static inline bool xfs_sb_version_hasmorebits(struct xfs_sb *sbp)
  378. {
  379. return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
  380. (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
  381. }
  382. /*
  383. * sb_features2 bit version macros.
  384. */
  385. static inline bool xfs_sb_version_haslazysbcount(struct xfs_sb *sbp)
  386. {
  387. return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
  388. (xfs_sb_version_hasmorebits(sbp) &&
  389. (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
  390. }
  391. static inline bool xfs_sb_version_hasattr2(struct xfs_sb *sbp)
  392. {
  393. return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
  394. (xfs_sb_version_hasmorebits(sbp) &&
  395. (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT));
  396. }
  397. static inline void xfs_sb_version_addattr2(struct xfs_sb *sbp)
  398. {
  399. sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
  400. sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
  401. sbp->sb_bad_features2 |= XFS_SB_VERSION2_ATTR2BIT;
  402. }
  403. static inline void xfs_sb_version_removeattr2(struct xfs_sb *sbp)
  404. {
  405. sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
  406. sbp->sb_bad_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
  407. if (!sbp->sb_features2)
  408. sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
  409. }
  410. static inline bool xfs_sb_version_hasprojid32bit(struct xfs_sb *sbp)
  411. {
  412. return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
  413. (xfs_sb_version_hasmorebits(sbp) &&
  414. (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT));
  415. }
  416. static inline void xfs_sb_version_addprojid32bit(struct xfs_sb *sbp)
  417. {
  418. sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
  419. sbp->sb_features2 |= XFS_SB_VERSION2_PROJID32BIT;
  420. sbp->sb_bad_features2 |= XFS_SB_VERSION2_PROJID32BIT;
  421. }
  422. /*
  423. * Extended v5 superblock feature masks. These are to be used for new v5
  424. * superblock features only.
  425. *
  426. * Compat features are new features that old kernels will not notice or affect
  427. * and so can mount read-write without issues.
  428. *
  429. * RO-Compat (read only) are features that old kernels can read but will break
  430. * if they write. Hence only read-only mounts of such filesystems are allowed on
  431. * kernels that don't support the feature bit.
  432. *
  433. * InCompat features are features which old kernels will not understand and so
  434. * must not mount.
  435. *
  436. * Log-InCompat features are for changes to log formats or new transactions that
  437. * can't be replayed on older kernels. The fields are set when the filesystem is
  438. * mounted, and a clean unmount clears the fields.
  439. */
  440. #define XFS_SB_FEAT_COMPAT_ALL 0
  441. #define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL
  442. static inline bool
  443. xfs_sb_has_compat_feature(
  444. struct xfs_sb *sbp,
  445. __uint32_t feature)
  446. {
  447. return (sbp->sb_features_compat & feature) != 0;
  448. }
  449. #define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0) /* free inode btree */
  450. #define XFS_SB_FEAT_RO_COMPAT_ALL \
  451. (XFS_SB_FEAT_RO_COMPAT_FINOBT)
  452. #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL
  453. static inline bool
  454. xfs_sb_has_ro_compat_feature(
  455. struct xfs_sb *sbp,
  456. __uint32_t feature)
  457. {
  458. return (sbp->sb_features_ro_compat & feature) != 0;
  459. }
  460. #define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */
  461. #define XFS_SB_FEAT_INCOMPAT_ALL \
  462. (XFS_SB_FEAT_INCOMPAT_FTYPE)
  463. #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL
  464. static inline bool
  465. xfs_sb_has_incompat_feature(
  466. struct xfs_sb *sbp,
  467. __uint32_t feature)
  468. {
  469. return (sbp->sb_features_incompat & feature) != 0;
  470. }
  471. #define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0
  472. #define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_LOG_ALL
  473. static inline bool
  474. xfs_sb_has_incompat_log_feature(
  475. struct xfs_sb *sbp,
  476. __uint32_t feature)
  477. {
  478. return (sbp->sb_features_log_incompat & feature) != 0;
  479. }
  480. /*
  481. * V5 superblock specific feature checks
  482. */
  483. static inline int xfs_sb_version_hascrc(struct xfs_sb *sbp)
  484. {
  485. return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
  486. }
  487. static inline int xfs_sb_version_has_pquotino(struct xfs_sb *sbp)
  488. {
  489. return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
  490. }
  491. static inline int xfs_sb_version_hasftype(struct xfs_sb *sbp)
  492. {
  493. return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
  494. xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_FTYPE)) ||
  495. (xfs_sb_version_hasmorebits(sbp) &&
  496. (sbp->sb_features2 & XFS_SB_VERSION2_FTYPE));
  497. }
  498. static inline int xfs_sb_version_hasfinobt(xfs_sb_t *sbp)
  499. {
  500. return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&
  501. (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_FINOBT);
  502. }
  503. /*
  504. * end of superblock version macros
  505. */
  506. static inline bool
  507. xfs_is_quota_inode(struct xfs_sb *sbp, xfs_ino_t ino)
  508. {
  509. return (ino == sbp->sb_uquotino ||
  510. ino == sbp->sb_gquotino ||
  511. ino == sbp->sb_pquotino);
  512. }
  513. #define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
  514. #define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
  515. #define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
  516. #define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
  517. #define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
  518. xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
  519. #define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
  520. XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
  521. /*
  522. * File system sector to basic block conversions.
  523. */
  524. #define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
  525. /*
  526. * File system block to basic block conversions.
  527. */
  528. #define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
  529. #define XFS_BB_TO_FSB(mp,bb) \
  530. (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
  531. #define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
  532. /*
  533. * File system block to byte conversions.
  534. */
  535. #define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
  536. #define XFS_B_TO_FSB(mp,b) \
  537. ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
  538. #define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
  539. #define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
  540. /*
  541. * perag get/put wrappers for ref counting
  542. */
  543. extern struct xfs_perag *xfs_perag_get(struct xfs_mount *, xfs_agnumber_t);
  544. extern struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *, xfs_agnumber_t,
  545. int tag);
  546. extern void xfs_perag_put(struct xfs_perag *pag);
  547. extern int xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
  548. extern void xfs_sb_calc_crc(struct xfs_buf *);
  549. extern void xfs_mod_sb(struct xfs_trans *, __int64_t);
  550. extern void xfs_sb_mount_common(struct xfs_mount *, struct xfs_sb *);
  551. extern void xfs_sb_from_disk(struct xfs_sb *, struct xfs_dsb *);
  552. extern void xfs_sb_to_disk(struct xfs_dsb *, struct xfs_sb *, __int64_t);
  553. extern void xfs_sb_quota_from_disk(struct xfs_sb *sbp);
  554. #endif /* __XFS_SB_H__ */