blob: a6a76f41aad2e3da33d4f20f951aaacafd72f41c [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;
Dave Chinnerff550682013-08-12 20:49:41 +100029struct xfs_trans;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */
32#define XFS_SB_VERSION_1 1 /* 5.3, 6.0.1, 6.1 */
33#define XFS_SB_VERSION_2 2 /* 6.2 - attributes */
34#define XFS_SB_VERSION_3 3 /* 6.2 - new inode version */
35#define XFS_SB_VERSION_4 4 /* 6.2+ - bitmask version */
Dave Chinner04a1e6c2013-04-03 16:11:31 +110036#define XFS_SB_VERSION_5 5 /* CRC enabled filesystem */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define XFS_SB_VERSION_NUMBITS 0x000f
38#define XFS_SB_VERSION_ALLFBITS 0xfff0
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define XFS_SB_VERSION_ATTRBIT 0x0010
40#define XFS_SB_VERSION_NLINKBIT 0x0020
41#define XFS_SB_VERSION_QUOTABIT 0x0040
42#define XFS_SB_VERSION_ALIGNBIT 0x0080
43#define XFS_SB_VERSION_DALIGNBIT 0x0100
44#define XFS_SB_VERSION_SHAREDBIT 0x0200
45#define XFS_SB_VERSION_LOGV2BIT 0x0400
46#define XFS_SB_VERSION_SECTORBIT 0x0800
47#define XFS_SB_VERSION_EXTFLGBIT 0x1000
48#define XFS_SB_VERSION_DIRV2BIT 0x2000
Barry Naujok189f4bf2008-05-21 16:58:55 +100049#define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define XFS_SB_VERSION_MOREBITSBIT 0x8000
Dave Chinnerf68a3732014-05-20 07:41:16 +100051
52/*
53 * Supported feature bit list is just all bits in the versionnum field because
54 * we've used them all up and understand them all.
55 */
56#define XFS_SB_VERSION_OKBITS \
57 (XFS_SB_VERSION_NUMBITS | \
58 XFS_SB_VERSION_ALLFBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*
61 * There are two words to hold XFS "feature" bits: the original
62 * word, sb_versionnum, and sb_features2. Whenever a bit is set in
63 * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
64 *
65 * These defines represent bits in sb_features2.
66 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
David Chinner92821e22007-05-24 15:26:31 +100068#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
Nathan Scottd8cc8902005-11-02 10:34:53 +110069#define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
70#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
Christoph Hellwig6d73cf12008-12-09 04:47:32 -050071#define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +000072#define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
Christoph Hellwigbc02e862012-11-16 09:20:37 +110073#define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */
Mark Tinguely3e3c51c2013-08-19 15:19:36 -050074#define XFS_SB_VERSION2_FTYPE 0x00000200 /* inode type in dir */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Dave Chinnerf68a3732014-05-20 07:41:16 +100076#define XFS_SB_VERSION2_OKBITS \
David Chinner92821e22007-05-24 15:26:31 +100077 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +000078 XFS_SB_VERSION2_ATTR2BIT | \
Mark Tinguely3e3c51c2013-08-19 15:19:36 -050079 XFS_SB_VERSION2_PROJID32BIT | \
80 XFS_SB_VERSION2_FTYPE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100082/*
83 * Superblock - in core version. Must match the ondisk version below.
David Chinneree1c0902008-03-06 13:45:50 +110084 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +100085 */
86typedef struct xfs_sb {
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
88 __uint32_t sb_blocksize; /* logical block size, bytes */
89 xfs_drfsbno_t sb_dblocks; /* number of data blocks */
90 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */
91 xfs_drtbno_t sb_rextents; /* number of realtime extents */
92 uuid_t sb_uuid; /* file system unique id */
93 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */
94 xfs_ino_t sb_rootino; /* root inode number */
95 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
96 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
97 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
98 xfs_agblock_t sb_agblocks; /* size of an allocation group */
99 xfs_agnumber_t sb_agcount; /* number of allocation groups */
100 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
101 xfs_extlen_t sb_logblocks; /* number of log blocks */
102 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
103 __uint16_t sb_sectsize; /* volume sector size, bytes */
104 __uint16_t sb_inodesize; /* inode size, bytes */
105 __uint16_t sb_inopblock; /* inodes per block */
106 char sb_fname[12]; /* file system name */
107 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
108 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
109 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
110 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
111 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
112 __uint8_t sb_rextslog; /* log2 of sb_rextents */
113 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
114 __uint8_t sb_imax_pct; /* max % of fs for inode space */
115 /* statistics */
116 /*
117 * These fields must remain contiguous. If you really
118 * want to change their layout, make sure you fix the
119 * code in xfs_trans_apply_sb_deltas().
120 */
121 __uint64_t sb_icount; /* allocated inodes */
122 __uint64_t sb_ifree; /* free inodes */
123 __uint64_t sb_fdblocks; /* free data blocks */
124 __uint64_t sb_frextents; /* free realtime extents */
125 /*
126 * End contiguous fields.
127 */
128 xfs_ino_t sb_uquotino; /* user quota inode */
129 xfs_ino_t sb_gquotino; /* group quota inode */
130 __uint16_t sb_qflags; /* quota flags */
131 __uint8_t sb_flags; /* misc. flags */
132 __uint8_t sb_shared_vn; /* shared version number */
133 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
134 __uint32_t sb_unit; /* stripe or raid unit */
135 __uint32_t sb_width; /* stripe or raid width */
136 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
137 __uint8_t sb_logsectlog; /* log2 of the log sector size */
138 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
139 __uint32_t sb_logsunit; /* stripe unit size for the log */
Nathan Scottd8cc8902005-11-02 10:34:53 +1100140 __uint32_t sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100141
142 /*
143 * bad features2 field as a result of failing to pad the sb
144 * structure to 64 bits. Some machines will be using this field
145 * for features2 bits. Easiest just to mark it bad and not use
146 * it for anything else.
147 */
148 __uint32_t sb_bad_features2;
149
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100150 /* version 5 superblock fields start here */
151
152 /* feature masks */
153 __uint32_t sb_features_compat;
154 __uint32_t sb_features_ro_compat;
155 __uint32_t sb_features_incompat;
Dave Chinnere721f502013-04-03 16:11:32 +1100156 __uint32_t sb_features_log_incompat;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100157
158 __uint32_t sb_crc; /* superblock crc */
Dave Chinnere721f502013-04-03 16:11:32 +1100159 __uint32_t sb_pad;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100160
161 xfs_ino_t sb_pquotino; /* project quota inode */
162 xfs_lsn_t sb_lsn; /* last write sequence */
163
David Chinneree1c0902008-03-06 13:45:50 +1100164 /* must be padded to 64 bit alignment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165} xfs_sb_t;
166
Eric Sandeen533b81c2014-02-27 15:15:27 +1100167#define XFS_SB_CRC_OFF offsetof(struct xfs_sb, sb_crc)
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/*
David Chinneree1c0902008-03-06 13:45:50 +1100170 * Superblock - on disk version. Must match the in core version above.
171 * Must be padded to 64 bit alignment.
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000172 */
173typedef struct xfs_dsb {
174 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
175 __be32 sb_blocksize; /* logical block size, bytes */
176 __be64 sb_dblocks; /* number of data blocks */
177 __be64 sb_rblocks; /* number of realtime blocks */
178 __be64 sb_rextents; /* number of realtime extents */
179 uuid_t sb_uuid; /* file system unique id */
180 __be64 sb_logstart; /* starting block of log if internal */
181 __be64 sb_rootino; /* root inode number */
182 __be64 sb_rbmino; /* bitmap inode for realtime extents */
183 __be64 sb_rsumino; /* summary inode for rt bitmap */
184 __be32 sb_rextsize; /* realtime extent size, blocks */
185 __be32 sb_agblocks; /* size of an allocation group */
186 __be32 sb_agcount; /* number of allocation groups */
187 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
188 __be32 sb_logblocks; /* number of log blocks */
189 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
190 __be16 sb_sectsize; /* volume sector size, bytes */
191 __be16 sb_inodesize; /* inode size, bytes */
192 __be16 sb_inopblock; /* inodes per block */
193 char sb_fname[12]; /* file system name */
194 __u8 sb_blocklog; /* log2 of sb_blocksize */
195 __u8 sb_sectlog; /* log2 of sb_sectsize */
196 __u8 sb_inodelog; /* log2 of sb_inodesize */
197 __u8 sb_inopblog; /* log2 of sb_inopblock */
198 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
199 __u8 sb_rextslog; /* log2 of sb_rextents */
200 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
201 __u8 sb_imax_pct; /* max % of fs for inode space */
202 /* statistics */
203 /*
204 * These fields must remain contiguous. If you really
205 * want to change their layout, make sure you fix the
206 * code in xfs_trans_apply_sb_deltas().
207 */
208 __be64 sb_icount; /* allocated inodes */
209 __be64 sb_ifree; /* free inodes */
210 __be64 sb_fdblocks; /* free data blocks */
211 __be64 sb_frextents; /* free realtime extents */
212 /*
213 * End contiguous fields.
214 */
215 __be64 sb_uquotino; /* user quota inode */
216 __be64 sb_gquotino; /* group quota inode */
217 __be16 sb_qflags; /* quota flags */
218 __u8 sb_flags; /* misc. flags */
219 __u8 sb_shared_vn; /* shared version number */
220 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
221 __be32 sb_unit; /* stripe or raid unit */
222 __be32 sb_width; /* stripe or raid width */
223 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
224 __u8 sb_logsectlog; /* log2 of the log sector size */
225 __be16 sb_logsectsize; /* sector size for the log, bytes */
226 __be32 sb_logsunit; /* stripe unit size for the log */
227 __be32 sb_features2; /* additional feature bits */
David Chinneree1c0902008-03-06 13:45:50 +1100228 /*
229 * bad features2 field as a result of failing to pad the sb
230 * structure to 64 bits. Some machines will be using this field
231 * for features2 bits. Easiest just to mark it bad and not use
232 * it for anything else.
233 */
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100234 __be32 sb_bad_features2;
235
236 /* version 5 superblock fields start here */
237
238 /* feature masks */
239 __be32 sb_features_compat;
240 __be32 sb_features_ro_compat;
241 __be32 sb_features_incompat;
Dave Chinnere721f502013-04-03 16:11:32 +1100242 __be32 sb_features_log_incompat;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100243
244 __le32 sb_crc; /* superblock crc */
Dave Chinnere721f502013-04-03 16:11:32 +1100245 __be32 sb_pad;
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100246
247 __be64 sb_pquotino; /* project quota inode */
248 __be64 sb_lsn; /* last write sequence */
David Chinneree1c0902008-03-06 13:45:50 +1100249
250 /* must be padded to 64 bit alignment */
Christoph Hellwig2bdf7cd2007-08-28 13:58:06 +1000251} xfs_dsb_t;
252
253/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 * Sequence number values for the fields.
255 */
256typedef enum {
257 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
258 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
259 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
260 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
261 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
262 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
263 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
264 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
265 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
266 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
267 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
268 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100269 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2, XFS_SBS_FEATURES_COMPAT,
Dave Chinnere721f502013-04-03 16:11:32 +1100270 XFS_SBS_FEATURES_RO_COMPAT, XFS_SBS_FEATURES_INCOMPAT,
271 XFS_SBS_FEATURES_LOG_INCOMPAT, XFS_SBS_CRC, XFS_SBS_PAD,
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100272 XFS_SBS_PQUOTINO, XFS_SBS_LSN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 XFS_SBS_FIELDCOUNT
274} xfs_sb_field_t;
275
276/*
277 * Mask values, defined based on the xfs_sb_field_t values.
278 * Only define the ones we're using.
279 */
280#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
281#define XFS_SB_UUID XFS_SB_MVAL(UUID)
282#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
283#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
284#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
285#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
286#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
287#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
288#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
289#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
290#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
291#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
292#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
David Chinner92821e22007-05-24 15:26:31 +1000293#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
294#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
295#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100296#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
David Chinneree1c0902008-03-06 13:45:50 +1100297#define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100298#define XFS_SB_FEATURES_COMPAT XFS_SB_MVAL(FEATURES_COMPAT)
299#define XFS_SB_FEATURES_RO_COMPAT XFS_SB_MVAL(FEATURES_RO_COMPAT)
300#define XFS_SB_FEATURES_INCOMPAT XFS_SB_MVAL(FEATURES_INCOMPAT)
Dave Chinnere721f502013-04-03 16:11:32 +1100301#define XFS_SB_FEATURES_LOG_INCOMPAT XFS_SB_MVAL(FEATURES_LOG_INCOMPAT)
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100302#define XFS_SB_CRC XFS_SB_MVAL(CRC)
303#define XFS_SB_PQUOTINO XFS_SB_MVAL(PQUOTINO)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
305#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
306#define XFS_SB_MOD_BITS \
307 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
308 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
Nathan Scottd8cc8902005-11-02 10:34:53 +1100309 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
David Chinneree1c0902008-03-06 13:45:50 +1100310 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100311 XFS_SB_BAD_FEATURES2 | XFS_SB_FEATURES_COMPAT | \
Dave Chinnere721f502013-04-03 16:11:32 +1100312 XFS_SB_FEATURES_RO_COMPAT | XFS_SB_FEATURES_INCOMPAT | \
313 XFS_SB_FEATURES_LOG_INCOMPAT | XFS_SB_PQUOTINO)
Nathan Scottd8cc8902005-11-02 10:34:53 +1100314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316/*
317 * Misc. Flags - warning - these will be cleared by xfs_repair unless
318 * a feature bit is set when the flag is used.
319 */
320#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
321#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
322
323/*
324 * define max. shared version we can interoperate with
325 */
326#define XFS_SB_MAX_SHARED_VN 0
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Dave Chinnerf68a3732014-05-20 07:41:16 +1000330/*
331 * The first XFS version we support is a v4 superblock with V2 directories.
332 */
333static inline bool xfs_sb_good_v4_features(struct xfs_sb *sbp)
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100334{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000335 if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
336 return false;
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100337
Dave Chinnerf68a3732014-05-20 07:41:16 +1000338 /* check for unknown features in the fs */
339 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
340 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
341 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
342 return false;
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100343
Dave Chinnerf68a3732014-05-20 07:41:16 +1000344 /* We don't support shared superblocks - nobody knows what it is */
345 if (sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT)
346 return false;
347
348 return true;
349}
350
351static inline bool xfs_sb_good_version(struct xfs_sb *sbp)
352{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100353 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
Dave Chinnerf68a3732014-05-20 07:41:16 +1000354 return true;
355 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
356 return xfs_sb_good_v4_features(sbp);
357 return false;
Nathan Scotta844f452005-11-02 14:38:42 +1100358}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
David Chinneree1c0902008-03-06 13:45:50 +1100360/*
Eric Sandeene6957ea42008-04-10 12:19:34 +1000361 * Detect a mismatched features2 field. Older kernels read/wrote
362 * this into the wrong slot, so to be safe we keep them in sync.
David Chinneree1c0902008-03-06 13:45:50 +1100363 */
Dave Chinnerf68a3732014-05-20 07:41:16 +1000364static inline bool xfs_sb_has_mismatched_features2(struct xfs_sb *sbp)
David Chinneree1c0902008-03-06 13:45:50 +1100365{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000366 return sbp->sb_bad_features2 != sbp->sb_features2;
David Chinneree1c0902008-03-06 13:45:50 +1100367}
368
Dave Chinnerf68a3732014-05-20 07:41:16 +1000369static inline bool xfs_sb_version_hasattr(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100370{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000371 return (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100372}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Dave Chinnerf68a3732014-05-20 07:41:16 +1000374static inline void xfs_sb_version_addattr(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100375{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000376 sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100377}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Dave Chinnerf68a3732014-05-20 07:41:16 +1000379static inline bool xfs_sb_version_hasnlink(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100380{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000381 return (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100382}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Dave Chinnerf68a3732014-05-20 07:41:16 +1000384static inline void xfs_sb_version_addnlink(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100385{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000386 sbp->sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100387}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Dave Chinnerf68a3732014-05-20 07:41:16 +1000389static inline bool xfs_sb_version_hasquota(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100390{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000391 return (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100392}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Dave Chinnerf68a3732014-05-20 07:41:16 +1000394static inline void xfs_sb_version_addquota(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100395{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000396 sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100397}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Dave Chinnerf68a3732014-05-20 07:41:16 +1000399static inline bool xfs_sb_version_hasalign(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100400{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000401 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100402 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100403}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Dave Chinnerf68a3732014-05-20 07:41:16 +1000405static inline bool xfs_sb_version_hasdalign(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100406{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000407 return (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100408}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Dave Chinnerf68a3732014-05-20 07:41:16 +1000410static inline bool xfs_sb_version_hasshared(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100411{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100412 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
413 (sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100414}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Dave Chinnerf68a3732014-05-20 07:41:16 +1000416static inline bool xfs_sb_version_hasdirv2(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100417{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000418 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
419 (sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100420}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Dave Chinnerf68a3732014-05-20 07:41:16 +1000422static inline bool xfs_sb_version_haslogv2(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100423{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000424 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
425 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100426}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Dave Chinnerf68a3732014-05-20 07:41:16 +1000428static inline bool xfs_sb_version_hasextflgbit(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100429{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000430 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
431 (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100432}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Dave Chinnerf68a3732014-05-20 07:41:16 +1000434static inline bool xfs_sb_version_hassector(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100435{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000436 return (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100437}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Dave Chinnerf68a3732014-05-20 07:41:16 +1000439static inline bool xfs_sb_version_hasasciici(struct xfs_sb *sbp)
Barry Naujok189f4bf2008-05-21 16:58:55 +1000440{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000441 return (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
Barry Naujok189f4bf2008-05-21 16:58:55 +1000442}
443
Dave Chinnerf68a3732014-05-20 07:41:16 +1000444static inline bool xfs_sb_version_hasmorebits(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100445{
Dave Chinnerf68a3732014-05-20 07:41:16 +1000446 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
447 (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
Nathan Scotta844f452005-11-02 14:38:42 +1100448}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450/*
451 * sb_features2 bit version macros.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 */
Dave Chinnerf68a3732014-05-20 07:41:16 +1000453static inline bool xfs_sb_version_haslazysbcount(struct xfs_sb *sbp)
David Chinner92821e22007-05-24 15:26:31 +1000454{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100455 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
456 (xfs_sb_version_hasmorebits(sbp) &&
457 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
David Chinner92821e22007-05-24 15:26:31 +1000458}
459
Dave Chinnerf68a3732014-05-20 07:41:16 +1000460static inline bool xfs_sb_version_hasattr2(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100461{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100462 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
463 (xfs_sb_version_hasmorebits(sbp) &&
464 (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT));
Nathan Scotta844f452005-11-02 14:38:42 +1100465}
466
Dave Chinnerf68a3732014-05-20 07:41:16 +1000467static inline void xfs_sb_version_addattr2(struct xfs_sb *sbp)
Nathan Scotta844f452005-11-02 14:38:42 +1100468{
Christoph Hellwig5efcbb82008-12-03 12:20:31 +0100469 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
470 sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
Dave Chinner32bf1de2014-05-20 07:41:43 +1000471 sbp->sb_bad_features2 |= XFS_SB_VERSION2_ATTR2BIT;
Nathan Scotta844f452005-11-02 14:38:42 +1100472}
473
Dave Chinnerf68a3732014-05-20 07:41:16 +1000474static inline void xfs_sb_version_removeattr2(struct xfs_sb *sbp)
Tim Shimmin7c12f292008-04-30 18:15:28 +1000475{
476 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
Dave Chinner32bf1de2014-05-20 07:41:43 +1000477 sbp->sb_bad_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
Tim Shimmin7c12f292008-04-30 18:15:28 +1000478 if (!sbp->sb_features2)
479 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
480}
481
Dave Chinnerf68a3732014-05-20 07:41:16 +1000482static inline bool xfs_sb_version_hasprojid32bit(struct xfs_sb *sbp)
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000483{
Dave Chinner04a1e6c2013-04-03 16:11:31 +1100484 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
485 (xfs_sb_version_hasmorebits(sbp) &&
486 (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT));
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +0000487}
488
Dave Chinnerf68a3732014-05-20 07:41:16 +1000489static inline void xfs_sb_version_addprojid32bit(struct xfs_sb *sbp)
Dave Chinnerd386b322013-08-12 20:49:31 +1000490{
491 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
492 sbp->sb_features2 |= XFS_SB_VERSION2_PROJID32BIT;
493 sbp->sb_bad_features2 |= XFS_SB_VERSION2_PROJID32BIT;
494}
495
Dave Chinnere721f502013-04-03 16:11:32 +1100496/*
497 * Extended v5 superblock feature masks. These are to be used for new v5
498 * superblock features only.
499 *
500 * Compat features are new features that old kernels will not notice or affect
501 * and so can mount read-write without issues.
502 *
503 * RO-Compat (read only) are features that old kernels can read but will break
504 * if they write. Hence only read-only mounts of such filesystems are allowed on
505 * kernels that don't support the feature bit.
506 *
507 * InCompat features are features which old kernels will not understand and so
508 * must not mount.
509 *
510 * Log-InCompat features are for changes to log formats or new transactions that
511 * can't be replayed on older kernels. The fields are set when the filesystem is
512 * mounted, and a clean unmount clears the fields.
513 */
514#define XFS_SB_FEAT_COMPAT_ALL 0
515#define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL
516static inline bool
517xfs_sb_has_compat_feature(
518 struct xfs_sb *sbp,
519 __uint32_t feature)
520{
521 return (sbp->sb_features_compat & feature) != 0;
522}
523
524#define XFS_SB_FEAT_RO_COMPAT_ALL 0
525#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL
526static inline bool
527xfs_sb_has_ro_compat_feature(
528 struct xfs_sb *sbp,
529 __uint32_t feature)
530{
531 return (sbp->sb_features_ro_compat & feature) != 0;
532}
533
Dave Chinner0cb97762013-08-12 20:50:09 +1000534#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */
Dave Chinner1c55cec2013-08-12 20:50:10 +1000535#define XFS_SB_FEAT_INCOMPAT_ALL \
536 (XFS_SB_FEAT_INCOMPAT_FTYPE)
Dave Chinner0cb97762013-08-12 20:50:09 +1000537
Dave Chinnere721f502013-04-03 16:11:32 +1100538#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL
539static inline bool
540xfs_sb_has_incompat_feature(
541 struct xfs_sb *sbp,
542 __uint32_t feature)
543{
544 return (sbp->sb_features_incompat & feature) != 0;
545}
546
547#define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0
548#define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_LOG_ALL
549static inline bool
550xfs_sb_has_incompat_log_feature(
551 struct xfs_sb *sbp,
552 __uint32_t feature)
553{
554 return (sbp->sb_features_log_incompat & feature) != 0;
555}
556
Dave Chinner0cb97762013-08-12 20:50:09 +1000557/*
558 * V5 superblock specific feature checks
559 */
Dave Chinnerf68a3732014-05-20 07:41:16 +1000560static inline int xfs_sb_version_hascrc(struct xfs_sb *sbp)
Dave Chinner0cb97762013-08-12 20:50:09 +1000561{
562 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
563}
564
Dave Chinnerf68a3732014-05-20 07:41:16 +1000565static inline int xfs_sb_version_has_pquotino(struct xfs_sb *sbp)
Chandra Seetharaman9cad19d2013-06-27 17:25:04 -0500566{
Chandra Seetharamand892d582013-07-19 17:36:02 -0500567 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
Chandra Seetharaman9cad19d2013-06-27 17:25:04 -0500568}
569
Dave Chinner0cb97762013-08-12 20:50:09 +1000570static inline int xfs_sb_version_hasftype(struct xfs_sb *sbp)
571{
Mark Tinguely3e3c51c2013-08-19 15:19:36 -0500572 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
573 xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_FTYPE)) ||
574 (xfs_sb_version_hasmorebits(sbp) &&
575 (sbp->sb_features2 & XFS_SB_VERSION2_FTYPE));
Dave Chinner0cb97762013-08-12 20:50:09 +1000576}
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/*
579 * end of superblock version macros
580 */
581
Chandra Seetharamand892d582013-07-19 17:36:02 -0500582static inline bool
583xfs_is_quota_inode(struct xfs_sb *sbp, xfs_ino_t ino)
584{
585 return (ino == sbp->sb_uquotino ||
586 ino == sbp->sb_gquotino ||
587 ino == sbp->sb_pquotino);
588}
589
Nathan Scotta844f452005-11-02 14:38:42 +1100590#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
Chandra Seetharaman62926042011-07-22 23:40:15 +0000592#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
Nathan Scotta844f452005-11-02 14:38:42 +1100593
594#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
595#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
Eric Sandeenb6e32222009-01-14 23:22:07 -0600596 xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
Nathan Scotta844f452005-11-02 14:38:42 +1100597#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
598 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600/*
601 * File system sector to basic block conversions.
602 */
603#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605/*
606 * File system block to basic block conversions.
607 */
608#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
609#define XFS_BB_TO_FSB(mp,bb) \
610 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
611#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613/*
614 * File system block to byte conversions.
615 */
616#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
617#define XFS_B_TO_FSB(mp,b) \
618 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
619#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
620#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
621
Dave Chinnerff550682013-08-12 20:49:41 +1000622/*
623 * perag get/put wrappers for ref counting
624 */
625extern struct xfs_perag *xfs_perag_get(struct xfs_mount *, xfs_agnumber_t);
626extern struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *, xfs_agnumber_t,
627 int tag);
628extern void xfs_perag_put(struct xfs_perag *pag);
629extern int xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
630
631extern void xfs_sb_calc_crc(struct xfs_buf *);
632extern void xfs_mod_sb(struct xfs_trans *, __int64_t);
633extern void xfs_sb_mount_common(struct xfs_mount *, struct xfs_sb *);
634extern void xfs_sb_from_disk(struct xfs_sb *, struct xfs_dsb *);
635extern void xfs_sb_to_disk(struct xfs_dsb *, struct xfs_sb *, __int64_t);
636extern void xfs_sb_quota_from_disk(struct xfs_sb *sbp);
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638#endif /* __XFS_SB_H__ */