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