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