// SPDX-License-Identifier: GPL-2.0/* * Copyright (c) 2000-2005 Silicon Graphics, Inc. * All Rights Reserved. */#include"xfs.h"#include"xfs_fs.h"#include"xfs_shared.h"#include"xfs_format.h"#include"xfs_log_format.h"#include"xfs_trans_resv.h"#include"xfs_bit.h"#include"xfs_sb.h"#include"xfs_mount.h"#include"xfs_ialloc.h"#include"xfs_alloc.h"#include"xfs_error.h"#include"xfs_trans.h"#include"xfs_buf_item.h"#include"xfs_bmap_btree.h"#include"xfs_alloc_btree.h"#include"xfs_log.h"#include"xfs_rmap_btree.h"#include"xfs_refcount_btree.h"#include"xfs_da_format.h"#include"xfs_health.h"#include"xfs_ag.h"#include"xfs_rtbitmap.h"/* * Physical superblock buffer manipulations. Shared with libxfs in userspace. *//* * Check that all the V4 feature bits that the V5 filesystem format requires are * correctly set. */staticboolxfs_sb_validate_v5_features(structxfs_sb*sbp){/* We must not have any unknown V4 feature bits set */if(sbp->sb_versionnum&~XFS_SB_VERSION_OKBITS)returnfalse;/* * The CRC bit is considered an invalid V4 flag, so we have to add it * manually to the OKBITS mask. */if(sbp->sb_features2&~(XFS_SB_VERSION2_OKBITS|XFS_SB_VERSION2_CRCBIT))returnfalse;/* Now check all the required V4 feature flags are set. */#define V5_VERS_FLAGS (XFS_SB_VERSION_NLINKBIT | \ XFS_SB_VERSION_ALIGNBIT | \ XFS_SB_VERSION_LOGV2BIT | \ XFS_SB_VERSION_EXTFLGBIT | \ XFS_SB_VERSION_DIRV2BIT | \ XFS_SB_VERSION_MOREBITSBIT)#define V5_FEAT_FLAGS (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \ XFS_SB_VERSION2_ATTR2BIT | \ XFS_SB_VERSION2_PROJID32BIT | \ XFS_SB_VERSION2_CRCBIT)if((sbp->sb_versionnum&V5_VERS_FLAGS)!=V5_VERS_FLAGS)returnfalse;if((sbp->sb_features2&V5_FEAT_FLAGS)!=V5_FEAT_FLAGS)returnfalse;returntrue;}/* * We current support XFS v5 formats with known features and v4 superblocks with * at least V2 directories. */boolxfs_sb_good_version(structxfs_sb*sbp){/* * All v5 filesystems are supported, but we must check that all the * required v4 feature flags are enabled correctly as the code checks * those flags and not for v5 support. */if(xfs_sb_is_v5(sbp))returnxfs_sb_validate_v5_features(sbp);/* versions prior to v4 are not supported */if(XFS_SB_VERSION_NUM(sbp)!=XFS_SB_VERSION_4)returnfalse;/* We must not have any unknown v4 feature bits set */if((sbp->sb_versionnum&~XFS_SB_VERSION_OKBITS)||((sbp->sb_versionnum&XFS_SB_VERSION_MOREBITSBIT)&&(