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 support all XFS versions newer than a v4 superblock with V2 directories.
82 * All v5 filesystems are supported, but we must check that all the
83 * required v4 feature flags are enabled correctly as the code checks
84 * those flags and not for v5 support.
86 if (xfs_sb_is_v5(sbp))
87 return xfs_sb_validate_v5_features(sbp);
89 /* We must not have any unknown v4 feature bits set */
90 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
91 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
92 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
95 /* versions prior to v4 are not supported */
96 if (XFS_SB_VERSION_NUM(sbp) < XFS_SB_VERSION_4)
99 /* V4 filesystems need v2 directories and unwritten extents */
100 if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
102 if (!(sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT))
105 /* It's a supported v4 filesystem */
110 xfs_sb_version_to_features(
113 uint64_t features = 0;
115 /* optional V4 features */
116 if (sbp->sb_rblocks > 0)
117 features |= XFS_FEAT_REALTIME;
118 if (sbp->sb_versionnum & XFS_SB_VERSION_NLINKBIT)
119 features |= XFS_FEAT_NLINK;
120 if (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT)
121 features |= XFS_FEAT_ATTR;
122 if (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT)
123 features |= XFS_FEAT_QUOTA;
124 if (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT)
125 features |= XFS_FEAT_ALIGN;
126 if (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT)
127 features |= XFS_FEAT_LOGV2;
128 if (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT)
129 features |= XFS_FEAT_DALIGN;
130 if (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT)
131 features |= XFS_FEAT_EXTFLG;
132 if (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT)
133 features |= XFS_FEAT_SECTOR;
134 if (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT)
135 features |= XFS_FEAT_ASCIICI;
136 if (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) {
137 if (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT)
138 features |= XFS_FEAT_LAZYSBCOUNT;
139 if (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT)
140 features |= XFS_FEAT_ATTR2;
141 if (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT)
142 features |= XFS_FEAT_PROJID32;
143 if (sbp->sb_features2 & XFS_SB_VERSION2_FTYPE)
144 features |= XFS_FEAT_FTYPE;
147 if (!xfs_sb_is_v5(sbp))
150 /* Always on V5 features */
151 features |= XFS_FEAT_ALIGN | XFS_FEAT_LOGV2 | XFS_FEAT_EXTFLG |
152 XFS_FEAT_LAZYSBCOUNT | XFS_FEAT_ATTR2 | XFS_FEAT_PROJID32 |
153 XFS_FEAT_V3INODES | XFS_FEAT_CRC | XFS_FEAT_PQUOTINO;
155 /* Optional V5 features */
156 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_FINOBT)
157 features |= XFS_FEAT_FINOBT;
158 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_RMAPBT)
159 features |= XFS_FEAT_RMAPBT;
160 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_REFLINK)
161 features |= XFS_FEAT_REFLINK;
162 if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
163 features |= XFS_FEAT_INOBTCNT;
164 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE)
165 features |= XFS_FEAT_FTYPE;
166 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES)
167 features |= XFS_FEAT_SPINODES;
168 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
169 features |= XFS_FEAT_META_UUID;
170 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_BIGTIME)
171 features |= XFS_FEAT_BIGTIME;
172 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR)
173 features |= XFS_FEAT_NEEDSREPAIR;
174 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NREXT64)
175 features |= XFS_FEAT_NREXT64;
180 /* Check all the superblock fields we care about when reading one in. */
182 xfs_validate_sb_read(
183 struct xfs_mount *mp,
186 if (!xfs_sb_is_v5(sbp))
190 * Version 5 superblock feature mask validation. Reject combinations
191 * the kernel cannot support up front before checking anything else.
193 if (xfs_sb_has_compat_feature(sbp, XFS_SB_FEAT_COMPAT_UNKNOWN)) {
195 "Superblock has unknown compatible features (0x%x) enabled.",
196 (sbp->sb_features_compat & XFS_SB_FEAT_COMPAT_UNKNOWN));
198 "Using a more recent kernel is recommended.");
201 if (xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
203 "Superblock has unknown read-only compatible features (0x%x) enabled.",
204 (sbp->sb_features_ro_compat &
205 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
206 if (!xfs_is_readonly(mp)) {
208 "Attempted to mount read-only compatible filesystem read-write.");
210 "Filesystem can only be safely mounted read only.");
215 if (xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
217 "Superblock has unknown incompatible features (0x%x) enabled.",
218 (sbp->sb_features_incompat &
219 XFS_SB_FEAT_INCOMPAT_UNKNOWN));
221 "Filesystem cannot be safely mounted by this kernel.");
228 /* Check all the superblock fields we care about when writing one out. */
230 xfs_validate_sb_write(
231 struct xfs_mount *mp,
236 * Carry out additional sb summary counter sanity checks when we write
237 * the superblock. We skip this in the read validator because there
238 * could be newer superblocks in the log and if the values are garbage
239 * even after replay we'll recalculate them at the end of log mount.
241 * mkfs has traditionally written zeroed counters to inprogress and
242 * secondary superblocks, so allow this usage to continue because
243 * we never read counters from such superblocks.
245 if (xfs_buf_daddr(bp) == XFS_SB_DADDR && !sbp->sb_inprogress &&
246 (sbp->sb_fdblocks > sbp->sb_dblocks ||
247 !xfs_verify_icount(mp, sbp->sb_icount) ||
248 sbp->sb_ifree > sbp->sb_icount)) {
249 xfs_warn(mp, "SB summary counter sanity check failed");
250 return -EFSCORRUPTED;
253 if (!xfs_sb_is_v5(sbp))
257 * Version 5 superblock feature mask validation. Reject combinations
258 * the kernel cannot support since we checked for unsupported bits in
259 * the read verifier, which means that memory is corrupt.
261 if (xfs_sb_has_compat_feature(sbp, XFS_SB_FEAT_COMPAT_UNKNOWN)) {
263 "Corruption detected in superblock compatible features (0x%x)!",
264 (sbp->sb_features_compat & XFS_SB_FEAT_COMPAT_UNKNOWN));
265 return -EFSCORRUPTED;
268 if (xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
270 "Corruption detected in superblock read-only compatible features (0x%x)!",
271 (sbp->sb_features_ro_compat &
272 XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
273 return -EFSCORRUPTED;
275 if (xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
277 "Corruption detected in superblock incompatible features (0x%x)!",
278 (sbp->sb_features_incompat &
279 XFS_SB_FEAT_INCOMPAT_UNKNOWN));
280 return -EFSCORRUPTED;
282 if (xfs_sb_has_incompat_log_feature(sbp,
283 XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN)) {
285 "Corruption detected in superblock incompatible log features (0x%x)!",
286 (sbp->sb_features_log_incompat &
287 XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN));
288 return -EFSCORRUPTED;
292 * We can't read verify the sb LSN because the read verifier is called
293 * before the log is allocated and processed. We know the log is set up
294 * before write verifier calls, so check it here.
296 if (!xfs_log_check_lsn(mp, sbp->sb_lsn))
297 return -EFSCORRUPTED;
302 /* Check the validity of the SB. */
304 xfs_validate_sb_common(
305 struct xfs_mount *mp,
309 struct xfs_dsb *dsb = bp->b_addr;
310 uint32_t agcount = 0;
314 if (!xfs_verify_magic(bp, dsb->sb_magicnum)) {
316 "Superblock has bad magic number 0x%x. Not an XFS filesystem?",
317 be32_to_cpu(dsb->sb_magicnum));
321 if (!xfs_sb_good_version(sbp)) {
323 "Superblock has unknown features enabled or corrupted feature masks.");
328 * Validate feature flags and state
330 if (xfs_sb_is_v5(sbp)) {
331 if (sbp->sb_blocksize < XFS_MIN_CRC_BLOCKSIZE) {
333 "Block size (%u bytes) too small for Version 5 superblock (minimum %d bytes)",
334 sbp->sb_blocksize, XFS_MIN_CRC_BLOCKSIZE);
335 return -EFSCORRUPTED;
338 /* V5 has a separate project quota inode */
339 if (sbp->sb_qflags & (XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD)) {
341 "Version 5 of Super block has XFS_OQUOTA bits.");
342 return -EFSCORRUPTED;
346 * Full inode chunks must be aligned to inode chunk size when
347 * sparse inodes are enabled to support the sparse chunk
348 * allocation algorithm and prevent overlapping inode records.
350 if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES) {
353 align = XFS_INODES_PER_CHUNK * sbp->sb_inodesize
355 if (sbp->sb_inoalignmt != align) {
357 "Inode block alignment (%u) must match chunk size (%u) for sparse inodes.",
358 sbp->sb_inoalignmt, align);
362 } else if (sbp->sb_qflags & (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD |
363 XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) {
365 "Superblock earlier than Version 5 has XFS_{P|G}QUOTA_{ENFD|CHKD} bits.");
366 return -EFSCORRUPTED;
370 sbp->sb_logstart == 0 && mp->m_logdev_targp == mp->m_ddev_targp)) {
372 "filesystem is marked as having an external log; "
373 "specify logdev on the mount command line.");
378 sbp->sb_logstart != 0 && mp->m_logdev_targp != mp->m_ddev_targp)) {
380 "filesystem is marked as having an internal log; "
381 "do not specify logdev on the mount command line.");
385 /* Compute agcount for this number of dblocks and agblocks */
386 if (sbp->sb_agblocks) {
387 agcount = div_u64_rem(sbp->sb_dblocks, sbp->sb_agblocks, &rem);
393 * More sanity checking. Most of these were stolen directly from
397 sbp->sb_agcount <= 0 ||
398 sbp->sb_sectsize < XFS_MIN_SECTORSIZE ||
399 sbp->sb_sectsize > XFS_MAX_SECTORSIZE ||
400 sbp->sb_sectlog < XFS_MIN_SECTORSIZE_LOG ||
401 sbp->sb_sectlog > XFS_MAX_SECTORSIZE_LOG ||
402 sbp->sb_sectsize != (1 << sbp->sb_sectlog) ||
403 sbp->sb_blocksize < XFS_MIN_BLOCKSIZE ||
404 sbp->sb_blocksize > XFS_MAX_BLOCKSIZE ||
405 sbp->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG ||
406 sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
407 sbp->sb_blocksize != (1 << sbp->sb_blocklog) ||
408 sbp->sb_dirblklog + sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG ||
409 sbp->sb_inodesize < XFS_DINODE_MIN_SIZE ||
410 sbp->sb_inodesize > XFS_DINODE_MAX_SIZE ||
411 sbp->sb_inodelog < XFS_DINODE_MIN_LOG ||
412 sbp->sb_inodelog > XFS_DINODE_MAX_LOG ||
413 sbp->sb_inodesize != (1 << sbp->sb_inodelog) ||
414 sbp->sb_logsunit > XLOG_MAX_RECORD_BSIZE ||
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;
432 /* Validate the realtime geometry; stolen from xfs_repair */
433 if (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE ||
434 sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE) {
436 "realtime extent sanity check failed");
437 return -EFSCORRUPTED;
440 if (sbp->sb_rblocks == 0) {
441 if (sbp->sb_rextents != 0 || sbp->sb_rbmblocks != 0 ||
442 sbp->sb_rextslog != 0 || sbp->sb_frextents != 0) {
444 "realtime zeroed geometry check failed");
445 return -EFSCORRUPTED;
451 rexts = div_u64(sbp->sb_rblocks, sbp->sb_rextsize);
452 rbmblocks = howmany_64(sbp->sb_rextents,
453 NBBY * sbp->sb_blocksize);
455 if (sbp->sb_rextents != rexts ||
456 sbp->sb_rextslog != xfs_highbit32(sbp->sb_rextents) ||
457 sbp->sb_rbmblocks != rbmblocks) {
459 "realtime geometry sanity check failed");
460 return -EFSCORRUPTED;
465 * Either (sb_unit and !hasdalign) or (!sb_unit and hasdalign)
466 * would imply the image is corrupted.
468 has_dalign = sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT;
469 if (!!sbp->sb_unit ^ has_dalign) {
470 xfs_notice(mp, "SB stripe alignment sanity check failed");
471 return -EFSCORRUPTED;
474 if (!xfs_validate_stripe_geometry(mp, XFS_FSB_TO_B(mp, sbp->sb_unit),
475 XFS_FSB_TO_B(mp, sbp->sb_width), 0, false))
476 return -EFSCORRUPTED;
479 * Currently only very few inode sizes are supported.
481 switch (sbp->sb_inodesize) {
488 xfs_warn(mp, "inode size of %d bytes not supported",
497 xfs_sb_quota_from_disk(struct xfs_sb *sbp)
500 * older mkfs doesn't initialize quota inodes to NULLFSINO. This
501 * leads to in-core values having two different values for a quota
502 * inode to be invalid: 0 and NULLFSINO. Change it to a single value
505 * Note that this change affect only the in-core values. These
506 * values are not written back to disk unless any quota information
507 * is written to the disk. Even in that case, sb_pquotino field is
508 * not written to disk unless the superblock supports pquotino.
510 if (sbp->sb_uquotino == 0)
511 sbp->sb_uquotino = NULLFSINO;
512 if (sbp->sb_gquotino == 0)
513 sbp->sb_gquotino = NULLFSINO;
514 if (sbp->sb_pquotino == 0)
515 sbp->sb_pquotino = NULLFSINO;
518 * We need to do these manipilations only if we are working
519 * with an older version of on-disk superblock.
521 if (xfs_sb_is_v5(sbp))
524 if (sbp->sb_qflags & XFS_OQUOTA_ENFD)
525 sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
526 XFS_PQUOTA_ENFD : XFS_GQUOTA_ENFD;
527 if (sbp->sb_qflags & XFS_OQUOTA_CHKD)
528 sbp->sb_qflags |= (sbp->sb_qflags & XFS_PQUOTA_ACCT) ?
529 XFS_PQUOTA_CHKD : XFS_GQUOTA_CHKD;
530 sbp->sb_qflags &= ~(XFS_OQUOTA_ENFD | XFS_OQUOTA_CHKD);
532 if (sbp->sb_qflags & XFS_PQUOTA_ACCT &&
533 sbp->sb_gquotino != NULLFSINO) {
535 * In older version of superblock, on-disk superblock only
536 * has sb_gquotino, and in-core superblock has both sb_gquotino
537 * and sb_pquotino. But, only one of them is supported at any
538 * point of time. So, if PQUOTA is set in disk superblock,
539 * copy over sb_gquotino to sb_pquotino. The NULLFSINO test
540 * above is to make sure we don't do this twice and wipe them
543 sbp->sb_pquotino = sbp->sb_gquotino;
544 sbp->sb_gquotino = NULLFSINO;
551 struct xfs_dsb *from,
554 to->sb_magicnum = be32_to_cpu(from->sb_magicnum);
555 to->sb_blocksize = be32_to_cpu(from->sb_blocksize);
556 to->sb_dblocks = be64_to_cpu(from->sb_dblocks);
557 to->sb_rblocks = be64_to_cpu(from->sb_rblocks);
558 to->sb_rextents = be64_to_cpu(from->sb_rextents);
559 memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
560 to->sb_logstart = be64_to_cpu(from->sb_logstart);
561 to->sb_rootino = be64_to_cpu(from->sb_rootino);
562 to->sb_rbmino = be64_to_cpu(from->sb_rbmino);
563 to->sb_rsumino = be64_to_cpu(from->sb_rsumino);
564 to->sb_rextsize = be32_to_cpu(from->sb_rextsize);
565 to->sb_agblocks = be32_to_cpu(from->sb_agblocks);
566 to->sb_agcount = be32_to_cpu(from->sb_agcount);
567 to->sb_rbmblocks = be32_to_cpu(from->sb_rbmblocks);
568 to->sb_logblocks = be32_to_cpu(from->sb_logblocks);
569 to->sb_versionnum = be16_to_cpu(from->sb_versionnum);
570 to->sb_sectsize = be16_to_cpu(from->sb_sectsize);
571 to->sb_inodesize = be16_to_cpu(from->sb_inodesize);
572 to->sb_inopblock = be16_to_cpu(from->sb_inopblock);
573 memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
574 to->sb_blocklog = from->sb_blocklog;
575 to->sb_sectlog = from->sb_sectlog;
576 to->sb_inodelog = from->sb_inodelog;
577 to->sb_inopblog = from->sb_inopblog;
578 to->sb_agblklog = from->sb_agblklog;
579 to->sb_rextslog = from->sb_rextslog;
580 to->sb_inprogress = from->sb_inprogress;
581 to->sb_imax_pct = from->sb_imax_pct;
582 to->sb_icount = be64_to_cpu(from->sb_icount);
583 to->sb_ifree = be64_to_cpu(from->sb_ifree);
584 to->sb_fdblocks = be64_to_cpu(from->sb_fdblocks);
585 to->sb_frextents = be64_to_cpu(from->sb_frextents);
586 to->sb_uquotino = be64_to_cpu(from->sb_uquotino);
587 to->sb_gquotino = be64_to_cpu(from->sb_gquotino);
588 to->sb_qflags = be16_to_cpu(from->sb_qflags);
589 to->sb_flags = from->sb_flags;
590 to->sb_shared_vn = from->sb_shared_vn;
591 to->sb_inoalignmt = be32_to_cpu(from->sb_inoalignmt);
592 to->sb_unit = be32_to_cpu(from->sb_unit);
593 to->sb_width = be32_to_cpu(from->sb_width);
594 to->sb_dirblklog = from->sb_dirblklog;
595 to->sb_logsectlog = from->sb_logsectlog;
596 to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize);
597 to->sb_logsunit = be32_to_cpu(from->sb_logsunit);
598 to->sb_features2 = be32_to_cpu(from->sb_features2);
599 to->sb_bad_features2 = be32_to_cpu(from->sb_bad_features2);
600 to->sb_features_compat = be32_to_cpu(from->sb_features_compat);
601 to->sb_features_ro_compat = be32_to_cpu(from->sb_features_ro_compat);
602 to->sb_features_incompat = be32_to_cpu(from->sb_features_incompat);
603 to->sb_features_log_incompat =
604 be32_to_cpu(from->sb_features_log_incompat);
605 /* crc is only used on disk, not in memory; just init to 0 here. */
607 to->sb_spino_align = be32_to_cpu(from->sb_spino_align);
608 to->sb_pquotino = be64_to_cpu(from->sb_pquotino);
609 to->sb_lsn = be64_to_cpu(from->sb_lsn);
611 * sb_meta_uuid is only on disk if it differs from sb_uuid and the
612 * feature flag is set; if not set we keep it only in memory.
614 if (xfs_sb_is_v5(to) &&
615 (to->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID))
616 uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
618 uuid_copy(&to->sb_meta_uuid, &from->sb_uuid);
619 /* Convert on-disk flags to in-memory flags? */
621 xfs_sb_quota_from_disk(to);
627 struct xfs_dsb *from)
629 __xfs_sb_from_disk(to, from, true);
633 xfs_sb_quota_to_disk(
637 uint16_t qflags = from->sb_qflags;
639 to->sb_uquotino = cpu_to_be64(from->sb_uquotino);
642 * The in-memory superblock quota state matches the v5 on-disk format so
643 * just write them out and return
645 if (xfs_sb_is_v5(from)) {
646 to->sb_qflags = cpu_to_be16(from->sb_qflags);
647 to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
648 to->sb_pquotino = cpu_to_be64(from->sb_pquotino);
653 * For older superblocks (v4), the in-core version of sb_qflags do not
654 * have XFS_OQUOTA_* flags, whereas the on-disk version does. So,
655 * convert incore XFS_{PG}QUOTA_* flags to on-disk XFS_OQUOTA_* flags.
657 qflags &= ~(XFS_PQUOTA_ENFD | XFS_PQUOTA_CHKD |
658 XFS_GQUOTA_ENFD | XFS_GQUOTA_CHKD);
660 if (from->sb_qflags &
661 (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD))
662 qflags |= XFS_OQUOTA_ENFD;
663 if (from->sb_qflags &
664 (XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD))
665 qflags |= XFS_OQUOTA_CHKD;
666 to->sb_qflags = cpu_to_be16(qflags);
669 * GQUOTINO and PQUOTINO cannot be used together in versions
670 * of superblock that do not have pquotino. from->sb_flags
671 * tells us which quota is active and should be copied to
672 * disk. If neither are active, we should NULL the inode.
674 * In all cases, the separate pquotino must remain 0 because it
675 * is beyond the "end" of the valid non-pquotino superblock.
677 if (from->sb_qflags & XFS_GQUOTA_ACCT)
678 to->sb_gquotino = cpu_to_be64(from->sb_gquotino);
679 else if (from->sb_qflags & XFS_PQUOTA_ACCT)
680 to->sb_gquotino = cpu_to_be64(from->sb_pquotino);
683 * We can't rely on just the fields being logged to tell us
684 * that it is safe to write NULLFSINO - we should only do that
685 * if quotas are not actually enabled. Hence only write
686 * NULLFSINO if both in-core quota inodes are NULL.
688 if (from->sb_gquotino == NULLFSINO &&
689 from->sb_pquotino == NULLFSINO)
690 to->sb_gquotino = cpu_to_be64(NULLFSINO);
701 xfs_sb_quota_to_disk(to, from);
703 to->sb_magicnum = cpu_to_be32(from->sb_magicnum);
704 to->sb_blocksize = cpu_to_be32(from->sb_blocksize);
705 to->sb_dblocks = cpu_to_be64(from->sb_dblocks);
706 to->sb_rblocks = cpu_to_be64(from->sb_rblocks);
707 to->sb_rextents = cpu_to_be64(from->sb_rextents);
708 memcpy(&to->sb_uuid, &from->sb_uuid, sizeof(to->sb_uuid));
709 to->sb_logstart = cpu_to_be64(from->sb_logstart);
710 to->sb_rootino = cpu_to_be64(from->sb_rootino);
711 to->sb_rbmino = cpu_to_be64(from->sb_rbmino);
712 to->sb_rsumino = cpu_to_be64(from->sb_rsumino);
713 to->sb_rextsize = cpu_to_be32(from->sb_rextsize);
714 to->sb_agblocks = cpu_to_be32(from->sb_agblocks);
715 to->sb_agcount = cpu_to_be32(from->sb_agcount);
716 to->sb_rbmblocks = cpu_to_be32(from->sb_rbmblocks);
717 to->sb_logblocks = cpu_to_be32(from->sb_logblocks);
718 to->sb_versionnum = cpu_to_be16(from->sb_versionnum);
719 to->sb_sectsize = cpu_to_be16(from->sb_sectsize);
720 to->sb_inodesize = cpu_to_be16(from->sb_inodesize);
721 to->sb_inopblock = cpu_to_be16(from->sb_inopblock);
722 memcpy(&to->sb_fname, &from->sb_fname, sizeof(to->sb_fname));
723 to->sb_blocklog = from->sb_blocklog;
724 to->sb_sectlog = from->sb_sectlog;
725 to->sb_inodelog = from->sb_inodelog;
726 to->sb_inopblog = from->sb_inopblog;
727 to->sb_agblklog = from->sb_agblklog;
728 to->sb_rextslog = from->sb_rextslog;
729 to->sb_inprogress = from->sb_inprogress;
730 to->sb_imax_pct = from->sb_imax_pct;
731 to->sb_icount = cpu_to_be64(from->sb_icount);
732 to->sb_ifree = cpu_to_be64(from->sb_ifree);
733 to->sb_fdblocks = cpu_to_be64(from->sb_fdblocks);
734 to->sb_frextents = cpu_to_be64(from->sb_frextents);
736 to->sb_flags = from->sb_flags;
737 to->sb_shared_vn = from->sb_shared_vn;
738 to->sb_inoalignmt = cpu_to_be32(from->sb_inoalignmt);
739 to->sb_unit = cpu_to_be32(from->sb_unit);
740 to->sb_width = cpu_to_be32(from->sb_width);
741 to->sb_dirblklog = from->sb_dirblklog;
742 to->sb_logsectlog = from->sb_logsectlog;
743 to->sb_logsectsize = cpu_to_be16(from->sb_logsectsize);
744 to->sb_logsunit = cpu_to_be32(from->sb_logsunit);
747 * We need to ensure that bad_features2 always matches features2.
748 * Hence we enforce that here rather than having to remember to do it
749 * everywhere else that updates features2.
751 from->sb_bad_features2 = from->sb_features2;
752 to->sb_features2 = cpu_to_be32(from->sb_features2);
753 to->sb_bad_features2 = cpu_to_be32(from->sb_bad_features2);
755 if (!xfs_sb_is_v5(from))
758 to->sb_features_compat = cpu_to_be32(from->sb_features_compat);
759 to->sb_features_ro_compat =
760 cpu_to_be32(from->sb_features_ro_compat);
761 to->sb_features_incompat =
762 cpu_to_be32(from->sb_features_incompat);
763 to->sb_features_log_incompat =
764 cpu_to_be32(from->sb_features_log_incompat);
765 to->sb_spino_align = cpu_to_be32(from->sb_spino_align);
766 to->sb_lsn = cpu_to_be64(from->sb_lsn);
767 if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID)
768 uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid);
772 * If the superblock has the CRC feature bit set or the CRC field is non-null,
773 * check that the CRC is valid. We check the CRC field is non-null because a
774 * single bit error could clear the feature bit and unused parts of the
775 * superblock are supposed to be zero. Hence a non-null crc field indicates that
776 * we've potentially lost a feature bit and we should check it anyway.
778 * However, past bugs (i.e. in growfs) left non-zeroed regions beyond the
779 * last field in V4 secondary superblocks. So for secondary superblocks,
780 * we are more forgiving, and ignore CRC failures if the primary doesn't
781 * indicate that the fs version is V5.
788 struct xfs_mount *mp = bp->b_mount;
789 struct xfs_dsb *dsb = bp->b_addr;
793 * open code the version check to avoid needing to convert the entire
794 * superblock from disk order just to check the version number
796 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC) &&
797 (((be16_to_cpu(dsb->sb_versionnum) & XFS_SB_VERSION_NUMBITS) ==
801 if (!xfs_buf_verify_cksum(bp, XFS_SB_CRC_OFF)) {
802 /* Only fail bad secondaries on a known V5 filesystem */
803 if (xfs_buf_daddr(bp) == XFS_SB_DADDR ||
812 * Check all the superblock fields. Don't byteswap the xquota flags
813 * because _verify_common checks the on-disk values.
815 __xfs_sb_from_disk(&sb, dsb, false);
816 error = xfs_validate_sb_common(mp, bp, &sb);
819 error = xfs_validate_sb_read(mp, &sb);
822 if (error == -EFSCORRUPTED || error == -EFSBADCRC)
823 xfs_verifier_error(bp, error, __this_address);
825 xfs_buf_ioerror(bp, error);
829 * We may be probed for a filesystem match, so we may not want to emit
830 * messages when the superblock buffer is not actually an XFS superblock.
831 * If we find an XFS superblock, then run a normal, noisy mount because we are
832 * really going to mount it and want to know about errors.
835 xfs_sb_quiet_read_verify(
838 struct xfs_dsb *dsb = bp->b_addr;
840 if (dsb->sb_magicnum == cpu_to_be32(XFS_SB_MAGIC)) {
841 /* XFS filesystem, verify noisily! */
842 xfs_sb_read_verify(bp);
846 xfs_buf_ioerror(bp, -EWRONGFS);
854 struct xfs_mount *mp = bp->b_mount;
855 struct xfs_buf_log_item *bip = bp->b_log_item;
856 struct xfs_dsb *dsb = bp->b_addr;
860 * Check all the superblock fields. Don't byteswap the xquota flags
861 * because _verify_common checks the on-disk values.
863 __xfs_sb_from_disk(&sb, dsb, false);
864 error = xfs_validate_sb_common(mp, bp, &sb);
867 error = xfs_validate_sb_write(mp, bp, &sb);
871 if (!xfs_sb_is_v5(&sb))
875 dsb->sb_lsn = cpu_to_be64(bip->bli_item.li_lsn);
877 xfs_buf_update_cksum(bp, XFS_SB_CRC_OFF);
881 xfs_verifier_error(bp, error, __this_address);
884 const struct xfs_buf_ops xfs_sb_buf_ops = {
886 .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
887 .verify_read = xfs_sb_read_verify,
888 .verify_write = xfs_sb_write_verify,
891 const struct xfs_buf_ops xfs_sb_quiet_buf_ops = {
892 .name = "xfs_sb_quiet",
893 .magic = { cpu_to_be32(XFS_SB_MAGIC), cpu_to_be32(XFS_SB_MAGIC) },
894 .verify_read = xfs_sb_quiet_read_verify,
895 .verify_write = xfs_sb_write_verify,
901 * Mount initialization code establishing various mount
902 * fields from the superblock associated with the given
905 * Inode geometry are calculated in xfs_ialloc_setup_geometry.
909 struct xfs_mount *mp,
912 mp->m_agfrotor = mp->m_agirotor = 0;
913 mp->m_maxagi = mp->m_sb.sb_agcount;
914 mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG;
915 mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT;
916 mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT;
917 mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1;
918 mp->m_blockmask = sbp->sb_blocksize - 1;
919 mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
920 mp->m_blockwmask = mp->m_blockwsize - 1;
922 mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1);
923 mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0);
924 mp->m_alloc_mnr[0] = mp->m_alloc_mxr[0] / 2;
925 mp->m_alloc_mnr[1] = mp->m_alloc_mxr[1] / 2;
927 mp->m_bmap_dmxr[0] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 1);
928 mp->m_bmap_dmxr[1] = xfs_bmbt_maxrecs(mp, sbp->sb_blocksize, 0);
929 mp->m_bmap_dmnr[0] = mp->m_bmap_dmxr[0] / 2;
930 mp->m_bmap_dmnr[1] = mp->m_bmap_dmxr[1] / 2;
932 mp->m_rmap_mxr[0] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 1);
933 mp->m_rmap_mxr[1] = xfs_rmapbt_maxrecs(sbp->sb_blocksize, 0);
934 mp->m_rmap_mnr[0] = mp->m_rmap_mxr[0] / 2;
935 mp->m_rmap_mnr[1] = mp->m_rmap_mxr[1] / 2;
937 mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, true);
938 mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, false);
939 mp->m_refc_mnr[0] = mp->m_refc_mxr[0] / 2;
940 mp->m_refc_mnr[1] = mp->m_refc_mxr[1] / 2;
942 mp->m_bsize = XFS_FSB_TO_BB(mp, 1);
943 mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
944 mp->m_ag_max_usable = xfs_alloc_ag_max_usable(mp);
948 * xfs_log_sb() can be used to copy arbitrary changes to the in-core superblock
949 * into the superblock buffer to be logged. It does not provide the higher
950 * level of locking that is needed to protect the in-core superblock from
955 struct xfs_trans *tp)
957 struct xfs_mount *mp = tp->t_mountp;
958 struct xfs_buf *bp = xfs_trans_getsb(tp);
961 * Lazy sb counters don't update the in-core superblock so do that now.
962 * If this is at unmount, the counters will be exactly correct, but at
963 * any other time they will only be ballpark correct because of
964 * reservations that have been taken out percpu counters. If we have an
965 * unclean shutdown, this will be corrected by log recovery rebuilding
966 * the counters from the AGF block counts.
968 * Do not update sb_frextents here because it is not part of the lazy
969 * sb counters, despite having a percpu counter. It is always kept
970 * consistent with the ondisk rtbitmap by xfs_trans_apply_sb_deltas()
971 * and hence we don't need have to update it here.
973 if (xfs_has_lazysbcount(mp)) {
974 mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount);
975 mp->m_sb.sb_ifree = percpu_counter_sum(&mp->m_ifree);
976 mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks);
979 xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
980 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
981 xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb) - 1);
987 * Sync the superblock to disk.
989 * Note that the caller is responsible for checking the frozen state of the
990 * filesystem. This procedure uses the non-blocking transaction allocator and
991 * thus will allow modifications to a frozen fs. This is required because this
992 * code can be called during the process of freezing where use of the high-level
993 * allocator would deadlock.
997 struct xfs_mount *mp,
1000 struct xfs_trans *tp;
1003 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0,
1004 XFS_TRANS_NO_WRITECOUNT, &tp);
1010 xfs_trans_set_sync(tp);
1011 return xfs_trans_commit(tp);
1015 * Update all the secondary superblocks to match the new state of the primary.
1016 * Because we are completely overwriting all the existing fields in the
1017 * secondary superblock buffers, there is no need to read them in from disk.
1018 * Just get a new buffer, stamp it and write it.
1020 * The sb buffers need to be cached here so that we serialise against other
1021 * operations that access the secondary superblocks, but we don't want to keep
1022 * them in memory once it is written so we mark it as a one-shot buffer.
1025 xfs_update_secondary_sbs(
1026 struct xfs_mount *mp)
1028 struct xfs_perag *pag;
1029 xfs_agnumber_t agno = 1;
1030 int saved_error = 0;
1032 LIST_HEAD (buffer_list);
1034 /* update secondary superblocks. */
1035 for_each_perag_from(mp, agno, pag) {
1038 error = xfs_buf_get(mp->m_ddev_targp,
1039 XFS_AG_DADDR(mp, pag->pag_agno, XFS_SB_DADDR),
1040 XFS_FSS_TO_BB(mp, 1), &bp);
1042 * If we get an error reading or writing alternate superblocks,
1043 * continue. xfs_repair chooses the "best" superblock based
1044 * on most matches; if we break early, we'll leave more
1045 * superblocks un-updated than updated, and xfs_repair may
1046 * pick them over the properly-updated primary.
1050 "error allocating secondary superblock for ag %d",
1053 saved_error = error;
1057 bp->b_ops = &xfs_sb_buf_ops;
1058 xfs_buf_oneshot(bp);
1059 xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
1060 xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
1061 xfs_buf_delwri_queue(bp, &buffer_list);
1064 /* don't hold too many buffers at once */
1068 error = xfs_buf_delwri_submit(&buffer_list);
1071 "write error %d updating a secondary superblock near ag %d",
1072 error, pag->pag_agno);
1074 saved_error = error;
1078 error = xfs_buf_delwri_submit(&buffer_list);
1081 "write error %d updating a secondary superblock near ag %d",
1085 return saved_error ? saved_error : error;
1089 * Same behavior as xfs_sync_sb, except that it is always synchronous and it
1090 * also writes the superblock buffer to disk sector 0 immediately.
1094 struct xfs_mount *mp)
1096 struct xfs_trans *tp;
1100 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
1104 bp = xfs_trans_getsb(tp);
1106 xfs_trans_bhold(tp, bp);
1107 xfs_trans_set_sync(tp);
1108 error = xfs_trans_commit(tp);
1112 * write out the sb buffer to get the changes to disk
1114 error = xfs_bwrite(bp);
1122 struct xfs_mount *mp,
1123 struct xfs_fsop_geom *geo,
1126 struct xfs_sb *sbp = &mp->m_sb;
1128 memset(geo, 0, sizeof(struct xfs_fsop_geom));
1130 geo->blocksize = sbp->sb_blocksize;
1131 geo->rtextsize = sbp->sb_rextsize;
1132 geo->agblocks = sbp->sb_agblocks;
1133 geo->agcount = sbp->sb_agcount;
1134 geo->logblocks = sbp->sb_logblocks;
1135 geo->sectsize = sbp->sb_sectsize;
1136 geo->inodesize = sbp->sb_inodesize;
1137 geo->imaxpct = sbp->sb_imax_pct;
1138 geo->datablocks = sbp->sb_dblocks;
1139 geo->rtblocks = sbp->sb_rblocks;
1140 geo->rtextents = sbp->sb_rextents;
1141 geo->logstart = sbp->sb_logstart;
1142 BUILD_BUG_ON(sizeof(geo->uuid) != sizeof(sbp->sb_uuid));
1143 memcpy(geo->uuid, &sbp->sb_uuid, sizeof(sbp->sb_uuid));
1145 if (struct_version < 2)
1148 geo->sunit = sbp->sb_unit;
1149 geo->swidth = sbp->sb_width;
1151 if (struct_version < 3)
1154 geo->version = XFS_FSOP_GEOM_VERSION;
1155 geo->flags = XFS_FSOP_GEOM_FLAGS_NLINK |
1156 XFS_FSOP_GEOM_FLAGS_DIRV2 |
1157 XFS_FSOP_GEOM_FLAGS_EXTFLG;
1158 if (xfs_has_attr(mp))
1159 geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR;
1160 if (xfs_has_quota(mp))
1161 geo->flags |= XFS_FSOP_GEOM_FLAGS_QUOTA;
1162 if (xfs_has_align(mp))
1163 geo->flags |= XFS_FSOP_GEOM_FLAGS_IALIGN;
1164 if (xfs_has_dalign(mp))
1165 geo->flags |= XFS_FSOP_GEOM_FLAGS_DALIGN;
1166 if (xfs_has_asciici(mp))
1167 geo->flags |= XFS_FSOP_GEOM_FLAGS_DIRV2CI;
1168 if (xfs_has_lazysbcount(mp))
1169 geo->flags |= XFS_FSOP_GEOM_FLAGS_LAZYSB;
1170 if (xfs_has_attr2(mp))
1171 geo->flags |= XFS_FSOP_GEOM_FLAGS_ATTR2;
1172 if (xfs_has_projid32(mp))
1173 geo->flags |= XFS_FSOP_GEOM_FLAGS_PROJID32;
1174 if (xfs_has_crc(mp))
1175 geo->flags |= XFS_FSOP_GEOM_FLAGS_V5SB;
1176 if (xfs_has_ftype(mp))
1177 geo->flags |= XFS_FSOP_GEOM_FLAGS_FTYPE;
1178 if (xfs_has_finobt(mp))
1179 geo->flags |= XFS_FSOP_GEOM_FLAGS_FINOBT;
1180 if (xfs_has_sparseinodes(mp))
1181 geo->flags |= XFS_FSOP_GEOM_FLAGS_SPINODES;
1182 if (xfs_has_rmapbt(mp))
1183 geo->flags |= XFS_FSOP_GEOM_FLAGS_RMAPBT;
1184 if (xfs_has_reflink(mp))
1185 geo->flags |= XFS_FSOP_GEOM_FLAGS_REFLINK;
1186 if (xfs_has_bigtime(mp))
1187 geo->flags |= XFS_FSOP_GEOM_FLAGS_BIGTIME;
1188 if (xfs_has_inobtcounts(mp))
1189 geo->flags |= XFS_FSOP_GEOM_FLAGS_INOBTCNT;
1190 if (xfs_has_sector(mp)) {
1191 geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR;
1192 geo->logsectsize = sbp->sb_logsectsize;
1194 geo->logsectsize = BBSIZE;
1196 if (xfs_has_large_extent_counts(mp))
1197 geo->flags |= XFS_FSOP_GEOM_FLAGS_NREXT64;
1198 geo->rtsectsize = sbp->sb_blocksize;
1199 geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
1201 if (struct_version < 4)
1204 if (xfs_has_logv2(mp))
1205 geo->flags |= XFS_FSOP_GEOM_FLAGS_LOGV2;
1207 geo->logsunit = sbp->sb_logsunit;
1209 if (struct_version < 5)
1212 geo->version = XFS_FSOP_GEOM_VERSION_V5;
1215 /* Read a secondary superblock. */
1217 xfs_sb_read_secondary(
1218 struct xfs_mount *mp,
1219 struct xfs_trans *tp,
1220 xfs_agnumber_t agno,
1221 struct xfs_buf **bpp)
1226 ASSERT(agno != 0 && agno != NULLAGNUMBER);
1227 error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
1228 XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
1229 XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_sb_buf_ops);
1232 xfs_buf_set_ref(bp, XFS_SSB_REF);
1237 /* Get an uninitialised secondary superblock buffer. */
1239 xfs_sb_get_secondary(
1240 struct xfs_mount *mp,
1241 struct xfs_trans *tp,
1242 xfs_agnumber_t agno,
1243 struct xfs_buf **bpp)
1248 ASSERT(agno != 0 && agno != NULLAGNUMBER);
1249 error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
1250 XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
1251 XFS_FSS_TO_BB(mp, 1), 0, &bp);
1254 bp->b_ops = &xfs_sb_buf_ops;
1255 xfs_buf_oneshot(bp);
1261 * sunit, swidth, sectorsize(optional with 0) should be all in bytes,
1262 * so users won't be confused by values in error messages.
1265 xfs_validate_stripe_geometry(
1266 struct xfs_mount *mp,
1272 if (swidth > INT_MAX) {
1275 "stripe width (%lld) is too large", swidth);
1279 if (sunit > swidth) {
1282 "stripe unit (%lld) is larger than the stripe width (%lld)", sunit, swidth);
1286 if (sectorsize && (int)sunit % sectorsize) {
1289 "stripe unit (%lld) must be a multiple of the sector size (%d)",
1294 if (sunit && !swidth) {
1297 "invalid stripe unit (%lld) and stripe width of 0", sunit);
1301 if (!sunit && swidth) {
1304 "invalid stripe width (%lld) and stripe unit of 0", swidth);
1308 if (sunit && (int)swidth % (int)sunit) {
1311 "stripe width (%lld) must be a multiple of the stripe unit (%lld)",