1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
8 #include "xfs_shared.h"
9 #include "xfs_format.h"
10 #include "xfs_log_format.h"
11 #include "xfs_trans_resv.h"
14 #include "xfs_mount.h"
15 #include "xfs_ialloc.h"
16 #include "xfs_alloc.h"
17 #include "xfs_error.h"
18 #include "xfs_trans.h"
19 #include "xfs_buf_item.h"
20 #include "xfs_bmap_btree.h"
21 #include "xfs_alloc_btree.h"
23 #include "xfs_rmap_btree.h"
24 #include "xfs_refcount_btree.h"
25 #include "xfs_da_format.h"
26 #include "xfs_health.h"
30 * Physical superblock buffer manipulations. Shared with libxfs in userspace.
34 * Check that all the V4 feature bits that the V5 filesystem format requires are
38 xfs_sb_validate_v5_features(
41 /* We must not have any unknown V4 feature bits set */
42 if (sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS)
46 * The CRC bit is considered an invalid V4 flag, so we have to add it
47 * manually to the OKBITS mask.
49 if (sbp->sb_features2 & ~(XFS_SB_VERSION2_OKBITS |
50 XFS_SB_VERSION2_CRCBIT))
53 /* Now check all the required V4 feature flags are set. */
55 #define V5_VERS_FLAGS (XFS_SB_VERSION_NLINKBIT | \
56 XFS_SB_VERSION_ALIGNBIT | \
57 XFS_SB_VERSION_LOGV2BIT | \
58 XFS_SB_VERSION_EXTFLGBIT | \
59 XFS_SB_VERSION_DIRV2BIT | \
60 XFS_SB_VERSION_MOREBITSBIT)
62 #define V5_FEAT_FLAGS (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
63 XFS_SB_VERSION2_ATTR2BIT | \
64 XFS_SB_VERSION2_PROJID32BIT | \
65 XFS_SB_VERSION2_CRCBIT)
67 if ((sbp->sb_versionnum & V5_VERS_FLAGS) != V5_VERS_FLAGS)
69 if ((sbp->sb_features2 & V5_FEAT_FLAGS) != V5_FEAT_FLAGS)
75 * We current support XFS v5 formats with known features and v4 superblocks with
76 * at least V2 directories.
83 * All v5 filesystems are supported, but we must check that all the
84 * required v4 feature flags are enabled correctly as the code checks
85 * those flags and not for v5 support.
87 if (xfs_sb_is_v5(sbp))
88 return xfs_sb_validate_v5_features(sbp);
90 /* versions prior to v4 are not supported */
91 if (XFS_SB_VERSION_NUM(sbp) != XFS_SB_VERSION_4)
94 /* We must not have any unknown v4 feature bits set */
95 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
96 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
97 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
100 /* V4 filesystems need v2 directories and unwritten extents */
101 if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
103 if (!(sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT))
106 /* It's a supported v4 filesystem */
111 xfs_sb_version_to_features(
114 uint64_t features = 0;
116 /* optional V4 features */
117 if (sbp->sb_rblocks > 0)
118 features |= XFS_FEAT_REALTIME;
119 if (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT)
120 features |= XFS_FEAT_NLINK;
121 if (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT)
122 features |= XFS_FEAT_ATTR;
123 if (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT)
124 features |= XFS_FEAT_QUOTA;
125 if (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT)
126 features |= XFS_FEAT_ALIGN;
127 if (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT)
128 features |= XFS_FEAT_LOGV2;
129 if (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT)
130 features |= XFS_FEAT_DALIGN;
131 if (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT)
132 features |= XFS_FEAT_EXTFLG;
133 if (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT)
134 features |= XFS_FEAT_SECTOR;
135 if (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT)
136 features |= XFS_FEAT_ASCIICI;
137 if (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) {
138 if (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT)
139 features |= XFS_FEAT_LAZYSBCOUNT;
140 if (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT)
141 features |= XFS_FEAT_ATTR2;
142 if (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT)
143 features |= XFS_FEAT_PROJID32;
144 if (sbp->sb_features2 & XFS_SB_VERSION2_FTYPE)
145 features |= XFS_FEAT_FTYPE;
148 if (!xfs_sb_is_v5(sbp))
151 /* Always on V5 features */
152 features |= XFS_FEAT_ALIGN | XFS_FEAT_LOGV2 | XFS_FEAT_EXTFLG |
153 XFS_FEAT_LAZYSBCOUNT | XFS_FEAT_ATTR2 | XFS_FEAT_PROJID32 |
154 XFS_FEAT_V3INODES | XFS_FEAT_CRC | XFS_FEAT_PQUOTINO;
156 /* Optional V5 features */
157 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_FINOBT)
158 features |= XFS_FEAT_FINOBT;
159 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_RMAPBT)
160 features |= XFS_FEAT_RMAPBT;
161 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_REFLINK)
162 features |= XFS_FEAT_REFLINK;
163 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
164 features |= XFS_FEAT_INOBTCNT;
165 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE)
166 features |= XFS_FEAT_FTYPE;
167 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES)
168 features |= XFS_FEAT_SPINODES;
169 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
170 features |= XFS_FEAT_META_UUID;
171 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_BIGTIME)
172 features |= XFS_FEAT_BIGTIME;
173 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR)
174 features |= XFS_FEAT_NEEDSREPAIR;
175 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NREXT64)
176 features |= XFS_FEAT_NREXT64;
181 /* Check all the superblock fields we care about when reading one in. */
183 xfs_validate_sb_read(
184 struct xfs_mount *mp,
187 if (!xfs_sb_is_v5(sbp))
191 * Version 5 superblock feature mask validation. Reject combinations
192 * the kernel cannot support up front before checking anything else.
194 if (xfs_sb_has_compat_feature(sbp, XFS_SB_FEAT_COMPAT_UNKNOWN)) {
196 "Superblock has unknown compatible features (0x%x) enabled.",
197 (sbp->sb_features_compat & XFS_SB_FEAT_COMPAT_UNKNOWN));
199 "Using a more recent kernel is recommended.");
202 if (xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
204 "Superblock has unknown read-only compatible features (0x%x) enabled.",
205 (sbp->sb_features_ro_compat &
206 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
207 if (!xfs_is_readonly(mp)) {
209 "Attempted to mount read-only compatible filesystem read-write.");
211 "Filesystem can only be safely mounted read only.");
216 if (xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
218 "Superblock has unknown incompatible features (0x%x) enabled.",
219 (sbp->sb_features_incompat &
220 XFS_SB_FEAT_INCOMPAT_UNKNOWN));
222 "Filesystem cannot be safely mounted by this kernel.");
229 /* Check all the superblock fields we care about when writing one out. */
231 xfs_validate_sb_write(
232 struct xfs_mount *mp,
237 * Carry out additional sb summary counter sanity checks when we write
238 * the superblock. We skip this in the read validator because there
239 * could be newer superblocks in the log and if the values are garbage
240 * even after replay we'll recalculate them at the end of log mount.
242 * mkfs has traditionally written zeroed counters to inprogress and
243 * secondary superblocks, so allow this usage to continue because
244 * we never read counters from such superblocks.
246 if (xfs_buf_daddr(bp) == XFS_SB_DADDR && !sbp->sb_inprogress &&
247 (sbp->sb_fdblocks > sbp->sb_dblocks ||
248 !xfs_verify_icount(mp, sbp->sb_icount) ||
249 sbp->sb_ifree > sbp->sb_icount)) {
250 xfs_warn(mp, "SB summary counter sanity check failed");
251 return -EFSCORRUPTED;
254 if (!xfs_sb_is_v5(sbp))
258 * Version 5 superblock feature mask validation. Reject combinations
259 * the kernel cannot support since we checked for unsupported bits in
260 * the read verifier, which means that memory is corrupt.
262 if (xfs_sb_has_compat_feature(sbp, XFS_SB_FEAT_COMPAT_UNKNOWN)) {
264 "Corruption detected in superblock compatible features (0x%x)!",
265 (sbp->sb_features_compat & XFS_SB_FEAT_COMPAT_UNKNOWN));
266 return -EFSCORRUPTED;
269 if (xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
271 "Corruption detected in superblock read-only compatible features (0x%x)!",
272 (sbp->sb_features_ro_compat &
273 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
274 return -EFSCORRUPTED;
276 if (xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
278 "Corruption detected in superblock incompatible features (0x%x)!",
279 (sbp->sb_features_incompat &
280 XFS_SB_FEAT_INCOMPAT_UNKNOWN));
281 return -EFSCORRUPTED;
283 if (xfs_sb_has_incompat_log_feature(sbp,
284 XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN)) {
286 "Corruption detected in superblock incompatible log features (0x%x)!",
287 (sbp->sb_features_log_incompat &
288 XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN));
289 return -EFSCORRUPTED;
293 * We can't read verify the sb LSN because the read verifier is called
294 * before the log is allocated and processed. We know the log is set up
295 * before write verifier calls, so check it here.
297 if (!xfs_log_check_lsn(mp, sbp->sb_lsn))
298 return -EFSCORRUPTED;
303 /* Check the validity of the SB. */
305 xfs_validate_sb_common(
306 struct xfs_mount *mp,
310 struct xfs_dsb *dsb = bp->b_addr;
311 uint32_t agcount = 0;
315 if (!xfs_verify_magic(bp, dsb->sb_magicnum)) {
317 "Superblock has bad magic number 0x%x. Not an XFS filesystem?",
318 be32_to_cpu(dsb->sb_magicnum));
322 if (!xfs_sb_good_version(sbp)) {
324 "Superblock has unknown features enabled or corrupted feature masks.");
329 * Validate feature flags and state
331 if (xfs_sb_is_v5(sbp)) {
332 if (sbp->sb_blocksize < XFS_MIN_CRC_BLOCKSIZE) {
334 "Block size (%u bytes) too small for Version 5 superblock (minimum %d bytes)",
335 sbp->sb_blocksize, XFS_MIN_CRC_BLOCKSIZE);
336 return -EFSCORRUPTED;
339 /* V5 has a separate project quota inode */
340 if (sbp->sb_qflags & (XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD)) {
342 "Version 5 of Super block has XFS_OQUOTA bits.");
343 return -EFSCORRUPTED;
347 * Full inode chunks must be aligned to inode chunk size when
348 * sparse inodes are enabled to support the sparse chunk
349 * allocation algorithm and prevent overlapping inode records.
351 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES) {
354 align = XFS_INODES_PER_CHUNK * sbp->sb_inodesize
356 if (sbp->sb_inoalignmt != align) {
358 "Inode block alignment (%u) must match chunk size (%u) for sparse inodes.",
359 sbp->sb_inoalignmt, align);
363 } else if (sbp->sb_qflags & (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD |
364 XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) {
366 "Superblock earlier than Version 5 has XFS_{P|G}QUOTA_{ENFD|CHKD} bits.");
367 return -EFSCORRUPTED;
371 sbp->sb_logstart == 0 && mp->m_logdev_targp == mp->m_ddev_targp)) {
373 "filesystem is marked as having an external log; "
374 "specify logdev on the mount command line.");
379 sbp->sb_logstart != 0 && mp->m_logdev_targp != mp->m_ddev_targp)) {
381 "filesystem is marked as having an internal log; "
382 "do not specify logdev on the mount command line.");
386 /* Compute agcount for this number of dblocks and agblocks */
387 if (sbp->sb_agblocks) {
388 agcount = div_u64_rem(sbp->sb_dblocks, sbp->sb_agblocks, &rem);
394 * More sanity checking. Most of these were stolen directly from
398 sbp->sb_agcount <= 0 ||
399 sbp->sb_sectsize < XFS_MIN_SECTORSIZE ||
400 sbp->sb_sectsize > XFS_MAX_SECTORSIZE ||
401 sbp->sb_sectlog < XFS_MIN_SECTORSIZE_LOG ||
402 sbp->sb_sectlog > XFS_MAX_SECTORSIZE_LOG ||
403 sbp->sb_sectsize != (1 << sbp->sb_sectlog) ||
404 sbp->sb_blocksize < XFS_MIN_BLOCKSIZE ||
405 sbp->sb_blocksize > XFS_MAX_BLOCKSIZE ||
406 sbp->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
407 sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
408 sbp->sb_blocksize != (1 << sbp->sb_blocklog) ||
409 sbp->sb_dirblklog + sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
410 sbp->sb_inodesize < XFS_DINODE_MIN_SIZE ||
411 sbp->sb_inodesize > XFS_DINODE_MAX_SIZE ||
412 sbp->sb_inodelog < XFS_DINODE_MIN_LOG ||
413 sbp->sb_inodelog > XFS_DINODE_MAX_LOG ||
414 sbp->sb_inodesize != (1 << sbp->sb_inodelog) ||
415 sbp->sb_inopblock != howmany(sbp->sb_blocksize,sbp->sb_inodesize) ||
416 XFS_FSB_TO_B(mp, sbp->sb_agblocks) < XFS_MIN_AG_BYTES ||
417 XFS_FSB_TO_B(mp, sbp->sb_agblocks) > XFS_MAX_AG_BYTES ||
418 sbp->sb_agblklog != xfs_highbit32(sbp->sb_agblocks - 1) + 1 ||
419 agcount == 0 || agcount != sbp->sb_agcount ||
420 (sbp->sb_blocklog - sbp->sb_inodelog != sbp->sb_inopblog) ||
421 (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE) ||
422 (sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) ||
423 (sbp->sb_imax_pct > 100 /* zero sb_imax_pct is valid */) ||
424 sbp->sb_dblocks == 0 ||
425 sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) ||
426 sbp->sb_dblocks < XFS_MIN_DBLOCKS(sbp) ||
427 sbp->sb_shared_vn != 0)) {
428 xfs_notice(mp, "SB sanity check failed");
429 return -EFSCORRUPTED;
433 * Logs that are too large are not supported at all. Reject them
434 * outright. Logs that are too small are tolerated on v4 filesystems,
435 * but we can only check that when mounting the log. Hence we skip
438 if (sbp->sb_logblocks > XFS_MAX_LOG_BLOCKS) {
440 "Log size 0x%x blocks too large, maximum size is 0x%llx blocks",
441 sbp->sb_logblocks, XFS_MAX_LOG_BLOCKS);
442 return -EFSCORRUPTED;
445 if (XFS_FSB_TO_B(mp, sbp->sb_logblocks) > XFS_MAX_LOG_BYTES) {
447 "log size 0x%llx bytes too large, maximum size is 0x%llx bytes",
448 XFS_FSB_TO_B(mp, sbp->sb_logblocks),
450 return -EFSCORRUPTED;
454 * Do not allow filesystems with corrupted log sector or stripe units to
455 * be mounted. We cannot safely size the iclogs or write to the log if
456 * the log stripe unit is not valid.
458 if (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT) {
459 if (sbp->sb_logsectsize != (1U << sbp->sb_logsectlog)) {
461 "log sector size in bytes/log2 (0x%x/0x%x) must match",
462 sbp->sb_logsectsize, 1U << sbp->sb_logsectlog);
463 return -EFSCORRUPTED;
465 } else if (sbp->sb_logsectsize || sbp->sb_logsectlog) {
467 "log sector size in bytes/log2 (0x%x/0x%x) are not zero",
468 sbp->sb_logsectsize, sbp->sb_logsectlog);
469 return -EFSCORRUPTED;
472 if (sbp->sb_logsunit > 1) {
473 if (sbp->sb_logsunit % sbp->sb_blocksize) {
475 "log stripe unit 0x%x bytes must be a multiple of block size",
477 return -EFSCORRUPTED;
479 if (sbp->sb_logsunit > XLOG_MAX_RECORD_BSIZE) {
481 "log stripe unit 0x%x bytes over maximum size (0x%x bytes)",
482 sbp->sb_logsunit, XLOG_MAX_RECORD_BSIZE);
483 return -EFSCORRUPTED;
487 /* Validate the realtime geometry; stolen from xfs_repair */
488 if (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE ||
489 sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) {
491 "realtime extent sanity check failed");
492 return -EFSCORRUPTED;
495 if (sbp->sb_rblocks == 0) {
496 if (sbp->sb_rextents != 0 || sbp->sb_rbmblocks != 0 ||
497 sbp->sb_rextslog != 0 || sbp->sb_frextents != 0) {
499 "realtime zeroed geometry check failed");
500 return -EFSCORRUPTED;
506 rexts = div_u64(sbp->sb_rblocks, sbp->sb_rextsize);
507 rbmblocks = howmany_64(sbp->sb_rextents,
508 NBBY * sbp->sb_blocksize);
510 if (sbp->sb_rextents != rexts ||
511 sbp->sb_rextslog != xfs_highbit32(sbp->sb_rextents) ||
512 sbp->sb_rbmblocks != rbmblocks) {
514 "realtime geometry sanity check failed");
515 return -EFSCORRUPTED;
520 * Either (sb_unit and !hasdalign) or (!sb_unit and hasdalign)
521 * would imply the image is corrupted.
523 has_dalign = sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT;
524 if (!!sbp->sb_unit ^ has_dalign) {
525 xfs_notice(mp, "SB stripe alignment sanity check failed");
526 return -EFSCORRUPTED;
529 if (!xfs_validate_stripe_geometry(mp, XFS_FSB_TO_B(mp, sbp->sb_unit),
530 XFS_FSB_TO_B(mp, sbp->sb_width), 0, false))
531 return -EFSCORRUPTED;
534 * Currently only very few inode sizes are supported.
536 switch (sbp->sb_inodesize) {
543 xfs_warn(mp, "inode size of %d bytes not supported",
552 xfs_sb_quota_from_disk(struct xfs_sb *sbp)
555 * older mkfs doesn't initialize quota inodes to NULLFSINO. This
556 * leads to in-core values having two different values for a quota
557 * inode to be invalid: 0 and NULLFSINO. Change it to a single value
560 * Note that this change affect only the in-core values. These
561 * values are not written back to disk unless any quota information
562 * is written to the disk. Even in that case, sb_pquotino field is
563 * not written to disk unless the superblock supports pquotino.
565 if (sbp->sb_uquotino == 0)
566 sbp->sb_uquotino = NULLFSINO;
567 if (sbp->sb_gquotino == 0)
568 sbp->sb_gquotino = NULLFSINO;
569 if (sbp->sb_pquotino == 0)
570 sbp->sb_pquotino = NULLFSINO;
573 * We need to do these manipilations only if we are working
574 * with an older version of on-disk superblock.
576 if (xfs_sb_is_v5(sbp))
579 if (sbp->sb_qflags & XFS_OQUOTA_ENFD)
580 sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
581 XFS_PQUOTA_ENFD : XFS_GQUOTA_ENFD;
582 if (sbp->sb_qflags & XFS_OQUOTA_CHKD)
583 sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
584 XFS_PQUOTA_CHKD : XFS_GQUOTA_CHKD;
585 sbp->sb_qflags &= ~(XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD);
587 if (sbp->sb_qflags & XFS_PQUOTA_ACCT &&
588 sbp->sb_gquotino != NULLFSINO) {
590 * In older version of superblock, on-disk superblock only
591 * has sb_gquotino, and in-core superblock has both sb_gquotino
592 * and sb_pquotino. But, only one of them is supported at any
593 * point of time. So, if PQUOTA is set in disk superblock,
594 * copy over sb_gquotino to sb_pquotino. The NULLFSINO test
595 * above is to make sure we don't do this twice and wipe them
598 sbp->sb_pquotino = sbp->sb_gquotino;
599 sbp->sb_gquotino = NULLFSINO;
606 struct xfs_dsb *from,
609 to->sb_magicnum = be32_to_cpu(from->sb_magicnum);
610 to->sb_blocksize = be32_to_cpu(from->sb_blocksize);
611 to->sb_dblocks = be64_to_cpu(from->sb_dblocks);
612 to->sb_rblocks = be64_to_cpu(from->sb_rblocks);
613 to->sb_rextents = be64_to_cpu(from->sb_rextents);
614 memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
615 to->sb_logstart = be64_to_cpu(from->sb_logstart);
616 to->sb_rootino = be64_to_cpu(from->sb_rootino);
617 to->sb_rbmino = be64_to_cpu(from->sb_rbmino);
618 to->sb_rsumino = be64_to_cpu(from->sb_rsumino);
619 to->sb_rextsize = be32_to_cpu(from->sb_rextsize);
620 to->sb_agblocks = be32_to_cpu(from->sb_agblocks);
621 to->sb_agcount = be32_to_cpu(from->sb_agcount);
622 to->sb_rbmblocks = be32_to_cpu(from->sb_rbmblocks);
623 to->sb_logblocks = be32_to_cpu(from->sb_logblocks);
624 to->sb_versionnum = be16_to_cpu(from->sb_versionnum);
625 to->sb_sectsize = be16_to_cpu(from->sb_sectsize);
626 to->sb_inodesize = be16_to_cpu(from->sb_inodesize);
627 to->sb_inopblock = be16_to_cpu(from->sb_inopblock);
628 memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
629 to->sb_blocklog = from->sb_blocklog;
630 to->sb_sectlog = from->sb_sectlog;
631 to->sb_inodelog = from->sb_inodelog;
632 to->sb_inopblog = from->sb_inopblog;
633 to->sb_agblklog = from->sb_agblklog;
634 to->sb_rextslog = from->sb_rextslog;
635 to->sb_inprogress = from->sb_inprogress;
636 to->sb_imax_pct = from->sb_imax_pct;
637 to->sb_icount = be64_to_cpu(from->sb_icount);
638 to->sb_ifree = be64_to_cpu(from->sb_ifree);
639 to->sb_fdblocks = be64_to_cpu(from->sb_fdblocks);
640 to->sb_frextents = be64_to_cpu(from->sb_frextents);
641 to->sb_uquotino = be64_to_cpu(from->sb_uquotino);
642 to->sb_gquotino = be64_to_cpu(from->sb_gquotino);
643 to->sb_qflags = be16_to_cpu(from->sb_qflags);
644 to->sb_flags = from->sb_flags;
645 to->sb_shared_vn = from->sb_shared_vn;
646 to->sb_inoalignmt = be32_to_cpu(from->sb_inoalignmt);
647 to->sb_unit = be32_to_cpu(from->sb_unit);
648 to->sb_width = be32_to_cpu(from->sb_width);
649 to->sb_dirblklog = from->sb_dirblklog;
650 to->sb_logsectlog = from->sb_logsectlog;
651 to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize);
652 to->sb_logsunit = be32_to_cpu(from->sb_logsunit);
653 to->sb_features2 = be32_to_cpu(from->sb_features2);
654 to->sb_bad_features2 = be32_to_cpu(from->sb_bad_features2);
655 to->sb_features_compat = be32_to_cpu(from->sb_features_compat);
656 to->sb_features_ro_compat = be32_to_cpu(from->sb_features_ro_compat);
657 to->sb_features_incompat = be32_to_cpu(from->sb_features_incompat);
658 to->sb_features_log_incompat =
659 be32_to_cpu(from->sb_features_log_incompat);
660 /* crc is only used on disk, not in memory; just init to 0 here. */
662 to->sb_spino_align = be32_to_cpu(from->sb_spino_align);
663 to->sb_pquotino = be64_to_cpu(from->sb_pquotino);
664 to->sb_lsn = be64_to_cpu(from->sb_lsn);
666 * sb_meta_uuid is only on disk if it differs from sb_uuid and the
667 * feature flag is set; if not set we keep it only in memory.
669 if (xfs_sb_is_v5(to) &&
670 (to->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID))
671 uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
673 uuid_copy(&to->sb_meta_uuid, &from->sb_uuid);
674 /* Convert on-disk flags to in-memory flags? */
676 xfs_sb_quota_from_disk(to);
682 struct xfs_dsb *from)
684 __xfs_sb_from_disk(to, from, true);
688 xfs_sb_quota_to_disk(
692 uint16_t qflags = from->sb_qflags;
694 to->sb_uquotino = cpu_to_be64(from->sb_uquotino);
697 * The in-memory superblock quota state matches the v5 on-disk format so
698 * just write them out and return
700 if (xfs_sb_is_v5(from)) {
701 to->sb_qflags = cpu_to_be16(from->sb_qflags);
702 to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
703 to->sb_pquotino = cpu_to_be64(from->sb_pquotino);
708 * For older superblocks (v4), the in-core version of sb_qflags do not
709 * have XFS_OQUOTA_* flags, whereas the on-disk version does. So,
710 * convert incore XFS_{PG}QUOTA_* flags to on-disk XFS_OQUOTA_* flags.
712 qflags &= ~(XFS_PQUOTA_ENFD | XFS_PQUOTA_CHKD |
713 XFS_GQUOTA_ENFD | XFS_GQUOTA_CHKD);
715 if (from->sb_qflags &
716 (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD))
717 qflags |= XFS_OQUOTA_ENFD;
718 if (from->sb_qflags &
719 (XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD))
720 qflags |= XFS_OQUOTA_CHKD;
721 to->sb_qflags = cpu_to_be16(qflags);
724 * GQUOTINO and PQUOTINO cannot be used together in versions
725 * of superblock that do not have pquotino. from->sb_flags
726 * tells us which quota is active and should be copied to
727 * disk. If neither are active, we should NULL the inode.
729 * In all cases, the separate pquotino must remain 0 because it
730 * is beyond the "end" of the valid non-pquotino superblock.
732 if (from->sb_qflags & XFS_GQUOTA_ACCT)
733 to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
734 else if (from->sb_qflags & XFS_PQUOTA_ACCT)
735 to->sb_gquotino = cpu_to_be64(from->sb_pquotino);
738 * We can't rely on just the fields being logged to tell us
739 * that it is safe to write NULLFSINO - we should only do that
740 * if quotas are not actually enabled. Hence only write
741 * NULLFSINO if both in-core quota inodes are NULL.
743 if (from->sb_gquotino == NULLFSINO &&
744 from->sb_pquotino == NULLFSINO)
745 to->sb_gquotino = cpu_to_be64(NULLFSINO);
756 xfs_sb_quota_to_disk(to, from);
758 to->sb_magicnum = cpu_to_be32(from->sb_magicnum);
759 to->sb_blocksize = cpu_to_be32(from->sb_blocksize);
760 to->sb_dblocks = cpu_to_be64(from->sb_dblocks);
761 to->sb_rblocks = cpu_to_be64(from->sb_rblocks);
762 to->sb_rextents = cpu_to_be64(from->sb_rextents);
763 memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
764 to->sb_logstart = cpu_to_be64(from->sb_logstart);
765 to->sb_rootino = cpu_to_be64(from->sb_rootino);
766 to->sb_rbmino = cpu_to_be64(from->sb_rbmino);
767 to->sb_rsumino = cpu_to_be64(from->sb_rsumino);
768 to->sb_rextsize = cpu_to_be32(from->sb_rextsize);
769 to->sb_agblocks = cpu_to_be32(from->sb_agblocks);
770 to->sb_agcount = cpu_to_be32(from->sb_agcount);
771 to->sb_rbmblocks = cpu_to_be32(from->sb_rbmblocks);
772 to->sb_logblocks = cpu_to_be32(from->sb_logblocks);
773 to->sb_versionnum = cpu_to_be16(from->sb_versionnum);
774 to->sb_sectsize = cpu_to_be16(from->sb_sectsize);
775 to->sb_inodesize = cpu_to_be16(from->sb_inodesize);
776 to->sb_inopblock = cpu_to_be16(from->sb_inopblock);
777 memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
778 to->sb_blocklog = from->sb_blocklog;
779 to->sb_sectlog = from->sb_sectlog;
780 to->sb_inodelog = from->sb_inodelog;
781 to->sb_inopblog = from->sb_inopblog;
782 to->sb_agblklog = from->sb_agblklog;
783 to->sb_rextslog = from->sb_rextslog;
784 to->sb_inprogress = from->sb_inprogress;
785 to->sb_imax_pct = from->sb_imax_pct;
786 to->sb_icount = cpu_to_be64(from->sb_icount);
787 to->sb_ifree = cpu_to_be64(from->sb_ifree);
788 to->sb_fdblocks = cpu_to_be64(from->sb_fdblocks);
789 to->sb_frextents = cpu_to_be64(from->sb_frextents);
791 to->sb_flags = from->sb_flags;
792 to->sb_shared_vn = from->sb_shared_vn;
793 to->sb_inoalignmt = cpu_to_be32(from->sb_inoalignmt);
794 to->sb_unit = cpu_to_be32(from->sb_unit);
795 to->sb_width = cpu_to_be32(from->sb_width);
796 to->sb_dirblklog = from->sb_dirblklog;
797 to->sb_logsectlog = from->sb_logsectlog;
798 to->sb_logsectsize = cpu_to_be16(from->sb_logsectsize);
799 to->sb_logsunit = cpu_to_be32(from->sb_logsunit);
802 * We need to ensure that bad_features2 always matches features2.
803 * Hence we enforce that here rather than having to remember to do it
804 * everywhere else that updates features2.
806 from->sb_bad_features2 = from->sb_features2;
807 to->sb_features2 = cpu_to_be32(from->sb_features2);
808 to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2);
810 if (!xfs_sb_is_v5(from))
813 to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
814 to->sb_features_ro_compat =
815 cpu_to_be32(from->sb_features_ro_compat);
816 to->sb_features_incompat =
817 cpu_to_be32(from->sb_features_incompat);
818 to->sb_features_log_incompat =
819 cpu_to_be32(from->sb_features_log_incompat);
820 to->sb_spino_align = cpu_to_be32(from->sb_spino_align);
821 to->sb_lsn = cpu_to_be64(from->sb_lsn);
822 if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
823 uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
827 * If the superblock has the CRC feature bit set or the CRC field is non-null,
828 * check that the CRC is valid. We check the CRC field is non-null because a
829 * single bit error could clear the feature bit and unused parts of the
830 * superblock are supposed to be zero. Hence a non-null crc field indicates that
831 * we've potentially lost a feature bit and we should check it anyway.
833 * However, past bugs (i.e. in growfs) left non-zeroed regions beyond the
834 * last field in V4 secondary superblocks. So for secondary superblocks,
835 * we are more forgiving, and ignore CRC failures if the primary doesn't
836 * indicate that the fs version is V5.
843 struct xfs_mount *mp = bp->b_mount;
844 struct xfs_dsb *dsb = bp->b_addr;
848 * open code the version check to avoid needing to convert the entire
849 * superblock from disk order just to check the version number
851 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC) &&
852 (((be16_to_cpu(dsb->sb_versionnum) & XFS_SB_VERSION_NUMBITS) ==
856 if (!xfs_buf_verify_cksum(bp, XFS_SB_CRC_OFF)) {
857 /* Only fail bad secondaries on a known V5 filesystem */
858 if (xfs_buf_daddr(bp) == XFS_SB_DADDR ||
867 * Check all the superblock fields. Don't byteswap the xquota flags
868 * because _verify_common checks the on-disk values.
870 __xfs_sb_from_disk(&sb, dsb, false);
871 error = xfs_validate_sb_common(mp, bp, &sb);
874 error = xfs_validate_sb_read(mp, &sb);
877 if (error == -EFSCORRUPTED || error == -EFSBADCRC)
878 xfs_verifier_error(bp, error, __this_address);
880 xfs_buf_ioerror(bp, error);
884 * We may be probed for a filesystem match, so we may not want to emit
885 * messages when the superblock buffer is not actually an XFS superblock.
886 * If we find an XFS superblock, then run a normal, noisy mount because we are
887 * really going to mount it and want to know about errors.
890 xfs_sb_quiet_read_verify(
893 struct xfs_dsb *dsb = bp->b_addr;
895 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC)) {
896 /* XFS filesystem, verify noisily! */
897 xfs_sb_read_verify(bp);
901 xfs_buf_ioerror(bp, -EWRONGFS);
909 struct xfs_mount *mp = bp->b_mount;
910 struct xfs_buf_log_item *bip = bp->b_log_item;
911 struct xfs_dsb *dsb = bp->b_addr;
915 * Check all the superblock fields. Don't byteswap the xquota flags
916 * because _verify_common checks the on-disk values.
918 __xfs_sb_from_disk(&sb, dsb, false);
919 error = xfs_validate_sb_common(mp, bp, &sb);
922 error = xfs_validate_sb_write(mp, bp, &sb);
926 if (!xfs_sb_is_v5(&sb))
930 dsb->sb_lsn = cpu_to_be64(bip->bli_item.li_lsn);
932 xfs_buf_update_cksum(bp, XFS_SB_CRC_OFF);
936 xfs_verifier_error(bp, error, __this_address);
939 const struct xfs_buf_ops xfs_sb_buf_ops = {
941 .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
942 .verify_read = xfs_sb_read_verify,
943 .verify_write = xfs_sb_write_verify,
946 const struct xfs_buf_ops xfs_sb_quiet_buf_ops = {
947 .name = "xfs_sb_quiet",
948 .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
949 .verify_read = xfs_sb_quiet_read_verify,
950 .verify_write = xfs_sb_write_verify,
956 * Mount initialization code establishing various mount
957 * fields from the superblock associated with the given
960 * Inode geometry are calculated in xfs_ialloc_setup_geometry.
964 struct xfs_mount *mp,
968 atomic_set(&mp->m_agirotor, 0);
969 mp->m_maxagi = mp->m_sb.sb_agcount;
970 mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG;
971 mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT;
972 mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT;
973 mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1;
974 mp->m_blockmask = sbp->sb_blocksize - 1;
975 mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
976 mp->m_blockwmask = mp->m_blockwsize - 1;
978 mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
979 mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
980 mp->m_alloc_mnr[0] = mp->m_alloc_mxr[0] / 2;
981 mp->m_alloc_mnr[1] = mp->m_alloc_mxr[1] / 2;
983 mp->m_bmap_dmxr[0] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 1);
984 mp->m_bmap_dmxr[1] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 0);
985 mp->m_bmap_dmnr[0] = mp->m_bmap_dmxr[0] / 2;
986 mp->m_bmap_dmnr[1] = mp->m_bmap_dmxr[1] / 2;
988 mp->m_rmap_mxr[0] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 1);
989 mp->m_rmap_mxr[1] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 0);
990 mp->m_rmap_mnr[0] = mp->m_rmap_mxr[0] / 2;
991 mp->m_rmap_mnr[1] = mp->m_rmap_mxr[1] / 2;
993 mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, true);
994 mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, false);
995 mp->m_refc_mnr[0] = mp->m_refc_mxr[0] / 2;
996 mp->m_refc_mnr[1] = mp->m_refc_mxr[1] / 2;
998 mp->m_bsize = XFS_FSB_TO_BB(mp, 1);
999 mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
1000 mp->m_ag_max_usable = xfs_alloc_ag_max_usable(mp);
1004 * xfs_log_sb() can be used to copy arbitrary changes to the in-core superblock
1005 * into the superblock buffer to be logged. It does not provide the higher
1006 * level of locking that is needed to protect the in-core superblock from
1007 * concurrent access.
1011 struct xfs_trans *tp)
1013 struct xfs_mount *mp = tp->t_mountp;
1014 struct xfs_buf *bp = xfs_trans_getsb(tp);
1017 * Lazy sb counters don't update the in-core superblock so do that now.
1018 * If this is at unmount, the counters will be exactly correct, but at
1019 * any other time they will only be ballpark correct because of
1020 * reservations that have been taken out percpu counters. If we have an
1021 * unclean shutdown, this will be corrected by log recovery rebuilding
1022 * the counters from the AGF block counts.
1024 * Do not update sb_frextents here because it is not part of the lazy
1025 * sb counters, despite having a percpu counter. It is always kept
1026 * consistent with the ondisk rtbitmap by xfs_trans_apply_sb_deltas()
1027 * and hence we don't need have to update it here.
1029 if (xfs_has_lazysbcount(mp)) {
1030 mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount);
1031 mp->m_sb.sb_ifree = min_t(uint64_t,
1032 percpu_counter_sum(&mp->m_ifree),
1033 mp->m_sb.sb_icount);
1034 mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
1037 xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
1038 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
1039 xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb) - 1);
1045 * Sync the superblock to disk.
1047 * Note that the caller is responsible for checking the frozen state of the
1048 * filesystem. This procedure uses the non-blocking transaction allocator and
1049 * thus will allow modifications to a frozen fs. This is required because this
1050 * code can be called during the process of freezing where use of the high-level
1051 * allocator would deadlock.
1055 struct xfs_mount *mp,
1058 struct xfs_trans *tp;
1061 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0,
1062 XFS_TRANS_NO_WRITECOUNT, &tp);
1068 xfs_trans_set_sync(tp);
1069 return xfs_trans_commit(tp);
1073 * Update all the secondary superblocks to match the new state of the primary.
1074 * Because we are completely overwriting all the existing fields in the
1075 * secondary superblock buffers, there is no need to read them in from disk.
1076 * Just get a new buffer, stamp it and write it.
1078 * The sb buffers need to be cached here so that we serialise against other
1079 * operations that access the secondary superblocks, but we don't want to keep
1080 * them in memory once it is written so we mark it as a one-shot buffer.
1083 xfs_update_secondary_sbs(
1084 struct xfs_mount *mp)
1086 struct xfs_perag *pag;
1087 xfs_agnumber_t agno = 1;
1088 int saved_error = 0;
1090 LIST_HEAD (buffer_list);
1092 /* update secondary superblocks. */
1093 for_each_perag_from(mp, agno, pag) {
1096 error = xfs_buf_get(mp->m_ddev_targp,
1097 XFS_AG_DADDR(mp, pag->pag_agno, XFS_SB_DADDR),
1098 XFS_FSS_TO_BB(mp, 1), &bp);
1100 * If we get an error reading or writing alternate superblocks,
1101 * continue. xfs_repair chooses the "best" superblock based
1102 * on most matches; if we break early, we'll leave more
1103 * superblocks un-updated than updated, and xfs_repair may
1104 * pick them over the properly-updated primary.
1108 "error allocating secondary superblock for ag %d",
1111 saved_error = error;
1115 bp->b_ops = &xfs_sb_buf_ops;
1116 xfs_buf_oneshot(bp);
1117 xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
1118 xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
1119 xfs_buf_delwri_queue(bp, &buffer_list);
1122 /* don't hold too many buffers at once */
1126 error = xfs_buf_delwri_submit(&buffer_list);
1129 "write error %d updating a secondary superblock near ag %d",
1130 error, pag->pag_agno);
1132 saved_error = error;
1136 error = xfs_buf_delwri_submit(&buffer_list);
1139 "write error %d updating a secondary superblock near ag %d",
1143 return saved_error ? saved_error : error;
1147 * Same behavior as xfs_sync_sb, except that it is always synchronous and it
1148 * also writes the superblock buffer to disk sector 0 immediately.
1152 struct xfs_mount *mp)
1154 struct xfs_trans *tp;
1158 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
1162 bp = xfs_trans_getsb(tp);
1164 xfs_trans_bhold(tp, bp);
1165 xfs_trans_set_sync(tp);
1166 error = xfs_trans_commit(tp);
1170 * write out the sb buffer to get the changes to disk
1172 error = xfs_bwrite(bp);
1180 struct xfs_mount *mp,
1181 struct xfs_fsop_geom *geo,
1184 struct xfs_sb *sbp = &mp->m_sb;
1186 memset(geo, 0, sizeof(struct xfs_fsop_geom));
1188 geo->blocksize = sbp->sb_blocksize;
1189 geo->rtextsize = sbp->sb_rextsize;
1190 geo->agblocks = sbp->sb_agblocks;
1191 geo->agcount = sbp->sb_agcount;
1192 geo->logblocks = sbp->sb_logblocks;
1193 geo->sectsize = sbp->sb_sectsize;
1194 geo->inodesize = sbp->sb_inodesize;
1195 geo->imaxpct = sbp->sb_imax_pct;
1196 geo->datablocks = sbp->sb_dblocks;
1197 geo->rtblocks = sbp->sb_rblocks;
1198 geo->rtextents = sbp->sb_rextents;
1199 geo->logstart = sbp->sb_logstart;
1200 BUILD_BUG_ON(sizeof(geo->uuid) != sizeof(sbp->sb_uuid));
1201 memcpy(geo->uuid, &sbp->sb_uuid, sizeof(sbp->sb_uuid));
1203 if (struct_version < 2)
1206 geo->sunit = sbp->sb_unit;
1207 geo->swidth = sbp->sb_width;
1209 if (struct_version < 3)
1212 geo->version = XFS_FSOP_GEOM_VERSION;
1213 geo->flags = XFS_FSOP_GEOM_FLAGS_NLINK |
1214 XFS_FSOP_GEOM_FLAGS_DIRV2 |
1215 XFS_FSOP_GEOM_FLAGS_EXTFLG;
1216 if (xfs_has_attr(mp))
1217 geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR;
1218 if (xfs_has_quota(mp))
1219 geo->flags |= XFS_FSOP_GEOM_FLAGS_QUOTA;
1220 if (xfs_has_align(mp))
1221 geo->flags |= XFS_FSOP_GEOM_FLAGS_IALIGN;
1222 if (xfs_has_dalign(mp))
1223 geo->flags |= XFS_FSOP_GEOM_FLAGS_DALIGN;
1224 if (xfs_has_asciici(mp))
1225 geo->flags |= XFS_FSOP_GEOM_FLAGS_DIRV2CI;
1226 if (xfs_has_lazysbcount(mp))
1227 geo->flags |= XFS_FSOP_GEOM_FLAGS_LAZYSB;
1228 if (xfs_has_attr2(mp))
1229 geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR2;
1230 if (xfs_has_projid32(mp))
1231 geo->flags |= XFS_FSOP_GEOM_FLAGS_PROJID32;
1232 if (xfs_has_crc(mp))
1233 geo->flags |= XFS_FSOP_GEOM_FLAGS_V5SB;
1234 if (xfs_has_ftype(mp))
1235 geo->flags |= XFS_FSOP_GEOM_FLAGS_FTYPE;
1236 if (xfs_has_finobt(mp))
1237 geo->flags |= XFS_FSOP_GEOM_FLAGS_FINOBT;
1238 if (xfs_has_sparseinodes(mp))
1239 geo->flags |= XFS_FSOP_GEOM_FLAGS_SPINODES;
1240 if (xfs_has_rmapbt(mp))
1241 geo->flags |= XFS_FSOP_GEOM_FLAGS_RMAPBT;
1242 if (xfs_has_reflink(mp))
1243 geo->flags |= XFS_FSOP_GEOM_FLAGS_REFLINK;
1244 if (xfs_has_bigtime(mp))
1245 geo->flags |= XFS_FSOP_GEOM_FLAGS_BIGTIME;
1246 if (xfs_has_inobtcounts(mp))
1247 geo->flags |= XFS_FSOP_GEOM_FLAGS_INOBTCNT;
1248 if (xfs_has_sector(mp)) {
1249 geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR;
1250 geo->logsectsize = sbp->sb_logsectsize;
1252 geo->logsectsize = BBSIZE;
1254 if (xfs_has_large_extent_counts(mp))
1255 geo->flags |= XFS_FSOP_GEOM_FLAGS_NREXT64;
1256 geo->rtsectsize = sbp->sb_blocksize;
1257 geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
1259 if (struct_version < 4)
1262 if (xfs_has_logv2(mp))
1263 geo->flags |= XFS_FSOP_GEOM_FLAGS_LOGV2;
1265 geo->logsunit = sbp->sb_logsunit;
1267 if (struct_version < 5)
1270 geo->version = XFS_FSOP_GEOM_VERSION_V5;
1273 /* Read a secondary superblock. */
1275 xfs_sb_read_secondary(
1276 struct xfs_mount *mp,
1277 struct xfs_trans *tp,
1278 xfs_agnumber_t agno,
1279 struct xfs_buf **bpp)
1284 ASSERT(agno != 0 && agno != NULLAGNUMBER);
1285 error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
1286 XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
1287 XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_sb_buf_ops);
1290 xfs_buf_set_ref(bp, XFS_SSB_REF);
1295 /* Get an uninitialised secondary superblock buffer. */
1297 xfs_sb_get_secondary(
1298 struct xfs_mount *mp,
1299 struct xfs_trans *tp,
1300 xfs_agnumber_t agno,
1301 struct xfs_buf **bpp)
1306 ASSERT(agno != 0 && agno != NULLAGNUMBER);
1307 error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
1308 XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
1309 XFS_FSS_TO_BB(mp, 1), 0, &bp);
1312 bp->b_ops = &xfs_sb_buf_ops;
1313 xfs_buf_oneshot(bp);
1319 * sunit, swidth, sectorsize(optional with 0) should be all in bytes,
1320 * so users won't be confused by values in error messages.
1323 xfs_validate_stripe_geometry(
1324 struct xfs_mount *mp,
1330 if (swidth > INT_MAX) {
1333 "stripe width (%lld) is too large", swidth);
1337 if (sunit > swidth) {
1340 "stripe unit (%lld) is larger than the stripe width (%lld)", sunit, swidth);
1344 if (sectorsize && (int)sunit % sectorsize) {
1347 "stripe unit (%lld) must be a multiple of the sector size (%d)",
1352 if (sunit && !swidth) {
1355 "invalid stripe unit (%lld) and stripe width of 0", sunit);
1359 if (!sunit && swidth) {
1362 "invalid stripe width (%lld) and stripe unit of 0", swidth);
1366 if (sunit && (int)swidth % (int)sunit) {
1369 "stripe width (%lld) must be a multiple of the stripe unit (%lld)",