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