xfs_sb.h 18 KB

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