blob: 78f9e70b80c7da8a64b92d528a9f7aa2ba49401e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
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
27struct xfs_buf;
28struct 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 */
Dave Chinner04a1e6c2013-04-03 16:11:31 +110035#define XFS_SB_VERSION_5 5 /* CRC enabled filesystem */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#define XFS_SB_VERSION_NUMBITS 0x000f
37#define XFS_SB_VERSION_ALLFBITS 0xfff0
38#define XFS_SB_VERSION_SASHFBITS 0xf000
39#define XFS_SB_VERSION_REALFBITS 0x0ff0
40#define XFS_SB_VERSION_ATTRBIT 0x0010
41#define XFS_SB_VERSION_NLINKBIT 0x0020
42#define XFS_SB_VERSION_QUOTABIT 0x0040
43#define XFS_SB_VERSION_ALIGNBIT 0x0080
44#define XFS_SB_VERSION_DALIGNBIT 0x0100
45#define XFS_SB_VERSION_SHAREDBIT 0x0200
46#define XFS_SB_VERSION_LOGV2BIT 0x0400
47#define XFS_SB_VERSION_SECTORBIT 0x0800
48#define XFS_SB_VERSION_EXTFLGBIT 0x1000
49#define XFS_SB_VERSION_DIRV2BIT 0x2000
Barry Naujok189f4bf2008-05-21 16:58:55 +100050#define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define XFS_SB_VERSION_MOREBITSBIT 0x8000
52#define XFS_SB_VERSION_OKSASHFBITS \
53 (XFS_SB_VERSION_EXTFLGBIT | \
Barry Naujok189f4bf2008-05-21 16:58:55 +100054 XFS_SB_VERSION_DIRV2BIT | \
55 XFS_SB_VERSION_BORGBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define XFS_SB_VERSION_OKREALFBITS \
57 (XFS_SB_VERSION_ATTRBIT | \
58 XFS_SB_VERSION_NLINKBIT | \
59 XFS_SB_VERSION_QUOTABIT | \
60 XFS_SB_VERSION_ALIGNBIT | \
61 XFS_SB_VERSION_DALIGNBIT | \
62 XFS_SB_VERSION_SHAREDBIT | \
63 XFS_SB_VERSION_LOGV2BIT | \
Nathan Scottd8cc8902005-11-02 10:34:53 +110064 XFS_SB_VERSION_SECTORBIT | \
65 XFS_SB_VERSION_MOREBITSBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define XFS_SB_VERSION_OKREALBITS \
67 (XFS_SB_VERSION_NUMBITS | \
68 XFS_SB_VERSION_OKREALFBITS | \
69 XFS_SB_VERSION_OKSASHFBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/*
72 * There are two words to hold XFS "feature" bits: the original
73 * word, sb_versionnum, and sb_features2. Whenever a bit is set in
74 * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
75 *
76 * These defines represent bits in sb_features2.
77 */
78#define XFS_SB_VERSION2_REALFBITS 0x00ffffff /* Mask: features */
79#define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
David Chinner92821e22007-05-24 15:26:31 +100080#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
Nathan Scottd8cc8902005-11-02 10:34:53 +110081#define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
82#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
Christoph Hellwig6d73cf12008-12-09 04:47:32 -050083#define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +000084#define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
Christoph Hellwigbc02e862012-11-16 09:20:37 +110085#define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87#define XFS_SB_VERSION2_OKREALFBITS \
David Chinner92821e22007-05-24 15:26:31 +100088 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +000089 XFS_SB_VERSION2_ATTR2BIT | \
90 XFS_SB_VERSION2_PROJID32BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define XFS_SB_VERSION2_OKSASHFBITS \
92 (0)
93#define XFS_SB_VERSION2_OKREALBITS \
94 (XFS_SB_VERSION2_OKREALFBITS | \
95 XFS_SB_VERSION2_OKSASHFBITS )
96
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100097/*
98 * Superblock - in core version. Must match the ondisk version below.
David Chinneree1c0902008-03-06 13:45:50 +110099 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000100 */
101typedef struct xfs_sb {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
103 __uint32_t sb_blocksize; /* logical block size, bytes */
104 xfs_drfsbno_t sb_dblocks; /* number of data blocks */
105 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
106 xfs_drtbno_t sb_rextents; /* number of realtime extents */
107 uuid_t sb_uuid; /* file system unique id */
108 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
109 xfs_ino_t sb_rootino; /* root inode number */
110 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
111 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
112 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
113 xfs_agblock_t sb_agblocks; /* size of an allocation group */
114 xfs_agnumber_t sb_agcount; /* number of allocation groups */
115 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
116 xfs_extlen_t sb_logblocks; /* number of log blocks */
117 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
118 __uint16_t sb_sectsize; /* volume sector size, bytes */
119 __uint16_t sb_inodesize; /* inode size, bytes */
120 __uint16_t sb_inopblock; /* inodes per block */
121 char sb_fname[12]; /* file system name */
122 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
123 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
124 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
125 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
126 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
127 __uint8_t sb_rextslog; /* log2 of sb_rextents */
128 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
129 __uint8_t sb_imax_pct; /* max % of fs for inode space */
130 /* statistics */
131 /*
132 * These fields must remain contiguous. If you really
133 * want to change their layout, make sure you fix the
134 * code in xfs_trans_apply_sb_deltas().
135 */
136 __uint64_t sb_icount; /* allocated inodes */
137 __uint64_t sb_ifree; /* free inodes */
138 __uint64_t sb_fdblocks; /* free data blocks */
139 __uint64_t sb_frextents; /* free realtime extents */
140 /*
141 * End contiguous fields.
142 */
143 xfs_ino_t sb_uquotino; /* user quota inode */
144 xfs_ino_t sb_gquotino; /* group quota inode */
145 __uint16_t sb_qflags; /* quota flags */
146 __uint8_t sb_flags; /* misc. flags */
147 __uint8_t sb_shared_vn; /* shared version number */
148 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
149 __uint32_t sb_unit; /* stripe or raid unit */
150 __uint32_t sb_width; /* stripe or raid width */
151 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
152 __uint8_t sb_logsectlog; /* log2 of the log sector size */
153 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
154 __uint32_t sb_logsunit; /* stripe unit size for the log */
Nathan Scottd8cc8902005-11-02 10:34:53 +1100155 __uint32_t sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100156
157 /*
158 * bad features2 field as a result of failing to pad the sb
159 * structure to 64 bits. Some machines will be using this field
160 * for features2 bits. Easiest just to mark it bad and not use
161 * it for anything else.
162 */
163 __uint32_t sb_bad_features2;
164
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100165 /* version 5 superblock fields start here */
166
167 /* feature masks */
168 __uint32_t sb_features_compat;
169 __uint32_t sb_features_ro_compat;
170 __uint32_t sb_features_incompat;
Dave Chinnere721f502013-04-03 16:11:32 +1100171 __uint32_t sb_features_log_incompat;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100172
173 __uint32_t sb_crc; /* superblock crc */
Dave Chinnere721f502013-04-03 16:11:32 +1100174 __uint32_t sb_pad;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100175
176 xfs_ino_t sb_pquotino; /* project quota inode */
177 xfs_lsn_t sb_lsn; /* last write sequence */
178
David Chinneree1c0902008-03-06 13:45:50 +1100179 /* must be padded to 64 bit alignment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180} xfs_sb_t;
181
182/*
David Chinneree1c0902008-03-06 13:45:50 +1100183 * Superblock - on disk version. Must match the in core version above.
184 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000185 */
186typedef struct xfs_dsb {
187 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
188 __be32 sb_blocksize; /* logical block size, bytes */
189 __be64 sb_dblocks; /* number of data blocks */
190 __be64 sb_rblocks; /* number of realtime blocks */
191 __be64 sb_rextents; /* number of realtime extents */
192 uuid_t sb_uuid; /* file system unique id */
193 __be64 sb_logstart; /* starting block of log if internal */
194 __be64 sb_rootino; /* root inode number */
195 __be64 sb_rbmino; /* bitmap inode for realtime extents */
196 __be64 sb_rsumino; /* summary inode for rt bitmap */
197 __be32 sb_rextsize; /* realtime extent size, blocks */
198 __be32 sb_agblocks; /* size of an allocation group */
199 __be32 sb_agcount; /* number of allocation groups */
200 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
201 __be32 sb_logblocks; /* number of log blocks */
202 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
203 __be16 sb_sectsize; /* volume sector size, bytes */
204 __be16 sb_inodesize; /* inode size, bytes */
205 __be16 sb_inopblock; /* inodes per block */
206 char sb_fname[12]; /* file system name */
207 __u8 sb_blocklog; /* log2 of sb_blocksize */
208 __u8 sb_sectlog; /* log2 of sb_sectsize */
209 __u8 sb_inodelog; /* log2 of sb_inodesize */
210 __u8 sb_inopblog; /* log2 of sb_inopblock */
211 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
212 __u8 sb_rextslog; /* log2 of sb_rextents */
213 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
214 __u8 sb_imax_pct; /* max % of fs for inode space */
215 /* statistics */
216 /*
217 * These fields must remain contiguous. If you really
218 * want to change their layout, make sure you fix the
219 * code in xfs_trans_apply_sb_deltas().
220 */
221 __be64 sb_icount; /* allocated inodes */
222 __be64 sb_ifree; /* free inodes */
223 __be64 sb_fdblocks; /* free data blocks */
224 __be64 sb_frextents; /* free realtime extents */
225 /*
226 * End contiguous fields.
227 */
228 __be64 sb_uquotino; /* user quota inode */
229 __be64 sb_gquotino; /* group quota inode */
230 __be16 sb_qflags; /* quota flags */
231 __u8 sb_flags; /* misc. flags */
232 __u8 sb_shared_vn; /* shared version number */
233 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
234 __be32 sb_unit; /* stripe or raid unit */
235 __be32 sb_width; /* stripe or raid width */
236 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
237 __u8 sb_logsectlog; /* log2 of the log sector size */
238 __be16 sb_logsectsize; /* sector size for the log, bytes */
239 __be32 sb_logsunit; /* stripe unit size for the log */
240 __be32 sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100241 /*
242 * bad features2 field as a result of failing to pad the sb
243 * structure to 64 bits. Some machines will be using this field
244 * for features2 bits. Easiest just to mark it bad and not use
245 * it for anything else.
246 */
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100247 __be32 sb_bad_features2;
248
249 /* version 5 superblock fields start here */
250
251 /* feature masks */
252 __be32 sb_features_compat;
253 __be32 sb_features_ro_compat;
254 __be32 sb_features_incompat;
Dave Chinnere721f502013-04-03 16:11:32 +1100255 __be32 sb_features_log_incompat;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100256
257 __le32 sb_crc; /* superblock crc */
Dave Chinnere721f502013-04-03 16:11:32 +1100258 __be32 sb_pad;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100259
260 __be64 sb_pquotino; /* project quota inode */
261 __be64 sb_lsn; /* last write sequence */
David Chinneree1c0902008-03-06 13:45:50 +1100262
263 /* must be padded to 64 bit alignment */
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000264} xfs_dsb_t;
265
266/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 * Sequence number values for the fields.
268 */
269typedef enum {
270 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
271 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
272 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
273 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
274 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
275 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
276 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
277 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
278 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
279 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
280 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
281 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100282 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2, XFS_SBS_FEATURES_COMPAT,
Dave Chinnere721f502013-04-03 16:11:32 +1100283 XFS_SBS_FEATURES_RO_COMPAT, XFS_SBS_FEATURES_INCOMPAT,
284 XFS_SBS_FEATURES_LOG_INCOMPAT, XFS_SBS_CRC, XFS_SBS_PAD,
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100285 XFS_SBS_PQUOTINO, XFS_SBS_LSN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 XFS_SBS_FIELDCOUNT
287} xfs_sb_field_t;
288
289/*
290 * Mask values, defined based on the xfs_sb_field_t values.
291 * Only define the ones we're using.
292 */
293#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
294#define XFS_SB_UUID XFS_SB_MVAL(UUID)
295#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
296#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
297#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
298#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
299#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
300#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
301#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
302#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
303#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
304#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
305#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
David Chinner92821e22007-05-24 15:26:31 +1000306#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
307#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
308#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100309#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
David Chinneree1c0902008-03-06 13:45:50 +1100310#define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100311#define XFS_SB_FEATURES_COMPAT XFS_SB_MVAL(FEATURES_COMPAT)
312#define XFS_SB_FEATURES_RO_COMPAT XFS_SB_MVAL(FEATURES_RO_COMPAT)
313#define XFS_SB_FEATURES_INCOMPAT XFS_SB_MVAL(FEATURES_INCOMPAT)
Dave Chinnere721f502013-04-03 16:11:32 +1100314#define XFS_SB_FEATURES_LOG_INCOMPAT XFS_SB_MVAL(FEATURES_LOG_INCOMPAT)
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100315#define XFS_SB_CRC XFS_SB_MVAL(CRC)
316#define XFS_SB_PQUOTINO XFS_SB_MVAL(PQUOTINO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
318#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
319#define XFS_SB_MOD_BITS \
320 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
321 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
Nathan Scottd8cc8902005-11-02 10:34:53 +1100322 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
David Chinneree1c0902008-03-06 13:45:50 +1100323 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100324 XFS_SB_BAD_FEATURES2 | XFS_SB_FEATURES_COMPAT | \
Dave Chinnere721f502013-04-03 16:11:32 +1100325 XFS_SB_FEATURES_RO_COMPAT | XFS_SB_FEATURES_INCOMPAT | \
326 XFS_SB_FEATURES_LOG_INCOMPAT | XFS_SB_PQUOTINO)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329/*
330 * Misc. Flags - warning - these will be cleared by xfs_repair unless
331 * a feature bit is set when the flag is used.
332 */
333#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
334#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
335
336/*
337 * define max. shared version we can interoperate with
338 */
339#define XFS_SB_MAX_SHARED_VN 0
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100343static inline int xfs_sb_good_version(xfs_sb_t *sbp)
344{
345 /* We always support version 1-3 */
346 if (sbp->sb_versionnum >= XFS_SB_VERSION_1 &&
347 sbp->sb_versionnum <= XFS_SB_VERSION_3)
348 return 1;
349
350 /* We support version 4 if all feature bits are supported */
351 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) {
352 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) ||
353 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
354 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS)))
355 return 0;
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357#ifdef __KERNEL__
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100358 if (sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
359 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#else
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100361 if ((sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) &&
362 sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
363 return 0;
364#endif
365
366 return 1;
367 }
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100368 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
369 return 1;
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100370
371 return 0;
Nathan Scotta844f452005-11-02 14:38:42 +1100372}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
David Chinneree1c0902008-03-06 13:45:50 +1100374/*
Eric Sandeene6957ea2008-04-10 12:19:34 +1000375 * Detect a mismatched features2 field. Older kernels read/wrote
376 * this into the wrong slot, so to be safe we keep them in sync.
David Chinneree1c0902008-03-06 13:45:50 +1100377 */
Eric Sandeene6957ea2008-04-10 12:19:34 +1000378static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp)
David Chinneree1c0902008-03-06 13:45:50 +1100379{
Eric Sandeene6957ea2008-04-10 12:19:34 +1000380 return (sbp->sb_bad_features2 != sbp->sb_features2);
David Chinneree1c0902008-03-06 13:45:50 +1100381}
382
Nathan Scotta844f452005-11-02 14:38:42 +1100383static inline unsigned xfs_sb_version_tonew(unsigned v)
384{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100385 if (v == XFS_SB_VERSION_1)
386 return XFS_SB_VERSION_4;
387
388 if (v == XFS_SB_VERSION_2)
389 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
390
391 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT |
392 XFS_SB_VERSION_NLINKBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100393}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Nathan Scotta844f452005-11-02 14:38:42 +1100395static inline unsigned xfs_sb_version_toold(unsigned v)
396{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100397 if (v & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT))
398 return 0;
399 if (v & XFS_SB_VERSION_NLINKBIT)
400 return XFS_SB_VERSION_3;
401 if (v & XFS_SB_VERSION_ATTRBIT)
402 return XFS_SB_VERSION_2;
403 return XFS_SB_VERSION_1;
Nathan Scotta844f452005-11-02 14:38:42 +1100404}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Nathan Scotta844f452005-11-02 14:38:42 +1100406static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
407{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100408 return sbp->sb_versionnum == XFS_SB_VERSION_2 ||
409 sbp->sb_versionnum == XFS_SB_VERSION_3 ||
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100410 (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100411 (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100412}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Nathan Scotta844f452005-11-02 14:38:42 +1100414static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
415{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100416 if (sbp->sb_versionnum == XFS_SB_VERSION_1)
417 sbp->sb_versionnum = XFS_SB_VERSION_2;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100418 else if (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4)
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100419 sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
420 else
421 sbp->sb_versionnum = XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100422}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Nathan Scotta844f452005-11-02 14:38:42 +1100424static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
425{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100426 return sbp->sb_versionnum == XFS_SB_VERSION_3 ||
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100427 (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100428 (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100429}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Nathan Scotta844f452005-11-02 14:38:42 +1100431static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
432{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100433 if (sbp->sb_versionnum <= XFS_SB_VERSION_2)
434 sbp->sb_versionnum = XFS_SB_VERSION_3;
435 else
436 sbp->sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100437}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Nathan Scotta844f452005-11-02 14:38:42 +1100439static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
440{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100441 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100442 (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100443}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Nathan Scotta844f452005-11-02 14:38:42 +1100445static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
446{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100447 if (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4)
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100448 sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
449 else
450 sbp->sb_versionnum = xfs_sb_version_tonew(sbp->sb_versionnum) |
451 XFS_SB_VERSION_QUOTABIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100452}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Nathan Scotta844f452005-11-02 14:38:42 +1100454static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
455{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100456 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
457 (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
458 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100459}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Nathan Scotta844f452005-11-02 14:38:42 +1100461static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
462{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100463 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100464 (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100465}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Nathan Scotta844f452005-11-02 14:38:42 +1100467static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
468{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100469 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
470 (sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100471}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Nathan Scotta844f452005-11-02 14:38:42 +1100473static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
474{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100475 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
476 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
477 (sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100478}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Nathan Scotta844f452005-11-02 14:38:42 +1100480static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
481{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100482 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
483 (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
484 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100485}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Nathan Scotta844f452005-11-02 14:38:42 +1100487static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
488{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100489 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
490 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
491 (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100492}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Nathan Scotta844f452005-11-02 14:38:42 +1100494static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
495{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100496 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100497 (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100498}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Barry Naujok189f4bf2008-05-21 16:58:55 +1000500static inline int xfs_sb_version_hasasciici(xfs_sb_t *sbp)
501{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100502 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
Barry Naujok189f4bf2008-05-21 16:58:55 +1000503 (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
504}
505
Nathan Scotta844f452005-11-02 14:38:42 +1100506static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
507{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100508 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
509 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
510 (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100511}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513/*
514 * sb_features2 bit version macros.
515 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100516 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 *
Nathan Scottd8cc8902005-11-02 10:34:53 +1100518 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
Eric Sandeen62118702008-03-06 13:44:28 +1100519 * ((xfs_sb_version_hasmorebits(sbp) &&
Nathan Scottd8cc8902005-11-02 10:34:53 +1100520 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 */
522
David Chinner92821e22007-05-24 15:26:31 +1000523static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
524{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100525 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
526 (xfs_sb_version_hasmorebits(sbp) &&
527 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
David Chinner92821e22007-05-24 15:26:31 +1000528}
529
Nathan Scotta844f452005-11-02 14:38:42 +1100530static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
531{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100532 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
533 (xfs_sb_version_hasmorebits(sbp) &&
534 (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100535}
536
Nathan Scotta844f452005-11-02 14:38:42 +1100537static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
538{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100539 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
540 sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100541}
542
Tim Shimmin7c12f292008-04-30 18:15:28 +1000543static inline void xfs_sb_version_removeattr2(xfs_sb_t *sbp)
544{
545 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
546 if (!sbp->sb_features2)
547 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
548}
549
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000550static inline int xfs_sb_version_hasprojid32bit(xfs_sb_t *sbp)
551{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100552 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
553 (xfs_sb_version_hasmorebits(sbp) &&
554 (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT));
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000555}
556
Christoph Hellwigbc02e862012-11-16 09:20:37 +1100557static inline int xfs_sb_version_hascrc(xfs_sb_t *sbp)
558{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100559 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
Christoph Hellwigbc02e862012-11-16 09:20:37 +1100560}
561
Dave Chinnere721f502013-04-03 16:11:32 +1100562
563/*
564 * Extended v5 superblock feature masks. These are to be used for new v5
565 * superblock features only.
566 *
567 * Compat features are new features that old kernels will not notice or affect
568 * and so can mount read-write without issues.
569 *
570 * RO-Compat (read only) are features that old kernels can read but will break
571 * if they write. Hence only read-only mounts of such filesystems are allowed on
572 * kernels that don't support the feature bit.
573 *
574 * InCompat features are features which old kernels will not understand and so
575 * must not mount.
576 *
577 * Log-InCompat features are for changes to log formats or new transactions that
578 * can't be replayed on older kernels. The fields are set when the filesystem is
579 * mounted, and a clean unmount clears the fields.
580 */
581#define XFS_SB_FEAT_COMPAT_ALL 0
582#define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL
583static inline bool
584xfs_sb_has_compat_feature(
585 struct xfs_sb *sbp,
586 __uint32_t feature)
587{
588 return (sbp->sb_features_compat & feature) != 0;
589}
590
591#define XFS_SB_FEAT_RO_COMPAT_ALL 0
592#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL
593static inline bool
594xfs_sb_has_ro_compat_feature(
595 struct xfs_sb *sbp,
596 __uint32_t feature)
597{
598 return (sbp->sb_features_ro_compat & feature) != 0;
599}
600
601#define XFS_SB_FEAT_INCOMPAT_ALL 0
602#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL
603static inline bool
604xfs_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
613static inline bool
614xfs_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
Chandra Seetharaman9cad19d2013-06-27 17:25:04 -0500621static inline bool
622xfs_is_quota_inode(struct xfs_sb *sbp, xfs_ino_t ino)
623{
624 return (ino == sbp->sb_uquotino || ino == sbp->sb_gquotino);
625}
626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627/*
628 * end of superblock version macros
629 */
630
Nathan Scotta844f452005-11-02 14:38:42 +1100631#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
Chandra Seetharaman62926042011-07-22 23:40:15 +0000633#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
Nathan Scotta844f452005-11-02 14:38:42 +1100634
635#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
636#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
Eric Sandeenb6e32222009-01-14 23:22:07 -0600637 xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
Nathan Scotta844f452005-11-02 14:38:42 +1100638#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
639 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641/*
642 * File system sector to basic block conversions.
643 */
644#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646/*
647 * File system block to basic block conversions.
648 */
649#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
650#define XFS_BB_TO_FSB(mp,bb) \
651 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
652#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654/*
655 * File system block to byte conversions.
656 */
657#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
658#define XFS_B_TO_FSB(mp,b) \
659 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
660#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
661#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
662
663#endif /* __XFS_SB_H__ */