fs/xfs/libxfs/xfs_sb.c

Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_sb.c

File Facts

System
Linux kernel
Corpus path
fs/xfs/libxfs/xfs_sb.c
Extension
.c
Size
52997 bytes
Lines
1756
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!xfs_is_readonly(mp)) {
			xfs_warn(mp,
"Attempted to mount read-only compatible filesystem read-write.");
			xfs_warn(mp,
"Filesystem can only be safely mounted read only.");

			return -EINVAL;
		}
	}
	if (xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_UNKNOWN)) {
		xfs_warn(mp,
"Superblock has unknown incompatible features (0x%x) enabled.",
			(sbp->sb_features_incompat &
					XFS_SB_FEAT_INCOMPAT_UNKNOWN));
		xfs_warn(mp,
"Filesystem cannot be safely mounted by this kernel.");
		return -EINVAL;
	}

	return 0;
}

/* Return the number of extents covered by a single rt bitmap file */
static xfs_rtbxlen_t
xfs_extents_per_rbm(
	struct xfs_sb		*sbp)
{
	if (xfs_sb_is_v5(sbp) &&
	    (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR))
		return sbp->sb_rgextents;
	return sbp->sb_rextents;
}

/*
 * Return the payload size of a single rt bitmap block (without the metadata
 * header if any).
 */
static inline unsigned int
xfs_rtbmblock_size(
	struct xfs_sb		*sbp)
{
	if (xfs_sb_is_v5(sbp) &&
	    (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR))
		return sbp->sb_blocksize - sizeof(struct xfs_rtbuf_blkinfo);
	return sbp->sb_blocksize;
}

static uint64_t
xfs_expected_rbmblocks(
	struct xfs_sb		*sbp)
{
	if (xfs_sb_is_v5(sbp) &&
	    (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED))
		return 0;
	return howmany_64(xfs_extents_per_rbm(sbp),
			  NBBY * xfs_rtbmblock_size(sbp));
}

/* Validate the realtime geometry */
bool
xfs_validate_rt_geometry(
	struct xfs_sb		*sbp)
{
	if (xfs_sb_is_v5(sbp) &&
	    (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED)) {
		if (sbp->sb_rextsize != 1)
			return false;
	} else {
		if (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE ||
		    sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE)
			return false;
	}

	if (sbp->sb_rblocks == 0) {
		if (sbp->sb_rextents != 0 || sbp->sb_rbmblocks != 0 ||
		    sbp->sb_rextslog != 0 || sbp->sb_frextents != 0)
			return false;
		return true;
	}

	if (sbp->sb_rextents == 0 ||
	    sbp->sb_rextents != div_u64(sbp->sb_rblocks, sbp->sb_rextsize) ||
	    sbp->sb_rextslog != xfs_compute_rextslog(sbp->sb_rextents) ||
	    sbp->sb_rbmblocks != xfs_expected_rbmblocks(sbp))
		return false;

	if (xfs_sb_is_v5(sbp) &&
	    (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_ZONED)) {
		uint32_t		mod;

Annotation

Implementation Notes