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