162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2000-2005 Silicon Graphics, Inc.
462306a36Sopenharmony_ci * Copyright (c) 2013 Red Hat, Inc.
562306a36Sopenharmony_ci * All Rights Reserved.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef __XFS_SHARED_H__
862306a36Sopenharmony_ci#define __XFS_SHARED_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci/*
1162306a36Sopenharmony_ci * Definitions shared between kernel and userspace that don't fit into any other
1262306a36Sopenharmony_ci * header file that is shared with userspace.
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_cistruct xfs_ifork;
1562306a36Sopenharmony_cistruct xfs_buf;
1662306a36Sopenharmony_cistruct xfs_buf_ops;
1762306a36Sopenharmony_cistruct xfs_mount;
1862306a36Sopenharmony_cistruct xfs_trans;
1962306a36Sopenharmony_cistruct xfs_inode;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * Buffer verifier operations are widely used, including userspace tools
2362306a36Sopenharmony_ci */
2462306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_agf_buf_ops;
2562306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_agfl_buf_ops;
2662306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_agi_buf_ops;
2762306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;
2862306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;
2962306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_bmbt_buf_ops;
3062306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_bnobt_buf_ops;
3162306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_cntbt_buf_ops;
3262306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_da3_node_buf_ops;
3362306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_dquot_buf_ops;
3462306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;
3562306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_finobt_buf_ops;
3662306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_inobt_buf_ops;
3762306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_inode_buf_ops;
3862306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_inode_buf_ra_ops;
3962306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_refcountbt_buf_ops;
4062306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_rmapbt_buf_ops;
4162306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_rtbuf_ops;
4262306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_sb_buf_ops;
4362306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;
4462306a36Sopenharmony_ciextern const struct xfs_buf_ops xfs_symlink_buf_ops;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/* log size calculation functions */
4762306a36Sopenharmony_ciint	xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
4862306a36Sopenharmony_ciint	xfs_log_calc_minimum_size(struct xfs_mount *);
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cistruct xfs_trans_res;
5162306a36Sopenharmony_civoid	xfs_log_get_max_trans_res(struct xfs_mount *mp,
5262306a36Sopenharmony_ci				  struct xfs_trans_res *max_resp);
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/*
5562306a36Sopenharmony_ci * Values for t_flags.
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_ci/* Transaction needs to be logged */
5862306a36Sopenharmony_ci#define XFS_TRANS_DIRTY			(1u << 0)
5962306a36Sopenharmony_ci/* Superblock is dirty and needs to be logged */
6062306a36Sopenharmony_ci#define XFS_TRANS_SB_DIRTY		(1u << 1)
6162306a36Sopenharmony_ci/* Transaction took a permanent log reservation */
6262306a36Sopenharmony_ci#define XFS_TRANS_PERM_LOG_RES		(1u << 2)
6362306a36Sopenharmony_ci/* Synchronous transaction commit needed */
6462306a36Sopenharmony_ci#define XFS_TRANS_SYNC			(1u << 3)
6562306a36Sopenharmony_ci/* Transaction can use reserve block pool */
6662306a36Sopenharmony_ci#define XFS_TRANS_RESERVE		(1u << 4)
6762306a36Sopenharmony_ci/* Transaction should avoid VFS level superblock write accounting */
6862306a36Sopenharmony_ci#define XFS_TRANS_NO_WRITECOUNT		(1u << 5)
6962306a36Sopenharmony_ci/* Transaction has freed blocks returned to it's reservation */
7062306a36Sopenharmony_ci#define XFS_TRANS_RES_FDBLKS		(1u << 6)
7162306a36Sopenharmony_ci/* Transaction contains an intent done log item */
7262306a36Sopenharmony_ci#define XFS_TRANS_HAS_INTENT_DONE	(1u << 7)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/*
7562306a36Sopenharmony_ci * LOWMODE is used by the allocator to activate the lowspace algorithm - when
7662306a36Sopenharmony_ci * free space is running low the extent allocator may choose to allocate an
7762306a36Sopenharmony_ci * extent from an AG without leaving sufficient space for a btree split when
7862306a36Sopenharmony_ci * inserting the new extent. In this case the allocator will enable the
7962306a36Sopenharmony_ci * lowspace algorithm which is supposed to allow further allocations (such as
8062306a36Sopenharmony_ci * btree splits and newroots) to allocate from sequential AGs. In order to
8162306a36Sopenharmony_ci * avoid locking AGs out of order the lowspace algorithm will start searching
8262306a36Sopenharmony_ci * for free space from AG 0. If the correct transaction reservations have been
8362306a36Sopenharmony_ci * made then this algorithm will eventually find all the space it needs.
8462306a36Sopenharmony_ci */
8562306a36Sopenharmony_ci#define XFS_TRANS_LOWMODE	0x100	/* allocate in low space mode */
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/*
8862306a36Sopenharmony_ci * Field values for xfs_trans_mod_sb.
8962306a36Sopenharmony_ci */
9062306a36Sopenharmony_ci#define	XFS_TRANS_SB_ICOUNT		0x00000001
9162306a36Sopenharmony_ci#define	XFS_TRANS_SB_IFREE		0x00000002
9262306a36Sopenharmony_ci#define	XFS_TRANS_SB_FDBLOCKS		0x00000004
9362306a36Sopenharmony_ci#define	XFS_TRANS_SB_RES_FDBLOCKS	0x00000008
9462306a36Sopenharmony_ci#define	XFS_TRANS_SB_FREXTENTS		0x00000010
9562306a36Sopenharmony_ci#define	XFS_TRANS_SB_RES_FREXTENTS	0x00000020
9662306a36Sopenharmony_ci#define	XFS_TRANS_SB_DBLOCKS		0x00000040
9762306a36Sopenharmony_ci#define	XFS_TRANS_SB_AGCOUNT		0x00000080
9862306a36Sopenharmony_ci#define	XFS_TRANS_SB_IMAXPCT		0x00000100
9962306a36Sopenharmony_ci#define	XFS_TRANS_SB_REXTSIZE		0x00000200
10062306a36Sopenharmony_ci#define	XFS_TRANS_SB_RBMBLOCKS		0x00000400
10162306a36Sopenharmony_ci#define	XFS_TRANS_SB_RBLOCKS		0x00000800
10262306a36Sopenharmony_ci#define	XFS_TRANS_SB_REXTENTS		0x00001000
10362306a36Sopenharmony_ci#define	XFS_TRANS_SB_REXTSLOG		0x00002000
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci/*
10662306a36Sopenharmony_ci * Here we centralize the specification of XFS meta-data buffer reference count
10762306a36Sopenharmony_ci * values.  This determines how hard the buffer cache tries to hold onto the
10862306a36Sopenharmony_ci * buffer.
10962306a36Sopenharmony_ci */
11062306a36Sopenharmony_ci#define	XFS_AGF_REF		4
11162306a36Sopenharmony_ci#define	XFS_AGI_REF		4
11262306a36Sopenharmony_ci#define	XFS_AGFL_REF		3
11362306a36Sopenharmony_ci#define	XFS_INO_BTREE_REF	3
11462306a36Sopenharmony_ci#define	XFS_ALLOC_BTREE_REF	2
11562306a36Sopenharmony_ci#define	XFS_BMAP_BTREE_REF	2
11662306a36Sopenharmony_ci#define	XFS_RMAP_BTREE_REF	2
11762306a36Sopenharmony_ci#define	XFS_DIR_BTREE_REF	2
11862306a36Sopenharmony_ci#define	XFS_INO_REF		2
11962306a36Sopenharmony_ci#define	XFS_ATTR_BTREE_REF	1
12062306a36Sopenharmony_ci#define	XFS_DQUOT_REF		1
12162306a36Sopenharmony_ci#define	XFS_REFC_BTREE_REF	1
12262306a36Sopenharmony_ci#define	XFS_SSB_REF		0
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci/*
12562306a36Sopenharmony_ci * Flags for xfs_trans_ichgtime().
12662306a36Sopenharmony_ci */
12762306a36Sopenharmony_ci#define	XFS_ICHGTIME_MOD	0x1	/* data fork modification timestamp */
12862306a36Sopenharmony_ci#define	XFS_ICHGTIME_CHG	0x2	/* inode field change timestamp */
12962306a36Sopenharmony_ci#define	XFS_ICHGTIME_CREATE	0x4	/* inode create timestamp */
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci/*
13362306a36Sopenharmony_ci * Symlink decoding/encoding functions
13462306a36Sopenharmony_ci */
13562306a36Sopenharmony_ciint xfs_symlink_blocks(struct xfs_mount *mp, int pathlen);
13662306a36Sopenharmony_ciint xfs_symlink_hdr_set(struct xfs_mount *mp, xfs_ino_t ino, uint32_t offset,
13762306a36Sopenharmony_ci			uint32_t size, struct xfs_buf *bp);
13862306a36Sopenharmony_cibool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset,
13962306a36Sopenharmony_ci			uint32_t size, struct xfs_buf *bp);
14062306a36Sopenharmony_civoid xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp,
14162306a36Sopenharmony_ci				 struct xfs_inode *ip, struct xfs_ifork *ifp);
14262306a36Sopenharmony_cixfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip);
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* Computed inode geometry for the filesystem. */
14562306a36Sopenharmony_cistruct xfs_ino_geometry {
14662306a36Sopenharmony_ci	/* Maximum inode count in this filesystem. */
14762306a36Sopenharmony_ci	uint64_t	maxicount;
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci	/* Actual inode cluster buffer size, in bytes. */
15062306a36Sopenharmony_ci	unsigned int	inode_cluster_size;
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	/*
15362306a36Sopenharmony_ci	 * Desired inode cluster buffer size, in bytes.  This value is not
15462306a36Sopenharmony_ci	 * rounded up to at least one filesystem block, which is necessary for
15562306a36Sopenharmony_ci	 * the sole purpose of validating sb_spino_align.  Runtime code must
15662306a36Sopenharmony_ci	 * only ever use inode_cluster_size.
15762306a36Sopenharmony_ci	 */
15862306a36Sopenharmony_ci	unsigned int	inode_cluster_size_raw;
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci	/* Inode cluster sizes, adjusted to be at least 1 fsb. */
16162306a36Sopenharmony_ci	unsigned int	inodes_per_cluster;
16262306a36Sopenharmony_ci	unsigned int	blocks_per_cluster;
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci	/* Inode cluster alignment. */
16562306a36Sopenharmony_ci	unsigned int	cluster_align;
16662306a36Sopenharmony_ci	unsigned int	cluster_align_inodes;
16762306a36Sopenharmony_ci	unsigned int	inoalign_mask;	/* mask sb_inoalignmt if used */
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci	unsigned int	inobt_mxr[2]; /* max inobt btree records */
17062306a36Sopenharmony_ci	unsigned int	inobt_mnr[2]; /* min inobt btree records */
17162306a36Sopenharmony_ci	unsigned int	inobt_maxlevels; /* max inobt btree levels. */
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	/* Size of inode allocations under normal operation. */
17462306a36Sopenharmony_ci	unsigned int	ialloc_inos;
17562306a36Sopenharmony_ci	unsigned int	ialloc_blks;
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	/* Minimum inode blocks for a sparse allocation. */
17862306a36Sopenharmony_ci	unsigned int	ialloc_min_blks;
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci	/* stripe unit inode alignment */
18162306a36Sopenharmony_ci	unsigned int	ialloc_align;
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	unsigned int	agino_log;	/* #bits for agino in inum */
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	/* precomputed default inode attribute fork offset */
18662306a36Sopenharmony_ci	unsigned int	attr_fork_offset;
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci	/* precomputed value for di_flags2 */
18962306a36Sopenharmony_ci	uint64_t	new_diflags2;
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci};
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci#endif /* __XFS_SHARED_H__ */
194