3030 * Physical superblock buffer manipulations. Shared with libxfs in userspace.
3131 */
3232
33+ /*
34+ * Check that all the V4 feature bits that the V5 filesystem format requires are
35+ * correctly set.
36+ */
37+ static bool
38+ xfs_sb_validate_v5_features (
39+ struct xfs_sb * sbp )
40+ {
41+ /* We must not have any unknown V4 feature bits set */
42+ if (sbp -> sb_versionnum & ~XFS_SB_VERSION_OKBITS )
43+ return false;
44+
45+ /*
46+ * The CRC bit is considered an invalid V4 flag, so we have to add it
47+ * manually to the OKBITS mask.
48+ */
49+ if (sbp -> sb_features2 & ~(XFS_SB_VERSION2_OKBITS |
50+ XFS_SB_VERSION2_CRCBIT ))
51+ return false;
52+
53+ /* Now check all the required V4 feature flags are set. */
54+
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)
61+
62+ #define V5_FEAT_FLAGS (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
63+ XFS_SB_VERSION2_ATTR2BIT | \
64+ XFS_SB_VERSION2_PROJID32BIT | \
65+ XFS_SB_VERSION2_CRCBIT)
66+
67+ if ((sbp -> sb_versionnum & V5_VERS_FLAGS ) != V5_VERS_FLAGS )
68+ return false;
69+ if ((sbp -> sb_features2 & V5_FEAT_FLAGS ) != V5_FEAT_FLAGS )
70+ return false;
71+ return true;
72+ }
73+
3374/*
3475 * We support all XFS versions newer than a v4 superblock with V2 directories.
3576 */
3677bool
3778xfs_sb_good_version (
3879 struct xfs_sb * sbp )
3980{
40- /* all v5 filesystems are supported */
81+ /*
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.
85+ */
4186 if (xfs_sb_is_v5 (sbp ))
42- return true;
87+ return xfs_sb_validate_v5_features (sbp );
88+
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 )))
93+ return false;
4394
4495 /* versions prior to v4 are not supported */
4596 if (XFS_SB_VERSION_NUM (sbp ) < XFS_SB_VERSION_4 )
@@ -51,12 +102,6 @@ xfs_sb_good_version(
51102 if (!(sbp -> sb_versionnum & XFS_SB_VERSION_EXTFLGBIT ))
52103 return false;
53104
54- /* And must not have any unknown v4 feature bits set */
55- if ((sbp -> sb_versionnum & ~XFS_SB_VERSION_OKBITS ) ||
56- ((sbp -> sb_versionnum & XFS_SB_VERSION_MOREBITSBIT ) &&
57- (sbp -> sb_features2 & ~XFS_SB_VERSION2_OKBITS )))
58- return false;
59-
60105 /* It's a supported v4 filesystem */
61106 return true;
62107}
@@ -267,12 +312,15 @@ xfs_validate_sb_common(
267312 bool has_dalign ;
268313
269314 if (!xfs_verify_magic (bp , dsb -> sb_magicnum )) {
270- xfs_warn (mp , "bad magic number" );
315+ xfs_warn (mp ,
316+ "Superblock has bad magic number 0x%x. Not an XFS filesystem?" ,
317+ be32_to_cpu (dsb -> sb_magicnum ));
271318 return - EWRONGFS ;
272319 }
273320
274321 if (!xfs_sb_good_version (sbp )) {
275- xfs_warn (mp , "bad version" );
322+ xfs_warn (mp ,
323+ "Superblock has unknown features enabled or corrupted feature masks." );
276324 return - EWRONGFS ;
277325 }
278326
0 commit comments