xfs: add CRC checks to the superblock
[deliverable/linux.git] / fs / xfs / xfs_sb.h
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
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
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
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.
1da177e4 13 *
7b718769
NS
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
1da177e4
LT
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
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 */
04a1e6c5 35#define XFS_SB_VERSION_5 5 /* CRC enabled filesystem */
1da177e4
LT
36#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
189f4bf2 50#define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
1da177e4
LT
51#define XFS_SB_VERSION_MOREBITSBIT 0x8000
52#define XFS_SB_VERSION_OKSASHFBITS \
53 (XFS_SB_VERSION_EXTFLGBIT | \
189f4bf2
BN
54 XFS_SB_VERSION_DIRV2BIT | \
55 XFS_SB_VERSION_BORGBIT)
1da177e4
LT
56#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 | \
d8cc890d
NS
64 XFS_SB_VERSION_SECTORBIT | \
65 XFS_SB_VERSION_MOREBITSBIT)
1da177e4
LT
66#define XFS_SB_VERSION_OKREALBITS \
67 (XFS_SB_VERSION_NUMBITS | \
68 XFS_SB_VERSION_OKREALFBITS | \
69 XFS_SB_VERSION_OKSASHFBITS)
1da177e4
LT
70
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
92821e2b 80#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
d8cc890d
NS
81#define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
82#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
6d73cf13 83#define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
6743099c 84#define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
bc02e869 85#define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */
1da177e4
LT
86
87#define XFS_SB_VERSION2_OKREALFBITS \
92821e2b 88 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
6743099c
AM
89 XFS_SB_VERSION2_ATTR2BIT | \
90 XFS_SB_VERSION2_PROJID32BIT)
1da177e4
LT
91#define XFS_SB_VERSION2_OKSASHFBITS \
92 (0)
93#define XFS_SB_VERSION2_OKREALBITS \
94 (XFS_SB_VERSION2_OKREALFBITS | \
95 XFS_SB_VERSION2_OKSASHFBITS )
96
2bdf7cd0
CH
97/*
98 * Superblock - in core version. Must match the ondisk version below.
ee1c0908 99 * Must be padded to 64 bit alignment.
2bdf7cd0
CH
100 */
101typedef struct xfs_sb {
1da177e4
LT
102 __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 */
d8cc890d 155 __uint32_t sb_features2; /* additional feature bits */
ee1c0908
DC
156
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
04a1e6c5
DC
165 /* 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;
171
172 __uint32_t sb_crc; /* superblock crc */
173
174 xfs_ino_t sb_pquotino; /* project quota inode */
175 xfs_lsn_t sb_lsn; /* last write sequence */
176
ee1c0908 177 /* must be padded to 64 bit alignment */
1da177e4
LT
178} xfs_sb_t;
179
2bdf7cd0 180/*
ee1c0908
DC
181 * Superblock - on disk version. Must match the in core version above.
182 * Must be padded to 64 bit alignment.
2bdf7cd0
CH
183 */
184typedef struct xfs_dsb {
185 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
186 __be32 sb_blocksize; /* logical block size, bytes */
187 __be64 sb_dblocks; /* number of data blocks */
188 __be64 sb_rblocks; /* number of realtime blocks */
189 __be64 sb_rextents; /* number of realtime extents */
190 uuid_t sb_uuid; /* file system unique id */
191 __be64 sb_logstart; /* starting block of log if internal */
192 __be64 sb_rootino; /* root inode number */
193 __be64 sb_rbmino; /* bitmap inode for realtime extents */
194 __be64 sb_rsumino; /* summary inode for rt bitmap */
195 __be32 sb_rextsize; /* realtime extent size, blocks */
196 __be32 sb_agblocks; /* size of an allocation group */
197 __be32 sb_agcount; /* number of allocation groups */
198 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
199 __be32 sb_logblocks; /* number of log blocks */
200 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
201 __be16 sb_sectsize; /* volume sector size, bytes */
202 __be16 sb_inodesize; /* inode size, bytes */
203 __be16 sb_inopblock; /* inodes per block */
204 char sb_fname[12]; /* file system name */
205 __u8 sb_blocklog; /* log2 of sb_blocksize */
206 __u8 sb_sectlog; /* log2 of sb_sectsize */
207 __u8 sb_inodelog; /* log2 of sb_inodesize */
208 __u8 sb_inopblog; /* log2 of sb_inopblock */
209 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
210 __u8 sb_rextslog; /* log2 of sb_rextents */
211 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
212 __u8 sb_imax_pct; /* max % of fs for inode space */
213 /* statistics */
214 /*
215 * These fields must remain contiguous. If you really
216 * want to change their layout, make sure you fix the
217 * code in xfs_trans_apply_sb_deltas().
218 */
219 __be64 sb_icount; /* allocated inodes */
220 __be64 sb_ifree; /* free inodes */
221 __be64 sb_fdblocks; /* free data blocks */
222 __be64 sb_frextents; /* free realtime extents */
223 /*
224 * End contiguous fields.
225 */
226 __be64 sb_uquotino; /* user quota inode */
227 __be64 sb_gquotino; /* group quota inode */
228 __be16 sb_qflags; /* quota flags */
229 __u8 sb_flags; /* misc. flags */
230 __u8 sb_shared_vn; /* shared version number */
231 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
232 __be32 sb_unit; /* stripe or raid unit */
233 __be32 sb_width; /* stripe or raid width */
234 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
235 __u8 sb_logsectlog; /* log2 of the log sector size */
236 __be16 sb_logsectsize; /* sector size for the log, bytes */
237 __be32 sb_logsunit; /* stripe unit size for the log */
238 __be32 sb_features2; /* additional feature bits */
ee1c0908
DC
239 /*
240 * bad features2 field as a result of failing to pad the sb
241 * structure to 64 bits. Some machines will be using this field
242 * for features2 bits. Easiest just to mark it bad and not use
243 * it for anything else.
244 */
04a1e6c5
DC
245 __be32 sb_bad_features2;
246
247 /* version 5 superblock fields start here */
248
249 /* feature masks */
250 __be32 sb_features_compat;
251 __be32 sb_features_ro_compat;
252 __be32 sb_features_incompat;
253
254 __le32 sb_crc; /* superblock crc */
255
256 __be64 sb_pquotino; /* project quota inode */
257 __be64 sb_lsn; /* last write sequence */
ee1c0908
DC
258
259 /* must be padded to 64 bit alignment */
2bdf7cd0
CH
260} xfs_dsb_t;
261
1da177e4
LT
262/*
263 * Sequence number values for the fields.
264 */
265typedef enum {
266 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
267 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
268 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
269 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
270 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
271 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
272 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
273 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
274 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
275 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
276 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
277 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
04a1e6c5
DC
278 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2, XFS_SBS_FEATURES_COMPAT,
279 XFS_SBS_FEATURES_RO_COMPAT, XFS_SBS_FEATURES_INCOMPAT, XFS_SBS_CRC,
280 XFS_SBS_PQUOTINO, XFS_SBS_LSN,
1da177e4
LT
281 XFS_SBS_FIELDCOUNT
282} xfs_sb_field_t;
283
284/*
285 * Mask values, defined based on the xfs_sb_field_t values.
286 * Only define the ones we're using.
287 */
288#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
289#define XFS_SB_UUID XFS_SB_MVAL(UUID)
290#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
291#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
292#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
293#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
294#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
295#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
296#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
297#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
298#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
299#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
300#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
92821e2b
DC
301#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
302#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
303#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
d8cc890d 304#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
ee1c0908 305#define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
04a1e6c5
DC
306#define XFS_SB_FEATURES_COMPAT XFS_SB_MVAL(FEATURES_COMPAT)
307#define XFS_SB_FEATURES_RO_COMPAT XFS_SB_MVAL(FEATURES_RO_COMPAT)
308#define XFS_SB_FEATURES_INCOMPAT XFS_SB_MVAL(FEATURES_INCOMPAT)
309#define XFS_SB_CRC XFS_SB_MVAL(CRC)
310#define XFS_SB_PQUOTINO XFS_SB_MVAL(PQUOTINO)
1da177e4
LT
311#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
312#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
313#define XFS_SB_MOD_BITS \
314 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
315 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
d8cc890d 316 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
ee1c0908 317 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
04a1e6c5
DC
318 XFS_SB_BAD_FEATURES2 | XFS_SB_FEATURES_COMPAT | \
319 XFS_SB_FEATURES_RO_COMPAT | XFS_SB_FEATURES_INCOMPAT | XFS_SB_PQUOTINO)
d8cc890d 320
1da177e4
LT
321
322/*
323 * Misc. Flags - warning - these will be cleared by xfs_repair unless
324 * a feature bit is set when the flag is used.
325 */
326#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
327#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
328
329/*
330 * define max. shared version we can interoperate with
331 */
332#define XFS_SB_MAX_SHARED_VN 0
333
1da177e4 334#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
1da177e4 335
a844f451
NS
336static inline int xfs_sb_good_version(xfs_sb_t *sbp)
337{
5efcbb85
CH
338 /* We always support version 1-3 */
339 if (sbp->sb_versionnum >= XFS_SB_VERSION_1 &&
340 sbp->sb_versionnum <= XFS_SB_VERSION_3)
341 return 1;
342
343 /* We support version 4 if all feature bits are supported */
344 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) {
345 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKREALBITS) ||
346 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
347 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKREALBITS)))
348 return 0;
349
350#ifdef __KERNEL__
351 if (sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
352 return 0;
a844f451 353#else
5efcbb85
CH
354 if ((sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT) &&
355 sbp->sb_shared_vn > XFS_SB_MAX_SHARED_VN)
356 return 0;
357#endif
358
359 return 1;
360 }
04a1e6c5
DC
361 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
362 return 1;
5efcbb85
CH
363
364 return 0;
a844f451 365}
1da177e4 366
ee1c0908 367/*
e6957ea4
ES
368 * Detect a mismatched features2 field. Older kernels read/wrote
369 * this into the wrong slot, so to be safe we keep them in sync.
ee1c0908 370 */
e6957ea4 371static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp)
ee1c0908 372{
e6957ea4 373 return (sbp->sb_bad_features2 != sbp->sb_features2);
ee1c0908
DC
374}
375
a844f451
NS
376static inline unsigned xfs_sb_version_tonew(unsigned v)
377{
5efcbb85
CH
378 if (v == XFS_SB_VERSION_1)
379 return XFS_SB_VERSION_4;
380
381 if (v == XFS_SB_VERSION_2)
382 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
383
384 return XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT |
385 XFS_SB_VERSION_NLINKBIT;
a844f451 386}
1da177e4 387
a844f451
NS
388static inline unsigned xfs_sb_version_toold(unsigned v)
389{
5efcbb85
CH
390 if (v & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT))
391 return 0;
392 if (v & XFS_SB_VERSION_NLINKBIT)
393 return XFS_SB_VERSION_3;
394 if (v & XFS_SB_VERSION_ATTRBIT)
395 return XFS_SB_VERSION_2;
396 return XFS_SB_VERSION_1;
a844f451 397}
1da177e4 398
a844f451
NS
399static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
400{
5efcbb85
CH
401 return sbp->sb_versionnum == XFS_SB_VERSION_2 ||
402 sbp->sb_versionnum == XFS_SB_VERSION_3 ||
04a1e6c5 403 (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
5efcbb85 404 (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
a844f451 405}
1da177e4 406
a844f451
NS
407static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
408{
5efcbb85
CH
409 if (sbp->sb_versionnum == XFS_SB_VERSION_1)
410 sbp->sb_versionnum = XFS_SB_VERSION_2;
04a1e6c5 411 else if (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4)
5efcbb85
CH
412 sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
413 else
414 sbp->sb_versionnum = XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT;
a844f451 415}
1da177e4 416
a844f451
NS
417static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
418{
5efcbb85 419 return sbp->sb_versionnum == XFS_SB_VERSION_3 ||
04a1e6c5 420 (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
5efcbb85 421 (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
a844f451 422}
1da177e4 423
a844f451
NS
424static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
425{
5efcbb85
CH
426 if (sbp->sb_versionnum <= XFS_SB_VERSION_2)
427 sbp->sb_versionnum = XFS_SB_VERSION_3;
428 else
429 sbp->sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
a844f451 430}
1da177e4 431
a844f451
NS
432static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
433{
04a1e6c5 434 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
5efcbb85 435 (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
a844f451 436}
1da177e4 437
a844f451
NS
438static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
439{
04a1e6c5 440 if (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4)
5efcbb85
CH
441 sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
442 else
443 sbp->sb_versionnum = xfs_sb_version_tonew(sbp->sb_versionnum) |
444 XFS_SB_VERSION_QUOTABIT;
a844f451
NS
445}
446
a844f451
NS
447static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
448{
04a1e6c5
DC
449 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
450 (XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
451 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT));
a844f451 452}
1da177e4 453
a844f451
NS
454static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
455{
04a1e6c5 456 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
5efcbb85 457 (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
a844f451 458}
1da177e4 459
a844f451
NS
460static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
461{
5efcbb85
CH
462 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
463 (sbp->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
a844f451 464}
1da177e4 465
a844f451
NS
466static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
467{
04a1e6c5
DC
468 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
469 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
470 (sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT));
a844f451 471}
1da177e4 472
a844f451
NS
473static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
474{
04a1e6c5
DC
475 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_LOGV2BIT));
a844f451 478}
1da177e4 479
a844f451
NS
480static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
481{
04a1e6c5
DC
482 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_EXTFLGBIT));
a844f451 485}
1da177e4 486
a844f451
NS
487static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
488{
04a1e6c5 489 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
5efcbb85 490 (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
a844f451 491}
1da177e4 492
189f4bf2
BN
493static inline int xfs_sb_version_hasasciici(xfs_sb_t *sbp)
494{
04a1e6c5 495 return XFS_SB_VERSION_NUM(sbp) >= XFS_SB_VERSION_4 &&
189f4bf2
BN
496 (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
497}
498
a844f451
NS
499static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
500{
04a1e6c5
DC
501 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
502 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 &&
503 (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT));
a844f451 504}
1da177e4
LT
505
506/*
507 * sb_features2 bit version macros.
508 *
d8cc890d 509 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
1da177e4 510 *
d8cc890d 511 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
62118709 512 * ((xfs_sb_version_hasmorebits(sbp) &&
d8cc890d 513 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
1da177e4 514 */
a844f451 515
92821e2b
DC
516static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
517{
04a1e6c5
DC
518 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
519 (xfs_sb_version_hasmorebits(sbp) &&
520 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
92821e2b
DC
521}
522
a844f451
NS
523static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
524{
04a1e6c5
DC
525 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
526 (xfs_sb_version_hasmorebits(sbp) &&
527 (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT));
a844f451 528}
1da177e4 529
a844f451
NS
530static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
531{
5efcbb85
CH
532 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
533 sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
a844f451
NS
534}
535
7c12f296
TS
536static inline void xfs_sb_version_removeattr2(xfs_sb_t *sbp)
537{
538 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
539 if (!sbp->sb_features2)
540 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
541}
542
6743099c
AM
543static inline int xfs_sb_version_hasprojid32bit(xfs_sb_t *sbp)
544{
04a1e6c5
DC
545 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
546 (xfs_sb_version_hasmorebits(sbp) &&
547 (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT));
6743099c
AM
548}
549
bc02e869
CH
550static inline int xfs_sb_version_hascrc(xfs_sb_t *sbp)
551{
04a1e6c5 552 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
bc02e869
CH
553}
554
1da177e4
LT
555/*
556 * end of superblock version macros
557 */
558
a844f451 559#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
1da177e4 560#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
62926044 561#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
a844f451
NS
562
563#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
564#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
b6e32227 565 xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
a844f451
NS
566#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
567 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
1da177e4
LT
568
569/*
570 * File system sector to basic block conversions.
571 */
572#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
1da177e4
LT
573
574/*
575 * File system block to basic block conversions.
576 */
577#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
578#define XFS_BB_TO_FSB(mp,bb) \
579 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
580#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
1da177e4
LT
581
582/*
583 * File system block to byte conversions.
584 */
585#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
586#define XFS_B_TO_FSB(mp,b) \
587 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
588#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
589#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
590
591#endif /* __XFS_SB_H__ */
This page took 0.603822 seconds and 5 git commands to generate.