18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2000-2005 Silicon Graphics, Inc.
48c2ecf20Sopenharmony_ci * Copyright (c) 2013 Red Hat, Inc.
58c2ecf20Sopenharmony_ci * All Rights Reserved.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef __XFS_SHARED_H__
88c2ecf20Sopenharmony_ci#define __XFS_SHARED_H__
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * Definitions shared between kernel and userspace that don't fit into any other
128c2ecf20Sopenharmony_ci * header file that is shared with userspace.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_cistruct xfs_ifork;
158c2ecf20Sopenharmony_cistruct xfs_buf;
168c2ecf20Sopenharmony_cistruct xfs_buf_ops;
178c2ecf20Sopenharmony_cistruct xfs_mount;
188c2ecf20Sopenharmony_cistruct xfs_trans;
198c2ecf20Sopenharmony_cistruct xfs_inode;
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * Buffer verifier operations are widely used, including userspace tools
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_agf_buf_ops;
258c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_agi_buf_ops;
268c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_agf_buf_ops;
278c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_agfl_buf_ops;
288c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_bnobt_buf_ops;
298c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_cntbt_buf_ops;
308c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_rmapbt_buf_ops;
318c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_refcountbt_buf_ops;
328c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;
338c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;
348c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_bmbt_buf_ops;
358c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_da3_node_buf_ops;
368c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_dquot_buf_ops;
378c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_symlink_buf_ops;
388c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_agi_buf_ops;
398c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_inobt_buf_ops;
408c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_finobt_buf_ops;
418c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_inode_buf_ops;
428c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_inode_buf_ra_ops;
438c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_dquot_buf_ops;
448c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;
458c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_sb_buf_ops;
468c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;
478c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_symlink_buf_ops;
488c2ecf20Sopenharmony_ciextern const struct xfs_buf_ops xfs_rtbuf_ops;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* log size calculation functions */
518c2ecf20Sopenharmony_ciint	xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
528c2ecf20Sopenharmony_ciint	xfs_log_calc_minimum_size(struct xfs_mount *);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct xfs_trans_res;
558c2ecf20Sopenharmony_civoid	xfs_log_get_max_trans_res(struct xfs_mount *mp,
568c2ecf20Sopenharmony_ci				  struct xfs_trans_res *max_resp);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/*
598c2ecf20Sopenharmony_ci * Values for t_flags.
608c2ecf20Sopenharmony_ci */
618c2ecf20Sopenharmony_ci#define	XFS_TRANS_DIRTY		0x01	/* something needs to be logged */
628c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_DIRTY	0x02	/* superblock is modified */
638c2ecf20Sopenharmony_ci#define	XFS_TRANS_PERM_LOG_RES	0x04	/* xact took a permanent log res */
648c2ecf20Sopenharmony_ci#define	XFS_TRANS_SYNC		0x08	/* make commit synchronous */
658c2ecf20Sopenharmony_ci#define XFS_TRANS_DQ_DIRTY	0x10	/* at least one dquot in trx dirty */
668c2ecf20Sopenharmony_ci#define XFS_TRANS_RESERVE	0x20    /* OK to use reserved data blocks */
678c2ecf20Sopenharmony_ci#define XFS_TRANS_NO_WRITECOUNT 0x40	/* do not elevate SB writecount */
688c2ecf20Sopenharmony_ci#define XFS_TRANS_RES_FDBLKS	0x80	/* reserve newly freed blocks */
698c2ecf20Sopenharmony_ci/*
708c2ecf20Sopenharmony_ci * LOWMODE is used by the allocator to activate the lowspace algorithm - when
718c2ecf20Sopenharmony_ci * free space is running low the extent allocator may choose to allocate an
728c2ecf20Sopenharmony_ci * extent from an AG without leaving sufficient space for a btree split when
738c2ecf20Sopenharmony_ci * inserting the new extent. In this case the allocator will enable the
748c2ecf20Sopenharmony_ci * lowspace algorithm which is supposed to allow further allocations (such as
758c2ecf20Sopenharmony_ci * btree splits and newroots) to allocate from sequential AGs. In order to
768c2ecf20Sopenharmony_ci * avoid locking AGs out of order the lowspace algorithm will start searching
778c2ecf20Sopenharmony_ci * for free space from AG 0. If the correct transaction reservations have been
788c2ecf20Sopenharmony_ci * made then this algorithm will eventually find all the space it needs.
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_ci#define XFS_TRANS_LOWMODE	0x100	/* allocate in low space mode */
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci * Field values for xfs_trans_mod_sb.
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_ICOUNT		0x00000001
868c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_IFREE		0x00000002
878c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_FDBLOCKS		0x00000004
888c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_RES_FDBLOCKS	0x00000008
898c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_FREXTENTS		0x00000010
908c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_RES_FREXTENTS	0x00000020
918c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_DBLOCKS		0x00000040
928c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_AGCOUNT		0x00000080
938c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_IMAXPCT		0x00000100
948c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_REXTSIZE		0x00000200
958c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_RBMBLOCKS		0x00000400
968c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_RBLOCKS		0x00000800
978c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_REXTENTS		0x00001000
988c2ecf20Sopenharmony_ci#define	XFS_TRANS_SB_REXTSLOG		0x00002000
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * Here we centralize the specification of XFS meta-data buffer reference count
1028c2ecf20Sopenharmony_ci * values.  This determines how hard the buffer cache tries to hold onto the
1038c2ecf20Sopenharmony_ci * buffer.
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_ci#define	XFS_AGF_REF		4
1068c2ecf20Sopenharmony_ci#define	XFS_AGI_REF		4
1078c2ecf20Sopenharmony_ci#define	XFS_AGFL_REF		3
1088c2ecf20Sopenharmony_ci#define	XFS_INO_BTREE_REF	3
1098c2ecf20Sopenharmony_ci#define	XFS_ALLOC_BTREE_REF	2
1108c2ecf20Sopenharmony_ci#define	XFS_BMAP_BTREE_REF	2
1118c2ecf20Sopenharmony_ci#define	XFS_RMAP_BTREE_REF	2
1128c2ecf20Sopenharmony_ci#define	XFS_DIR_BTREE_REF	2
1138c2ecf20Sopenharmony_ci#define	XFS_INO_REF		2
1148c2ecf20Sopenharmony_ci#define	XFS_ATTR_BTREE_REF	1
1158c2ecf20Sopenharmony_ci#define	XFS_DQUOT_REF		1
1168c2ecf20Sopenharmony_ci#define	XFS_REFC_BTREE_REF	1
1178c2ecf20Sopenharmony_ci#define	XFS_SSB_REF		0
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/*
1208c2ecf20Sopenharmony_ci * Flags for xfs_trans_ichgtime().
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ci#define	XFS_ICHGTIME_MOD	0x1	/* data fork modification timestamp */
1238c2ecf20Sopenharmony_ci#define	XFS_ICHGTIME_CHG	0x2	/* inode field change timestamp */
1248c2ecf20Sopenharmony_ci#define	XFS_ICHGTIME_CREATE	0x4	/* inode create timestamp */
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/*
1288c2ecf20Sopenharmony_ci * Symlink decoding/encoding functions
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ciint xfs_symlink_blocks(struct xfs_mount *mp, int pathlen);
1318c2ecf20Sopenharmony_ciint xfs_symlink_hdr_set(struct xfs_mount *mp, xfs_ino_t ino, uint32_t offset,
1328c2ecf20Sopenharmony_ci			uint32_t size, struct xfs_buf *bp);
1338c2ecf20Sopenharmony_cibool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset,
1348c2ecf20Sopenharmony_ci			uint32_t size, struct xfs_buf *bp);
1358c2ecf20Sopenharmony_civoid xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp,
1368c2ecf20Sopenharmony_ci				 struct xfs_inode *ip, struct xfs_ifork *ifp);
1378c2ecf20Sopenharmony_cixfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/* Computed inode geometry for the filesystem. */
1408c2ecf20Sopenharmony_cistruct xfs_ino_geometry {
1418c2ecf20Sopenharmony_ci	/* Maximum inode count in this filesystem. */
1428c2ecf20Sopenharmony_ci	uint64_t	maxicount;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/* Actual inode cluster buffer size, in bytes. */
1458c2ecf20Sopenharmony_ci	unsigned int	inode_cluster_size;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	/*
1488c2ecf20Sopenharmony_ci	 * Desired inode cluster buffer size, in bytes.  This value is not
1498c2ecf20Sopenharmony_ci	 * rounded up to at least one filesystem block, which is necessary for
1508c2ecf20Sopenharmony_ci	 * the sole purpose of validating sb_spino_align.  Runtime code must
1518c2ecf20Sopenharmony_ci	 * only ever use inode_cluster_size.
1528c2ecf20Sopenharmony_ci	 */
1538c2ecf20Sopenharmony_ci	unsigned int	inode_cluster_size_raw;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	/* Inode cluster sizes, adjusted to be at least 1 fsb. */
1568c2ecf20Sopenharmony_ci	unsigned int	inodes_per_cluster;
1578c2ecf20Sopenharmony_ci	unsigned int	blocks_per_cluster;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	/* Inode cluster alignment. */
1608c2ecf20Sopenharmony_ci	unsigned int	cluster_align;
1618c2ecf20Sopenharmony_ci	unsigned int	cluster_align_inodes;
1628c2ecf20Sopenharmony_ci	unsigned int	inoalign_mask;	/* mask sb_inoalignmt if used */
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	unsigned int	inobt_mxr[2]; /* max inobt btree records */
1658c2ecf20Sopenharmony_ci	unsigned int	inobt_mnr[2]; /* min inobt btree records */
1668c2ecf20Sopenharmony_ci	unsigned int	inobt_maxlevels; /* max inobt btree levels. */
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	/* Size of inode allocations under normal operation. */
1698c2ecf20Sopenharmony_ci	unsigned int	ialloc_inos;
1708c2ecf20Sopenharmony_ci	unsigned int	ialloc_blks;
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	/* Minimum inode blocks for a sparse allocation. */
1738c2ecf20Sopenharmony_ci	unsigned int	ialloc_min_blks;
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	/* stripe unit inode alignment */
1768c2ecf20Sopenharmony_ci	unsigned int	ialloc_align;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	unsigned int	agino_log;	/* #bits for agino in inum */
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	/* precomputed value for di_flags2 */
1818c2ecf20Sopenharmony_ci	uint64_t	new_diflags2;
1828c2ecf20Sopenharmony_ci};
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#endif /* __XFS_SHARED_H__ */
185