xfs_sb.h 21 KB

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