18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2000-2005 Silicon Graphics, Inc.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef __XFS_FORMAT_H__
78c2ecf20Sopenharmony_ci#define __XFS_FORMAT_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * XFS On Disk Format Definitions
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * This header file defines all the on-disk format definitions for
138c2ecf20Sopenharmony_ci * general XFS objects. Directory and attribute related objects are defined in
148c2ecf20Sopenharmony_ci * xfs_da_format.h, which log and log item formats are defined in
158c2ecf20Sopenharmony_ci * xfs_log_format.h. Everything else goes here.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct xfs_mount;
198c2ecf20Sopenharmony_cistruct xfs_trans;
208c2ecf20Sopenharmony_cistruct xfs_inode;
218c2ecf20Sopenharmony_cistruct xfs_buf;
228c2ecf20Sopenharmony_cistruct xfs_ifork;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * Super block
268c2ecf20Sopenharmony_ci * Fits into a sector-sized buffer at address 0 of each allocation group.
278c2ecf20Sopenharmony_ci * Only the first of these is ever updated except during growfs.
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci#define	XFS_SB_MAGIC		0x58465342	/* 'XFSB' */
308c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_1	1		/* 5.3, 6.0.1, 6.1 */
318c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_2	2		/* 6.2 - attributes */
328c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_3	3		/* 6.2 - new inode version */
338c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_4	4		/* 6.2+ - bitmask version */
348c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_5	5		/* CRC enabled filesystem */
358c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_NUMBITS		0x000f
368c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_ALLFBITS		0xfff0
378c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_ATTRBIT		0x0010
388c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_NLINKBIT		0x0020
398c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_QUOTABIT		0x0040
408c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_ALIGNBIT		0x0080
418c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_DALIGNBIT	0x0100
428c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_SHAREDBIT	0x0200
438c2ecf20Sopenharmony_ci#define XFS_SB_VERSION_LOGV2BIT		0x0400
448c2ecf20Sopenharmony_ci#define XFS_SB_VERSION_SECTORBIT	0x0800
458c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_EXTFLGBIT	0x1000
468c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_DIRV2BIT		0x2000
478c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_BORGBIT		0x4000	/* ASCII only case-insens. */
488c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_MOREBITSBIT	0x8000
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/*
518c2ecf20Sopenharmony_ci * The size of a single extended attribute on disk is limited by
528c2ecf20Sopenharmony_ci * the size of index values within the attribute entries themselves.
538c2ecf20Sopenharmony_ci * These are be16 fields, so we can only support attribute data
548c2ecf20Sopenharmony_ci * sizes up to 2^16 bytes in length.
558c2ecf20Sopenharmony_ci */
568c2ecf20Sopenharmony_ci#define XFS_XATTR_SIZE_MAX (1 << 16)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/*
598c2ecf20Sopenharmony_ci * Supported feature bit list is just all bits in the versionnum field because
608c2ecf20Sopenharmony_ci * we've used them all up and understand them all. Except, of course, for the
618c2ecf20Sopenharmony_ci * shared superblock bit, which nobody knows what it does and so is unsupported.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_OKBITS		\
648c2ecf20Sopenharmony_ci	((XFS_SB_VERSION_NUMBITS | XFS_SB_VERSION_ALLFBITS) & \
658c2ecf20Sopenharmony_ci		~XFS_SB_VERSION_SHAREDBIT)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci/*
688c2ecf20Sopenharmony_ci * There are two words to hold XFS "feature" bits: the original
698c2ecf20Sopenharmony_ci * word, sb_versionnum, and sb_features2.  Whenever a bit is set in
708c2ecf20Sopenharmony_ci * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
718c2ecf20Sopenharmony_ci *
728c2ecf20Sopenharmony_ci * These defines represent bits in sb_features2.
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_RESERVED1BIT	0x00000001
758c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_LAZYSBCOUNTBIT	0x00000002	/* Superblk counters */
768c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_RESERVED4BIT	0x00000004
778c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_ATTR2BIT	0x00000008	/* Inline attr rework */
788c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_PARENTBIT	0x00000010	/* parent pointers */
798c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_PROJID32BIT	0x00000080	/* 32 bit project id */
808c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_CRCBIT		0x00000100	/* metadata CRCs */
818c2ecf20Sopenharmony_ci#define XFS_SB_VERSION2_FTYPE		0x00000200	/* inode type in dir */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION2_OKBITS		\
848c2ecf20Sopenharmony_ci	(XFS_SB_VERSION2_LAZYSBCOUNTBIT	| \
858c2ecf20Sopenharmony_ci	 XFS_SB_VERSION2_ATTR2BIT	| \
868c2ecf20Sopenharmony_ci	 XFS_SB_VERSION2_PROJID32BIT	| \
878c2ecf20Sopenharmony_ci	 XFS_SB_VERSION2_FTYPE)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* Maximum size of the xfs filesystem label, no terminating NULL */
908c2ecf20Sopenharmony_ci#define XFSLABEL_MAX			12
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/*
938c2ecf20Sopenharmony_ci * Superblock - in core version.  Must match the ondisk version below.
948c2ecf20Sopenharmony_ci * Must be padded to 64 bit alignment.
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_citypedef struct xfs_sb {
978c2ecf20Sopenharmony_ci	uint32_t	sb_magicnum;	/* magic number == XFS_SB_MAGIC */
988c2ecf20Sopenharmony_ci	uint32_t	sb_blocksize;	/* logical block size, bytes */
998c2ecf20Sopenharmony_ci	xfs_rfsblock_t	sb_dblocks;	/* number of data blocks */
1008c2ecf20Sopenharmony_ci	xfs_rfsblock_t	sb_rblocks;	/* number of realtime blocks */
1018c2ecf20Sopenharmony_ci	xfs_rtblock_t	sb_rextents;	/* number of realtime extents */
1028c2ecf20Sopenharmony_ci	uuid_t		sb_uuid;	/* user-visible file system unique id */
1038c2ecf20Sopenharmony_ci	xfs_fsblock_t	sb_logstart;	/* starting block of log if internal */
1048c2ecf20Sopenharmony_ci	xfs_ino_t	sb_rootino;	/* root inode number */
1058c2ecf20Sopenharmony_ci	xfs_ino_t	sb_rbmino;	/* bitmap inode for realtime extents */
1068c2ecf20Sopenharmony_ci	xfs_ino_t	sb_rsumino;	/* summary inode for rt bitmap */
1078c2ecf20Sopenharmony_ci	xfs_agblock_t	sb_rextsize;	/* realtime extent size, blocks */
1088c2ecf20Sopenharmony_ci	xfs_agblock_t	sb_agblocks;	/* size of an allocation group */
1098c2ecf20Sopenharmony_ci	xfs_agnumber_t	sb_agcount;	/* number of allocation groups */
1108c2ecf20Sopenharmony_ci	xfs_extlen_t	sb_rbmblocks;	/* number of rt bitmap blocks */
1118c2ecf20Sopenharmony_ci	xfs_extlen_t	sb_logblocks;	/* number of log blocks */
1128c2ecf20Sopenharmony_ci	uint16_t	sb_versionnum;	/* header version == XFS_SB_VERSION */
1138c2ecf20Sopenharmony_ci	uint16_t	sb_sectsize;	/* volume sector size, bytes */
1148c2ecf20Sopenharmony_ci	uint16_t	sb_inodesize;	/* inode size, bytes */
1158c2ecf20Sopenharmony_ci	uint16_t	sb_inopblock;	/* inodes per block */
1168c2ecf20Sopenharmony_ci	char		sb_fname[XFSLABEL_MAX]; /* file system name */
1178c2ecf20Sopenharmony_ci	uint8_t		sb_blocklog;	/* log2 of sb_blocksize */
1188c2ecf20Sopenharmony_ci	uint8_t		sb_sectlog;	/* log2 of sb_sectsize */
1198c2ecf20Sopenharmony_ci	uint8_t		sb_inodelog;	/* log2 of sb_inodesize */
1208c2ecf20Sopenharmony_ci	uint8_t		sb_inopblog;	/* log2 of sb_inopblock */
1218c2ecf20Sopenharmony_ci	uint8_t		sb_agblklog;	/* log2 of sb_agblocks (rounded up) */
1228c2ecf20Sopenharmony_ci	uint8_t		sb_rextslog;	/* log2 of sb_rextents */
1238c2ecf20Sopenharmony_ci	uint8_t		sb_inprogress;	/* mkfs is in progress, don't mount */
1248c2ecf20Sopenharmony_ci	uint8_t		sb_imax_pct;	/* max % of fs for inode space */
1258c2ecf20Sopenharmony_ci					/* statistics */
1268c2ecf20Sopenharmony_ci	/*
1278c2ecf20Sopenharmony_ci	 * These fields must remain contiguous.  If you really
1288c2ecf20Sopenharmony_ci	 * want to change their layout, make sure you fix the
1298c2ecf20Sopenharmony_ci	 * code in xfs_trans_apply_sb_deltas().
1308c2ecf20Sopenharmony_ci	 */
1318c2ecf20Sopenharmony_ci	uint64_t	sb_icount;	/* allocated inodes */
1328c2ecf20Sopenharmony_ci	uint64_t	sb_ifree;	/* free inodes */
1338c2ecf20Sopenharmony_ci	uint64_t	sb_fdblocks;	/* free data blocks */
1348c2ecf20Sopenharmony_ci	uint64_t	sb_frextents;	/* free realtime extents */
1358c2ecf20Sopenharmony_ci	/*
1368c2ecf20Sopenharmony_ci	 * End contiguous fields.
1378c2ecf20Sopenharmony_ci	 */
1388c2ecf20Sopenharmony_ci	xfs_ino_t	sb_uquotino;	/* user quota inode */
1398c2ecf20Sopenharmony_ci	xfs_ino_t	sb_gquotino;	/* group quota inode */
1408c2ecf20Sopenharmony_ci	uint16_t	sb_qflags;	/* quota flags */
1418c2ecf20Sopenharmony_ci	uint8_t		sb_flags;	/* misc. flags */
1428c2ecf20Sopenharmony_ci	uint8_t		sb_shared_vn;	/* shared version number */
1438c2ecf20Sopenharmony_ci	xfs_extlen_t	sb_inoalignmt;	/* inode chunk alignment, fsblocks */
1448c2ecf20Sopenharmony_ci	uint32_t	sb_unit;	/* stripe or raid unit */
1458c2ecf20Sopenharmony_ci	uint32_t	sb_width;	/* stripe or raid width */
1468c2ecf20Sopenharmony_ci	uint8_t		sb_dirblklog;	/* log2 of dir block size (fsbs) */
1478c2ecf20Sopenharmony_ci	uint8_t		sb_logsectlog;	/* log2 of the log sector size */
1488c2ecf20Sopenharmony_ci	uint16_t	sb_logsectsize;	/* sector size for the log, bytes */
1498c2ecf20Sopenharmony_ci	uint32_t	sb_logsunit;	/* stripe unit size for the log */
1508c2ecf20Sopenharmony_ci	uint32_t	sb_features2;	/* additional feature bits */
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	/*
1538c2ecf20Sopenharmony_ci	 * bad features2 field as a result of failing to pad the sb structure to
1548c2ecf20Sopenharmony_ci	 * 64 bits. Some machines will be using this field for features2 bits.
1558c2ecf20Sopenharmony_ci	 * Easiest just to mark it bad and not use it for anything else.
1568c2ecf20Sopenharmony_ci	 *
1578c2ecf20Sopenharmony_ci	 * This is not kept up to date in memory; it is always overwritten by
1588c2ecf20Sopenharmony_ci	 * the value in sb_features2 when formatting the incore superblock to
1598c2ecf20Sopenharmony_ci	 * the disk buffer.
1608c2ecf20Sopenharmony_ci	 */
1618c2ecf20Sopenharmony_ci	uint32_t	sb_bad_features2;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	/* version 5 superblock fields start here */
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci	/* feature masks */
1668c2ecf20Sopenharmony_ci	uint32_t	sb_features_compat;
1678c2ecf20Sopenharmony_ci	uint32_t	sb_features_ro_compat;
1688c2ecf20Sopenharmony_ci	uint32_t	sb_features_incompat;
1698c2ecf20Sopenharmony_ci	uint32_t	sb_features_log_incompat;
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	uint32_t	sb_crc;		/* superblock crc */
1728c2ecf20Sopenharmony_ci	xfs_extlen_t	sb_spino_align;	/* sparse inode chunk alignment */
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	xfs_ino_t	sb_pquotino;	/* project quota inode */
1758c2ecf20Sopenharmony_ci	xfs_lsn_t	sb_lsn;		/* last write sequence */
1768c2ecf20Sopenharmony_ci	uuid_t		sb_meta_uuid;	/* metadata file system unique id */
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	/* must be padded to 64 bit alignment */
1798c2ecf20Sopenharmony_ci} xfs_sb_t;
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define XFS_SB_CRC_OFF		offsetof(struct xfs_sb, sb_crc)
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/*
1848c2ecf20Sopenharmony_ci * Superblock - on disk version.  Must match the in core version above.
1858c2ecf20Sopenharmony_ci * Must be padded to 64 bit alignment.
1868c2ecf20Sopenharmony_ci */
1878c2ecf20Sopenharmony_citypedef struct xfs_dsb {
1888c2ecf20Sopenharmony_ci	__be32		sb_magicnum;	/* magic number == XFS_SB_MAGIC */
1898c2ecf20Sopenharmony_ci	__be32		sb_blocksize;	/* logical block size, bytes */
1908c2ecf20Sopenharmony_ci	__be64		sb_dblocks;	/* number of data blocks */
1918c2ecf20Sopenharmony_ci	__be64		sb_rblocks;	/* number of realtime blocks */
1928c2ecf20Sopenharmony_ci	__be64		sb_rextents;	/* number of realtime extents */
1938c2ecf20Sopenharmony_ci	uuid_t		sb_uuid;	/* user-visible file system unique id */
1948c2ecf20Sopenharmony_ci	__be64		sb_logstart;	/* starting block of log if internal */
1958c2ecf20Sopenharmony_ci	__be64		sb_rootino;	/* root inode number */
1968c2ecf20Sopenharmony_ci	__be64		sb_rbmino;	/* bitmap inode for realtime extents */
1978c2ecf20Sopenharmony_ci	__be64		sb_rsumino;	/* summary inode for rt bitmap */
1988c2ecf20Sopenharmony_ci	__be32		sb_rextsize;	/* realtime extent size, blocks */
1998c2ecf20Sopenharmony_ci	__be32		sb_agblocks;	/* size of an allocation group */
2008c2ecf20Sopenharmony_ci	__be32		sb_agcount;	/* number of allocation groups */
2018c2ecf20Sopenharmony_ci	__be32		sb_rbmblocks;	/* number of rt bitmap blocks */
2028c2ecf20Sopenharmony_ci	__be32		sb_logblocks;	/* number of log blocks */
2038c2ecf20Sopenharmony_ci	__be16		sb_versionnum;	/* header version == XFS_SB_VERSION */
2048c2ecf20Sopenharmony_ci	__be16		sb_sectsize;	/* volume sector size, bytes */
2058c2ecf20Sopenharmony_ci	__be16		sb_inodesize;	/* inode size, bytes */
2068c2ecf20Sopenharmony_ci	__be16		sb_inopblock;	/* inodes per block */
2078c2ecf20Sopenharmony_ci	char		sb_fname[XFSLABEL_MAX]; /* file system name */
2088c2ecf20Sopenharmony_ci	__u8		sb_blocklog;	/* log2 of sb_blocksize */
2098c2ecf20Sopenharmony_ci	__u8		sb_sectlog;	/* log2 of sb_sectsize */
2108c2ecf20Sopenharmony_ci	__u8		sb_inodelog;	/* log2 of sb_inodesize */
2118c2ecf20Sopenharmony_ci	__u8		sb_inopblog;	/* log2 of sb_inopblock */
2128c2ecf20Sopenharmony_ci	__u8		sb_agblklog;	/* log2 of sb_agblocks (rounded up) */
2138c2ecf20Sopenharmony_ci	__u8		sb_rextslog;	/* log2 of sb_rextents */
2148c2ecf20Sopenharmony_ci	__u8		sb_inprogress;	/* mkfs is in progress, don't mount */
2158c2ecf20Sopenharmony_ci	__u8		sb_imax_pct;	/* max % of fs for inode space */
2168c2ecf20Sopenharmony_ci					/* statistics */
2178c2ecf20Sopenharmony_ci	/*
2188c2ecf20Sopenharmony_ci	 * These fields must remain contiguous.  If you really
2198c2ecf20Sopenharmony_ci	 * want to change their layout, make sure you fix the
2208c2ecf20Sopenharmony_ci	 * code in xfs_trans_apply_sb_deltas().
2218c2ecf20Sopenharmony_ci	 */
2228c2ecf20Sopenharmony_ci	__be64		sb_icount;	/* allocated inodes */
2238c2ecf20Sopenharmony_ci	__be64		sb_ifree;	/* free inodes */
2248c2ecf20Sopenharmony_ci	__be64		sb_fdblocks;	/* free data blocks */
2258c2ecf20Sopenharmony_ci	__be64		sb_frextents;	/* free realtime extents */
2268c2ecf20Sopenharmony_ci	/*
2278c2ecf20Sopenharmony_ci	 * End contiguous fields.
2288c2ecf20Sopenharmony_ci	 */
2298c2ecf20Sopenharmony_ci	__be64		sb_uquotino;	/* user quota inode */
2308c2ecf20Sopenharmony_ci	__be64		sb_gquotino;	/* group quota inode */
2318c2ecf20Sopenharmony_ci	__be16		sb_qflags;	/* quota flags */
2328c2ecf20Sopenharmony_ci	__u8		sb_flags;	/* misc. flags */
2338c2ecf20Sopenharmony_ci	__u8		sb_shared_vn;	/* shared version number */
2348c2ecf20Sopenharmony_ci	__be32		sb_inoalignmt;	/* inode chunk alignment, fsblocks */
2358c2ecf20Sopenharmony_ci	__be32		sb_unit;	/* stripe or raid unit */
2368c2ecf20Sopenharmony_ci	__be32		sb_width;	/* stripe or raid width */
2378c2ecf20Sopenharmony_ci	__u8		sb_dirblklog;	/* log2 of dir block size (fsbs) */
2388c2ecf20Sopenharmony_ci	__u8		sb_logsectlog;	/* log2 of the log sector size */
2398c2ecf20Sopenharmony_ci	__be16		sb_logsectsize;	/* sector size for the log, bytes */
2408c2ecf20Sopenharmony_ci	__be32		sb_logsunit;	/* stripe unit size for the log */
2418c2ecf20Sopenharmony_ci	__be32		sb_features2;	/* additional feature bits */
2428c2ecf20Sopenharmony_ci	/*
2438c2ecf20Sopenharmony_ci	 * bad features2 field as a result of failing to pad the sb
2448c2ecf20Sopenharmony_ci	 * structure to 64 bits. Some machines will be using this field
2458c2ecf20Sopenharmony_ci	 * for features2 bits. Easiest just to mark it bad and not use
2468c2ecf20Sopenharmony_ci	 * it for anything else.
2478c2ecf20Sopenharmony_ci	 */
2488c2ecf20Sopenharmony_ci	__be32		sb_bad_features2;
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	/* version 5 superblock fields start here */
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	/* feature masks */
2538c2ecf20Sopenharmony_ci	__be32		sb_features_compat;
2548c2ecf20Sopenharmony_ci	__be32		sb_features_ro_compat;
2558c2ecf20Sopenharmony_ci	__be32		sb_features_incompat;
2568c2ecf20Sopenharmony_ci	__be32		sb_features_log_incompat;
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	__le32		sb_crc;		/* superblock crc */
2598c2ecf20Sopenharmony_ci	__be32		sb_spino_align;	/* sparse inode chunk alignment */
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	__be64		sb_pquotino;	/* project quota inode */
2628c2ecf20Sopenharmony_ci	__be64		sb_lsn;		/* last write sequence */
2638c2ecf20Sopenharmony_ci	uuid_t		sb_meta_uuid;	/* metadata file system unique id */
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/* must be padded to 64 bit alignment */
2668c2ecf20Sopenharmony_ci} xfs_dsb_t;
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/*
2708c2ecf20Sopenharmony_ci * Misc. Flags - warning - these will be cleared by xfs_repair unless
2718c2ecf20Sopenharmony_ci * a feature bit is set when the flag is used.
2728c2ecf20Sopenharmony_ci */
2738c2ecf20Sopenharmony_ci#define XFS_SBF_NOFLAGS		0x00	/* no flags set */
2748c2ecf20Sopenharmony_ci#define XFS_SBF_READONLY	0x01	/* only read-only mounts allowed */
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/*
2778c2ecf20Sopenharmony_ci * define max. shared version we can interoperate with
2788c2ecf20Sopenharmony_ci */
2798c2ecf20Sopenharmony_ci#define XFS_SB_MAX_SHARED_VN	0
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci#define	XFS_SB_VERSION_NUM(sbp)	((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci/*
2848c2ecf20Sopenharmony_ci * The first XFS version we support is a v4 superblock with V2 directories.
2858c2ecf20Sopenharmony_ci */
2868c2ecf20Sopenharmony_cistatic inline bool xfs_sb_good_v4_features(struct xfs_sb *sbp)
2878c2ecf20Sopenharmony_ci{
2888c2ecf20Sopenharmony_ci	if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
2898c2ecf20Sopenharmony_ci		return false;
2908c2ecf20Sopenharmony_ci	if (!(sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT))
2918c2ecf20Sopenharmony_ci		return false;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	/* check for unknown features in the fs */
2948c2ecf20Sopenharmony_ci	if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
2958c2ecf20Sopenharmony_ci	    ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
2968c2ecf20Sopenharmony_ci	     (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
2978c2ecf20Sopenharmony_ci		return false;
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	return true;
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistatic inline bool xfs_sb_good_version(struct xfs_sb *sbp)
3038c2ecf20Sopenharmony_ci{
3048c2ecf20Sopenharmony_ci	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
3058c2ecf20Sopenharmony_ci		return true;
3068c2ecf20Sopenharmony_ci	if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
3078c2ecf20Sopenharmony_ci		return xfs_sb_good_v4_features(sbp);
3088c2ecf20Sopenharmony_ci	return false;
3098c2ecf20Sopenharmony_ci}
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasrealtime(struct xfs_sb *sbp)
3128c2ecf20Sopenharmony_ci{
3138c2ecf20Sopenharmony_ci	return sbp->sb_rblocks > 0;
3148c2ecf20Sopenharmony_ci}
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci/*
3178c2ecf20Sopenharmony_ci * Detect a mismatched features2 field.  Older kernels read/wrote
3188c2ecf20Sopenharmony_ci * this into the wrong slot, so to be safe we keep them in sync.
3198c2ecf20Sopenharmony_ci */
3208c2ecf20Sopenharmony_cistatic inline bool xfs_sb_has_mismatched_features2(struct xfs_sb *sbp)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	return sbp->sb_bad_features2 != sbp->sb_features2;
3238c2ecf20Sopenharmony_ci}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasattr(struct xfs_sb *sbp)
3268c2ecf20Sopenharmony_ci{
3278c2ecf20Sopenharmony_ci	return (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT);
3288c2ecf20Sopenharmony_ci}
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cistatic inline void xfs_sb_version_addattr(struct xfs_sb *sbp)
3318c2ecf20Sopenharmony_ci{
3328c2ecf20Sopenharmony_ci	sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
3338c2ecf20Sopenharmony_ci}
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasquota(struct xfs_sb *sbp)
3368c2ecf20Sopenharmony_ci{
3378c2ecf20Sopenharmony_ci	return (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_cistatic inline void xfs_sb_version_addquota(struct xfs_sb *sbp)
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
3438c2ecf20Sopenharmony_ci}
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasalign(struct xfs_sb *sbp)
3468c2ecf20Sopenharmony_ci{
3478c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
3488c2ecf20Sopenharmony_ci		(sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT));
3498c2ecf20Sopenharmony_ci}
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasdalign(struct xfs_sb *sbp)
3528c2ecf20Sopenharmony_ci{
3538c2ecf20Sopenharmony_ci	return (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
3548c2ecf20Sopenharmony_ci}
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_haslogv2(struct xfs_sb *sbp)
3578c2ecf20Sopenharmony_ci{
3588c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
3598c2ecf20Sopenharmony_ci	       (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
3608c2ecf20Sopenharmony_ci}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hassector(struct xfs_sb *sbp)
3638c2ecf20Sopenharmony_ci{
3648c2ecf20Sopenharmony_ci	return (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
3658c2ecf20Sopenharmony_ci}
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasasciici(struct xfs_sb *sbp)
3688c2ecf20Sopenharmony_ci{
3698c2ecf20Sopenharmony_ci	return (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
3708c2ecf20Sopenharmony_ci}
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasmorebits(struct xfs_sb *sbp)
3738c2ecf20Sopenharmony_ci{
3748c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
3758c2ecf20Sopenharmony_ci	       (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
3768c2ecf20Sopenharmony_ci}
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci/*
3798c2ecf20Sopenharmony_ci * sb_features2 bit version macros.
3808c2ecf20Sopenharmony_ci */
3818c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_haslazysbcount(struct xfs_sb *sbp)
3828c2ecf20Sopenharmony_ci{
3838c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
3848c2ecf20Sopenharmony_ci	       (xfs_sb_version_hasmorebits(sbp) &&
3858c2ecf20Sopenharmony_ci		(sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
3868c2ecf20Sopenharmony_ci}
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasattr2(struct xfs_sb *sbp)
3898c2ecf20Sopenharmony_ci{
3908c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
3918c2ecf20Sopenharmony_ci	       (xfs_sb_version_hasmorebits(sbp) &&
3928c2ecf20Sopenharmony_ci		(sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT));
3938c2ecf20Sopenharmony_ci}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_cistatic inline void xfs_sb_version_addattr2(struct xfs_sb *sbp)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
3988c2ecf20Sopenharmony_ci	sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
3998c2ecf20Sopenharmony_ci}
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_cistatic inline void xfs_sb_version_removeattr2(struct xfs_sb *sbp)
4028c2ecf20Sopenharmony_ci{
4038c2ecf20Sopenharmony_ci	sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
4048c2ecf20Sopenharmony_ci	if (!sbp->sb_features2)
4058c2ecf20Sopenharmony_ci		sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasprojid32bit(struct xfs_sb *sbp)
4098c2ecf20Sopenharmony_ci{
4108c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
4118c2ecf20Sopenharmony_ci	       (xfs_sb_version_hasmorebits(sbp) &&
4128c2ecf20Sopenharmony_ci		(sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT));
4138c2ecf20Sopenharmony_ci}
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_cistatic inline void xfs_sb_version_addprojid32bit(struct xfs_sb *sbp)
4168c2ecf20Sopenharmony_ci{
4178c2ecf20Sopenharmony_ci	sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
4188c2ecf20Sopenharmony_ci	sbp->sb_features2 |= XFS_SB_VERSION2_PROJID32BIT;
4198c2ecf20Sopenharmony_ci}
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci/*
4228c2ecf20Sopenharmony_ci * Extended v5 superblock feature masks. These are to be used for new v5
4238c2ecf20Sopenharmony_ci * superblock features only.
4248c2ecf20Sopenharmony_ci *
4258c2ecf20Sopenharmony_ci * Compat features are new features that old kernels will not notice or affect
4268c2ecf20Sopenharmony_ci * and so can mount read-write without issues.
4278c2ecf20Sopenharmony_ci *
4288c2ecf20Sopenharmony_ci * RO-Compat (read only) are features that old kernels can read but will break
4298c2ecf20Sopenharmony_ci * if they write. Hence only read-only mounts of such filesystems are allowed on
4308c2ecf20Sopenharmony_ci * kernels that don't support the feature bit.
4318c2ecf20Sopenharmony_ci *
4328c2ecf20Sopenharmony_ci * InCompat features are features which old kernels will not understand and so
4338c2ecf20Sopenharmony_ci * must not mount.
4348c2ecf20Sopenharmony_ci *
4358c2ecf20Sopenharmony_ci * Log-InCompat features are for changes to log formats or new transactions that
4368c2ecf20Sopenharmony_ci * can't be replayed on older kernels. The fields are set when the filesystem is
4378c2ecf20Sopenharmony_ci * mounted, and a clean unmount clears the fields.
4388c2ecf20Sopenharmony_ci */
4398c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_COMPAT_ALL 0
4408c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_COMPAT_UNKNOWN	~XFS_SB_FEAT_COMPAT_ALL
4418c2ecf20Sopenharmony_cistatic inline bool
4428c2ecf20Sopenharmony_cixfs_sb_has_compat_feature(
4438c2ecf20Sopenharmony_ci	struct xfs_sb	*sbp,
4448c2ecf20Sopenharmony_ci	uint32_t	feature)
4458c2ecf20Sopenharmony_ci{
4468c2ecf20Sopenharmony_ci	return (sbp->sb_features_compat & feature) != 0;
4478c2ecf20Sopenharmony_ci}
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_RO_COMPAT_FINOBT   (1 << 0)		/* free inode btree */
4508c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 << 1)		/* reverse map btree */
4518c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 << 2)		/* reflinked files */
4528c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)		/* inobt block counts */
4538c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_RO_COMPAT_ALL \
4548c2ecf20Sopenharmony_ci		(XFS_SB_FEAT_RO_COMPAT_FINOBT | \
4558c2ecf20Sopenharmony_ci		 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
4568c2ecf20Sopenharmony_ci		 XFS_SB_FEAT_RO_COMPAT_REFLINK| \
4578c2ecf20Sopenharmony_ci		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
4588c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN	~XFS_SB_FEAT_RO_COMPAT_ALL
4598c2ecf20Sopenharmony_cistatic inline bool
4608c2ecf20Sopenharmony_cixfs_sb_has_ro_compat_feature(
4618c2ecf20Sopenharmony_ci	struct xfs_sb	*sbp,
4628c2ecf20Sopenharmony_ci	uint32_t	feature)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	return (sbp->sb_features_ro_compat & feature) != 0;
4658c2ecf20Sopenharmony_ci}
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_FTYPE	(1 << 0)	/* filetype in dirent */
4688c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_SPINODES	(1 << 1)	/* sparse inode chunks */
4698c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_META_UUID	(1 << 2)	/* metadata UUID */
4708c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_BIGTIME	(1 << 3)	/* large timestamps */
4718c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_ALL \
4728c2ecf20Sopenharmony_ci		(XFS_SB_FEAT_INCOMPAT_FTYPE|	\
4738c2ecf20Sopenharmony_ci		 XFS_SB_FEAT_INCOMPAT_SPINODES|	\
4748c2ecf20Sopenharmony_ci		 XFS_SB_FEAT_INCOMPAT_META_UUID| \
4758c2ecf20Sopenharmony_ci		 XFS_SB_FEAT_INCOMPAT_BIGTIME)
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_UNKNOWN	~XFS_SB_FEAT_INCOMPAT_ALL
4788c2ecf20Sopenharmony_cistatic inline bool
4798c2ecf20Sopenharmony_cixfs_sb_has_incompat_feature(
4808c2ecf20Sopenharmony_ci	struct xfs_sb	*sbp,
4818c2ecf20Sopenharmony_ci	uint32_t	feature)
4828c2ecf20Sopenharmony_ci{
4838c2ecf20Sopenharmony_ci	return (sbp->sb_features_incompat & feature) != 0;
4848c2ecf20Sopenharmony_ci}
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0
4878c2ecf20Sopenharmony_ci#define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN	~XFS_SB_FEAT_INCOMPAT_LOG_ALL
4888c2ecf20Sopenharmony_cistatic inline bool
4898c2ecf20Sopenharmony_cixfs_sb_has_incompat_log_feature(
4908c2ecf20Sopenharmony_ci	struct xfs_sb	*sbp,
4918c2ecf20Sopenharmony_ci	uint32_t	feature)
4928c2ecf20Sopenharmony_ci{
4938c2ecf20Sopenharmony_ci	return (sbp->sb_features_log_incompat & feature) != 0;
4948c2ecf20Sopenharmony_ci}
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci/*
4978c2ecf20Sopenharmony_ci * V5 superblock specific feature checks
4988c2ecf20Sopenharmony_ci */
4998c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hascrc(struct xfs_sb *sbp)
5008c2ecf20Sopenharmony_ci{
5018c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
5028c2ecf20Sopenharmony_ci}
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci/*
5058c2ecf20Sopenharmony_ci * v5 file systems support V3 inodes only, earlier file systems support
5068c2ecf20Sopenharmony_ci * v2 and v1 inodes.
5078c2ecf20Sopenharmony_ci */
5088c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_has_v3inode(struct xfs_sb *sbp)
5098c2ecf20Sopenharmony_ci{
5108c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
5118c2ecf20Sopenharmony_ci}
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_cistatic inline bool xfs_dinode_good_version(struct xfs_sb *sbp,
5148c2ecf20Sopenharmony_ci		uint8_t version)
5158c2ecf20Sopenharmony_ci{
5168c2ecf20Sopenharmony_ci	if (xfs_sb_version_has_v3inode(sbp))
5178c2ecf20Sopenharmony_ci		return version == 3;
5188c2ecf20Sopenharmony_ci	return version == 1 || version == 2;
5198c2ecf20Sopenharmony_ci}
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_has_pquotino(struct xfs_sb *sbp)
5228c2ecf20Sopenharmony_ci{
5238c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
5248c2ecf20Sopenharmony_ci}
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_cistatic inline int xfs_sb_version_hasftype(struct xfs_sb *sbp)
5278c2ecf20Sopenharmony_ci{
5288c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
5298c2ecf20Sopenharmony_ci		xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_FTYPE)) ||
5308c2ecf20Sopenharmony_ci	       (xfs_sb_version_hasmorebits(sbp) &&
5318c2ecf20Sopenharmony_ci		 (sbp->sb_features2 & XFS_SB_VERSION2_FTYPE));
5328c2ecf20Sopenharmony_ci}
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasfinobt(xfs_sb_t *sbp)
5358c2ecf20Sopenharmony_ci{
5368c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&
5378c2ecf20Sopenharmony_ci		(sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_FINOBT);
5388c2ecf20Sopenharmony_ci}
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hassparseinodes(struct xfs_sb *sbp)
5418c2ecf20Sopenharmony_ci{
5428c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
5438c2ecf20Sopenharmony_ci		xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_SPINODES);
5448c2ecf20Sopenharmony_ci}
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci/*
5478c2ecf20Sopenharmony_ci * XFS_SB_FEAT_INCOMPAT_META_UUID indicates that the metadata UUID
5488c2ecf20Sopenharmony_ci * is stored separately from the user-visible UUID; this allows the
5498c2ecf20Sopenharmony_ci * user-visible UUID to be changed on V5 filesystems which have a
5508c2ecf20Sopenharmony_ci * filesystem UUID stamped into every piece of metadata.
5518c2ecf20Sopenharmony_ci */
5528c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp)
5538c2ecf20Sopenharmony_ci{
5548c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&
5558c2ecf20Sopenharmony_ci		(sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID);
5568c2ecf20Sopenharmony_ci}
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasrmapbt(struct xfs_sb *sbp)
5598c2ecf20Sopenharmony_ci{
5608c2ecf20Sopenharmony_ci	return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&
5618c2ecf20Sopenharmony_ci		(sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_RMAPBT);
5628c2ecf20Sopenharmony_ci}
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasreflink(struct xfs_sb *sbp)
5658c2ecf20Sopenharmony_ci{
5668c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
5678c2ecf20Sopenharmony_ci		(sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_REFLINK);
5688c2ecf20Sopenharmony_ci}
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasbigtime(struct xfs_sb *sbp)
5718c2ecf20Sopenharmony_ci{
5728c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
5738c2ecf20Sopenharmony_ci		(sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_BIGTIME);
5748c2ecf20Sopenharmony_ci}
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci/*
5778c2ecf20Sopenharmony_ci * Inode btree block counter.  We record the number of inobt and finobt blocks
5788c2ecf20Sopenharmony_ci * in the AGI header so that we can skip the finobt walk at mount time when
5798c2ecf20Sopenharmony_ci * setting up per-AG reservations.
5808c2ecf20Sopenharmony_ci */
5818c2ecf20Sopenharmony_cistatic inline bool xfs_sb_version_hasinobtcounts(struct xfs_sb *sbp)
5828c2ecf20Sopenharmony_ci{
5838c2ecf20Sopenharmony_ci	return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
5848c2ecf20Sopenharmony_ci		(sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT);
5858c2ecf20Sopenharmony_ci}
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci/*
5888c2ecf20Sopenharmony_ci * end of superblock version macros
5898c2ecf20Sopenharmony_ci */
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_cistatic inline bool
5928c2ecf20Sopenharmony_cixfs_is_quota_inode(struct xfs_sb *sbp, xfs_ino_t ino)
5938c2ecf20Sopenharmony_ci{
5948c2ecf20Sopenharmony_ci	return (ino == sbp->sb_uquotino ||
5958c2ecf20Sopenharmony_ci		ino == sbp->sb_gquotino ||
5968c2ecf20Sopenharmony_ci		ino == sbp->sb_pquotino);
5978c2ecf20Sopenharmony_ci}
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci#define XFS_SB_DADDR		((xfs_daddr_t)0) /* daddr in filesystem/ag */
6008c2ecf20Sopenharmony_ci#define	XFS_SB_BLOCK(mp)	XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci#define	XFS_HDR_BLOCK(mp,d)	((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
6038c2ecf20Sopenharmony_ci#define	XFS_DADDR_TO_FSB(mp,d)	XFS_AGB_TO_FSB(mp, \
6048c2ecf20Sopenharmony_ci			xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
6058c2ecf20Sopenharmony_ci#define	XFS_FSB_TO_DADDR(mp,fsbno)	XFS_AGB_TO_DADDR(mp, \
6068c2ecf20Sopenharmony_ci			XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci/*
6098c2ecf20Sopenharmony_ci * File system sector to basic block conversions.
6108c2ecf20Sopenharmony_ci */
6118c2ecf20Sopenharmony_ci#define XFS_FSS_TO_BB(mp,sec)	((sec) << (mp)->m_sectbb_log)
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci/*
6148c2ecf20Sopenharmony_ci * File system block to basic block conversions.
6158c2ecf20Sopenharmony_ci */
6168c2ecf20Sopenharmony_ci#define	XFS_FSB_TO_BB(mp,fsbno)	((fsbno) << (mp)->m_blkbb_log)
6178c2ecf20Sopenharmony_ci#define	XFS_BB_TO_FSB(mp,bb)	\
6188c2ecf20Sopenharmony_ci	(((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
6198c2ecf20Sopenharmony_ci#define	XFS_BB_TO_FSBT(mp,bb)	((bb) >> (mp)->m_blkbb_log)
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci/*
6228c2ecf20Sopenharmony_ci * File system block to byte conversions.
6238c2ecf20Sopenharmony_ci */
6248c2ecf20Sopenharmony_ci#define XFS_FSB_TO_B(mp,fsbno)	((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
6258c2ecf20Sopenharmony_ci#define XFS_B_TO_FSB(mp,b)	\
6268c2ecf20Sopenharmony_ci	((((uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
6278c2ecf20Sopenharmony_ci#define XFS_B_TO_FSBT(mp,b)	(((uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
6288c2ecf20Sopenharmony_ci#define XFS_B_FSB_OFFSET(mp,b)	((b) & (mp)->m_blockmask)
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci/*
6318c2ecf20Sopenharmony_ci * Allocation group header
6328c2ecf20Sopenharmony_ci *
6338c2ecf20Sopenharmony_ci * This is divided into three structures, placed in sequential 512-byte
6348c2ecf20Sopenharmony_ci * buffers after a copy of the superblock (also in a 512-byte buffer).
6358c2ecf20Sopenharmony_ci */
6368c2ecf20Sopenharmony_ci#define	XFS_AGF_MAGIC	0x58414746	/* 'XAGF' */
6378c2ecf20Sopenharmony_ci#define	XFS_AGI_MAGIC	0x58414749	/* 'XAGI' */
6388c2ecf20Sopenharmony_ci#define	XFS_AGFL_MAGIC	0x5841464c	/* 'XAFL' */
6398c2ecf20Sopenharmony_ci#define	XFS_AGF_VERSION	1
6408c2ecf20Sopenharmony_ci#define	XFS_AGI_VERSION	1
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci#define	XFS_AGF_GOOD_VERSION(v)	((v) == XFS_AGF_VERSION)
6438c2ecf20Sopenharmony_ci#define	XFS_AGI_GOOD_VERSION(v)	((v) == XFS_AGI_VERSION)
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci/*
6468c2ecf20Sopenharmony_ci * Btree number 0 is bno, 1 is cnt, 2 is rmap. This value gives the size of the
6478c2ecf20Sopenharmony_ci * arrays below.
6488c2ecf20Sopenharmony_ci */
6498c2ecf20Sopenharmony_ci#define	XFS_BTNUM_AGF	((int)XFS_BTNUM_RMAPi + 1)
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ci/*
6528c2ecf20Sopenharmony_ci * The second word of agf_levels in the first a.g. overlaps the EFS
6538c2ecf20Sopenharmony_ci * superblock's magic number.  Since the magic numbers valid for EFS
6548c2ecf20Sopenharmony_ci * are > 64k, our value cannot be confused for an EFS superblock's.
6558c2ecf20Sopenharmony_ci */
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_citypedef struct xfs_agf {
6588c2ecf20Sopenharmony_ci	/*
6598c2ecf20Sopenharmony_ci	 * Common allocation group header information
6608c2ecf20Sopenharmony_ci	 */
6618c2ecf20Sopenharmony_ci	__be32		agf_magicnum;	/* magic number == XFS_AGF_MAGIC */
6628c2ecf20Sopenharmony_ci	__be32		agf_versionnum;	/* header version == XFS_AGF_VERSION */
6638c2ecf20Sopenharmony_ci	__be32		agf_seqno;	/* sequence # starting from 0 */
6648c2ecf20Sopenharmony_ci	__be32		agf_length;	/* size in blocks of a.g. */
6658c2ecf20Sopenharmony_ci	/*
6668c2ecf20Sopenharmony_ci	 * Freespace and rmap information
6678c2ecf20Sopenharmony_ci	 */
6688c2ecf20Sopenharmony_ci	__be32		agf_roots[XFS_BTNUM_AGF];	/* root blocks */
6698c2ecf20Sopenharmony_ci	__be32		agf_levels[XFS_BTNUM_AGF];	/* btree levels */
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci	__be32		agf_flfirst;	/* first freelist block's index */
6728c2ecf20Sopenharmony_ci	__be32		agf_fllast;	/* last freelist block's index */
6738c2ecf20Sopenharmony_ci	__be32		agf_flcount;	/* count of blocks in freelist */
6748c2ecf20Sopenharmony_ci	__be32		agf_freeblks;	/* total free blocks */
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	__be32		agf_longest;	/* longest free space */
6778c2ecf20Sopenharmony_ci	__be32		agf_btreeblks;	/* # of blocks held in AGF btrees */
6788c2ecf20Sopenharmony_ci	uuid_t		agf_uuid;	/* uuid of filesystem */
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	__be32		agf_rmap_blocks;	/* rmapbt blocks used */
6818c2ecf20Sopenharmony_ci	__be32		agf_refcount_blocks;	/* refcountbt blocks used */
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	__be32		agf_refcount_root;	/* refcount tree root block */
6848c2ecf20Sopenharmony_ci	__be32		agf_refcount_level;	/* refcount btree levels */
6858c2ecf20Sopenharmony_ci
6868c2ecf20Sopenharmony_ci	/*
6878c2ecf20Sopenharmony_ci	 * reserve some contiguous space for future logged fields before we add
6888c2ecf20Sopenharmony_ci	 * the unlogged fields. This makes the range logging via flags and
6898c2ecf20Sopenharmony_ci	 * structure offsets much simpler.
6908c2ecf20Sopenharmony_ci	 */
6918c2ecf20Sopenharmony_ci	__be64		agf_spare64[14];
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_ci	/* unlogged fields, written during buffer writeback. */
6948c2ecf20Sopenharmony_ci	__be64		agf_lsn;	/* last write sequence */
6958c2ecf20Sopenharmony_ci	__be32		agf_crc;	/* crc of agf sector */
6968c2ecf20Sopenharmony_ci	__be32		agf_spare2;
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci	/* structure must be padded to 64 bit alignment */
6998c2ecf20Sopenharmony_ci} xfs_agf_t;
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci#define XFS_AGF_CRC_OFF		offsetof(struct xfs_agf, agf_crc)
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci#define	XFS_AGF_MAGICNUM	0x00000001
7048c2ecf20Sopenharmony_ci#define	XFS_AGF_VERSIONNUM	0x00000002
7058c2ecf20Sopenharmony_ci#define	XFS_AGF_SEQNO		0x00000004
7068c2ecf20Sopenharmony_ci#define	XFS_AGF_LENGTH		0x00000008
7078c2ecf20Sopenharmony_ci#define	XFS_AGF_ROOTS		0x00000010
7088c2ecf20Sopenharmony_ci#define	XFS_AGF_LEVELS		0x00000020
7098c2ecf20Sopenharmony_ci#define	XFS_AGF_FLFIRST		0x00000040
7108c2ecf20Sopenharmony_ci#define	XFS_AGF_FLLAST		0x00000080
7118c2ecf20Sopenharmony_ci#define	XFS_AGF_FLCOUNT		0x00000100
7128c2ecf20Sopenharmony_ci#define	XFS_AGF_FREEBLKS	0x00000200
7138c2ecf20Sopenharmony_ci#define	XFS_AGF_LONGEST		0x00000400
7148c2ecf20Sopenharmony_ci#define	XFS_AGF_BTREEBLKS	0x00000800
7158c2ecf20Sopenharmony_ci#define	XFS_AGF_UUID		0x00001000
7168c2ecf20Sopenharmony_ci#define	XFS_AGF_RMAP_BLOCKS	0x00002000
7178c2ecf20Sopenharmony_ci#define	XFS_AGF_REFCOUNT_BLOCKS	0x00004000
7188c2ecf20Sopenharmony_ci#define	XFS_AGF_REFCOUNT_ROOT	0x00008000
7198c2ecf20Sopenharmony_ci#define	XFS_AGF_REFCOUNT_LEVEL	0x00010000
7208c2ecf20Sopenharmony_ci#define	XFS_AGF_SPARE64		0x00020000
7218c2ecf20Sopenharmony_ci#define	XFS_AGF_NUM_BITS	18
7228c2ecf20Sopenharmony_ci#define	XFS_AGF_ALL_BITS	((1 << XFS_AGF_NUM_BITS) - 1)
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci#define XFS_AGF_FLAGS \
7258c2ecf20Sopenharmony_ci	{ XFS_AGF_MAGICNUM,	"MAGICNUM" }, \
7268c2ecf20Sopenharmony_ci	{ XFS_AGF_VERSIONNUM,	"VERSIONNUM" }, \
7278c2ecf20Sopenharmony_ci	{ XFS_AGF_SEQNO,	"SEQNO" }, \
7288c2ecf20Sopenharmony_ci	{ XFS_AGF_LENGTH,	"LENGTH" }, \
7298c2ecf20Sopenharmony_ci	{ XFS_AGF_ROOTS,	"ROOTS" }, \
7308c2ecf20Sopenharmony_ci	{ XFS_AGF_LEVELS,	"LEVELS" }, \
7318c2ecf20Sopenharmony_ci	{ XFS_AGF_FLFIRST,	"FLFIRST" }, \
7328c2ecf20Sopenharmony_ci	{ XFS_AGF_FLLAST,	"FLLAST" }, \
7338c2ecf20Sopenharmony_ci	{ XFS_AGF_FLCOUNT,	"FLCOUNT" }, \
7348c2ecf20Sopenharmony_ci	{ XFS_AGF_FREEBLKS,	"FREEBLKS" }, \
7358c2ecf20Sopenharmony_ci	{ XFS_AGF_LONGEST,	"LONGEST" }, \
7368c2ecf20Sopenharmony_ci	{ XFS_AGF_BTREEBLKS,	"BTREEBLKS" }, \
7378c2ecf20Sopenharmony_ci	{ XFS_AGF_UUID,		"UUID" }, \
7388c2ecf20Sopenharmony_ci	{ XFS_AGF_RMAP_BLOCKS,	"RMAP_BLOCKS" }, \
7398c2ecf20Sopenharmony_ci	{ XFS_AGF_REFCOUNT_BLOCKS,	"REFCOUNT_BLOCKS" }, \
7408c2ecf20Sopenharmony_ci	{ XFS_AGF_REFCOUNT_ROOT,	"REFCOUNT_ROOT" }, \
7418c2ecf20Sopenharmony_ci	{ XFS_AGF_REFCOUNT_LEVEL,	"REFCOUNT_LEVEL" }, \
7428c2ecf20Sopenharmony_ci	{ XFS_AGF_SPARE64,	"SPARE64" }
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci/* disk block (xfs_daddr_t) in the AG */
7458c2ecf20Sopenharmony_ci#define XFS_AGF_DADDR(mp)	((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
7468c2ecf20Sopenharmony_ci#define	XFS_AGF_BLOCK(mp)	XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci/*
7498c2ecf20Sopenharmony_ci * Size of the unlinked inode hash table in the agi.
7508c2ecf20Sopenharmony_ci */
7518c2ecf20Sopenharmony_ci#define	XFS_AGI_UNLINKED_BUCKETS	64
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_citypedef struct xfs_agi {
7548c2ecf20Sopenharmony_ci	/*
7558c2ecf20Sopenharmony_ci	 * Common allocation group header information
7568c2ecf20Sopenharmony_ci	 */
7578c2ecf20Sopenharmony_ci	__be32		agi_magicnum;	/* magic number == XFS_AGI_MAGIC */
7588c2ecf20Sopenharmony_ci	__be32		agi_versionnum;	/* header version == XFS_AGI_VERSION */
7598c2ecf20Sopenharmony_ci	__be32		agi_seqno;	/* sequence # starting from 0 */
7608c2ecf20Sopenharmony_ci	__be32		agi_length;	/* size in blocks of a.g. */
7618c2ecf20Sopenharmony_ci	/*
7628c2ecf20Sopenharmony_ci	 * Inode information
7638c2ecf20Sopenharmony_ci	 * Inodes are mapped by interpreting the inode number, so no
7648c2ecf20Sopenharmony_ci	 * mapping data is needed here.
7658c2ecf20Sopenharmony_ci	 */
7668c2ecf20Sopenharmony_ci	__be32		agi_count;	/* count of allocated inodes */
7678c2ecf20Sopenharmony_ci	__be32		agi_root;	/* root of inode btree */
7688c2ecf20Sopenharmony_ci	__be32		agi_level;	/* levels in inode btree */
7698c2ecf20Sopenharmony_ci	__be32		agi_freecount;	/* number of free inodes */
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_ci	__be32		agi_newino;	/* new inode just allocated */
7728c2ecf20Sopenharmony_ci	__be32		agi_dirino;	/* last directory inode chunk */
7738c2ecf20Sopenharmony_ci	/*
7748c2ecf20Sopenharmony_ci	 * Hash table of inodes which have been unlinked but are
7758c2ecf20Sopenharmony_ci	 * still being referenced.
7768c2ecf20Sopenharmony_ci	 */
7778c2ecf20Sopenharmony_ci	__be32		agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
7788c2ecf20Sopenharmony_ci	/*
7798c2ecf20Sopenharmony_ci	 * This marks the end of logging region 1 and start of logging region 2.
7808c2ecf20Sopenharmony_ci	 */
7818c2ecf20Sopenharmony_ci	uuid_t		agi_uuid;	/* uuid of filesystem */
7828c2ecf20Sopenharmony_ci	__be32		agi_crc;	/* crc of agi sector */
7838c2ecf20Sopenharmony_ci	__be32		agi_pad32;
7848c2ecf20Sopenharmony_ci	__be64		agi_lsn;	/* last write sequence */
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci	__be32		agi_free_root; /* root of the free inode btree */
7878c2ecf20Sopenharmony_ci	__be32		agi_free_level;/* levels in free inode btree */
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	__be32		agi_iblocks;	/* inobt blocks used */
7908c2ecf20Sopenharmony_ci	__be32		agi_fblocks;	/* finobt blocks used */
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci	/* structure must be padded to 64 bit alignment */
7938c2ecf20Sopenharmony_ci} xfs_agi_t;
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci#define XFS_AGI_CRC_OFF		offsetof(struct xfs_agi, agi_crc)
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci#define	XFS_AGI_MAGICNUM	(1 << 0)
7988c2ecf20Sopenharmony_ci#define	XFS_AGI_VERSIONNUM	(1 << 1)
7998c2ecf20Sopenharmony_ci#define	XFS_AGI_SEQNO		(1 << 2)
8008c2ecf20Sopenharmony_ci#define	XFS_AGI_LENGTH		(1 << 3)
8018c2ecf20Sopenharmony_ci#define	XFS_AGI_COUNT		(1 << 4)
8028c2ecf20Sopenharmony_ci#define	XFS_AGI_ROOT		(1 << 5)
8038c2ecf20Sopenharmony_ci#define	XFS_AGI_LEVEL		(1 << 6)
8048c2ecf20Sopenharmony_ci#define	XFS_AGI_FREECOUNT	(1 << 7)
8058c2ecf20Sopenharmony_ci#define	XFS_AGI_NEWINO		(1 << 8)
8068c2ecf20Sopenharmony_ci#define	XFS_AGI_DIRINO		(1 << 9)
8078c2ecf20Sopenharmony_ci#define	XFS_AGI_UNLINKED	(1 << 10)
8088c2ecf20Sopenharmony_ci#define	XFS_AGI_NUM_BITS_R1	11	/* end of the 1st agi logging region */
8098c2ecf20Sopenharmony_ci#define	XFS_AGI_ALL_BITS_R1	((1 << XFS_AGI_NUM_BITS_R1) - 1)
8108c2ecf20Sopenharmony_ci#define	XFS_AGI_FREE_ROOT	(1 << 11)
8118c2ecf20Sopenharmony_ci#define	XFS_AGI_FREE_LEVEL	(1 << 12)
8128c2ecf20Sopenharmony_ci#define	XFS_AGI_IBLOCKS		(1 << 13) /* both inobt/finobt block counters */
8138c2ecf20Sopenharmony_ci#define	XFS_AGI_NUM_BITS_R2	14
8148c2ecf20Sopenharmony_ci
8158c2ecf20Sopenharmony_ci/* disk block (xfs_daddr_t) in the AG */
8168c2ecf20Sopenharmony_ci#define XFS_AGI_DADDR(mp)	((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
8178c2ecf20Sopenharmony_ci#define	XFS_AGI_BLOCK(mp)	XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci/*
8208c2ecf20Sopenharmony_ci * The third a.g. block contains the a.g. freelist, an array
8218c2ecf20Sopenharmony_ci * of block pointers to blocks owned by the allocation btree code.
8228c2ecf20Sopenharmony_ci */
8238c2ecf20Sopenharmony_ci#define XFS_AGFL_DADDR(mp)	((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
8248c2ecf20Sopenharmony_ci#define	XFS_AGFL_BLOCK(mp)	XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
8258c2ecf20Sopenharmony_ci#define	XFS_BUF_TO_AGFL(bp)	((struct xfs_agfl *)((bp)->b_addr))
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_cistruct xfs_agfl {
8288c2ecf20Sopenharmony_ci	__be32		agfl_magicnum;
8298c2ecf20Sopenharmony_ci	__be32		agfl_seqno;
8308c2ecf20Sopenharmony_ci	uuid_t		agfl_uuid;
8318c2ecf20Sopenharmony_ci	__be64		agfl_lsn;
8328c2ecf20Sopenharmony_ci	__be32		agfl_crc;
8338c2ecf20Sopenharmony_ci} __attribute__((packed));
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_ci#define XFS_AGFL_CRC_OFF	offsetof(struct xfs_agfl, agfl_crc)
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci#define XFS_AGB_TO_FSB(mp,agno,agbno)	\
8388c2ecf20Sopenharmony_ci	(((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
8398c2ecf20Sopenharmony_ci#define	XFS_FSB_TO_AGNO(mp,fsbno)	\
8408c2ecf20Sopenharmony_ci	((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
8418c2ecf20Sopenharmony_ci#define	XFS_FSB_TO_AGBNO(mp,fsbno)	\
8428c2ecf20Sopenharmony_ci	((xfs_agblock_t)((fsbno) & xfs_mask32lo((mp)->m_sb.sb_agblklog)))
8438c2ecf20Sopenharmony_ci#define	XFS_AGB_TO_DADDR(mp,agno,agbno)	\
8448c2ecf20Sopenharmony_ci	((xfs_daddr_t)XFS_FSB_TO_BB(mp, \
8458c2ecf20Sopenharmony_ci		(xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno)))
8468c2ecf20Sopenharmony_ci#define	XFS_AG_DADDR(mp,agno,d)		(XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci/*
8498c2ecf20Sopenharmony_ci * For checking for bad ranges of xfs_daddr_t's, covering multiple
8508c2ecf20Sopenharmony_ci * allocation groups or a single xfs_daddr_t that's a superblock copy.
8518c2ecf20Sopenharmony_ci */
8528c2ecf20Sopenharmony_ci#define	XFS_AG_CHECK_DADDR(mp,d,len)	\
8538c2ecf20Sopenharmony_ci	((len) == 1 ? \
8548c2ecf20Sopenharmony_ci	    ASSERT((d) == XFS_SB_DADDR || \
8558c2ecf20Sopenharmony_ci		   xfs_daddr_to_agbno(mp, d) != XFS_SB_DADDR) : \
8568c2ecf20Sopenharmony_ci	    ASSERT(xfs_daddr_to_agno(mp, d) == \
8578c2ecf20Sopenharmony_ci		   xfs_daddr_to_agno(mp, (d) + (len) - 1)))
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ci/*
8608c2ecf20Sopenharmony_ci * XFS Timestamps
8618c2ecf20Sopenharmony_ci * ==============
8628c2ecf20Sopenharmony_ci *
8638c2ecf20Sopenharmony_ci * Traditional ondisk inode timestamps consist of signed 32-bit counters for
8648c2ecf20Sopenharmony_ci * seconds and nanoseconds; time zero is the Unix epoch, Jan  1 00:00:00 UTC
8658c2ecf20Sopenharmony_ci * 1970, which means that the timestamp epoch is the same as the Unix epoch.
8668c2ecf20Sopenharmony_ci * Therefore, the ondisk min and max defined here can be used directly to
8678c2ecf20Sopenharmony_ci * constrain the incore timestamps on a Unix system.  Note that we actually
8688c2ecf20Sopenharmony_ci * encode a __be64 value on disk.
8698c2ecf20Sopenharmony_ci *
8708c2ecf20Sopenharmony_ci * When the bigtime feature is enabled, ondisk inode timestamps become an
8718c2ecf20Sopenharmony_ci * unsigned 64-bit nanoseconds counter.  This means that the bigtime inode
8728c2ecf20Sopenharmony_ci * timestamp epoch is the start of the classic timestamp range, which is
8738c2ecf20Sopenharmony_ci * Dec 31 20:45:52 UTC 1901.  Because the epochs are not the same, callers
8748c2ecf20Sopenharmony_ci * /must/ use the bigtime conversion functions when encoding and decoding raw
8758c2ecf20Sopenharmony_ci * timestamps.
8768c2ecf20Sopenharmony_ci */
8778c2ecf20Sopenharmony_citypedef __be64 xfs_timestamp_t;
8788c2ecf20Sopenharmony_ci
8798c2ecf20Sopenharmony_ci/* Legacy timestamp encoding format. */
8808c2ecf20Sopenharmony_cistruct xfs_legacy_timestamp {
8818c2ecf20Sopenharmony_ci	__be32		t_sec;		/* timestamp seconds */
8828c2ecf20Sopenharmony_ci	__be32		t_nsec;		/* timestamp nanoseconds */
8838c2ecf20Sopenharmony_ci};
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ci/*
8868c2ecf20Sopenharmony_ci * Smallest possible ondisk seconds value with traditional timestamps.  This
8878c2ecf20Sopenharmony_ci * corresponds exactly with the incore timestamp Dec 13 20:45:52 UTC 1901.
8888c2ecf20Sopenharmony_ci */
8898c2ecf20Sopenharmony_ci#define XFS_LEGACY_TIME_MIN	((int64_t)S32_MIN)
8908c2ecf20Sopenharmony_ci
8918c2ecf20Sopenharmony_ci/*
8928c2ecf20Sopenharmony_ci * Largest possible ondisk seconds value with traditional timestamps.  This
8938c2ecf20Sopenharmony_ci * corresponds exactly with the incore timestamp Jan 19 03:14:07 UTC 2038.
8948c2ecf20Sopenharmony_ci */
8958c2ecf20Sopenharmony_ci#define XFS_LEGACY_TIME_MAX	((int64_t)S32_MAX)
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci/*
8988c2ecf20Sopenharmony_ci * Smallest possible ondisk seconds value with bigtime timestamps.  This
8998c2ecf20Sopenharmony_ci * corresponds (after conversion to a Unix timestamp) with the traditional
9008c2ecf20Sopenharmony_ci * minimum timestamp of Dec 13 20:45:52 UTC 1901.
9018c2ecf20Sopenharmony_ci */
9028c2ecf20Sopenharmony_ci#define XFS_BIGTIME_TIME_MIN	((int64_t)0)
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_ci/*
9058c2ecf20Sopenharmony_ci * Largest supported ondisk seconds value with bigtime timestamps.  This
9068c2ecf20Sopenharmony_ci * corresponds (after conversion to a Unix timestamp) with an incore timestamp
9078c2ecf20Sopenharmony_ci * of Jul  2 20:20:24 UTC 2486.
9088c2ecf20Sopenharmony_ci *
9098c2ecf20Sopenharmony_ci * We round down the ondisk limit so that the bigtime quota and inode max
9108c2ecf20Sopenharmony_ci * timestamps will be the same.
9118c2ecf20Sopenharmony_ci */
9128c2ecf20Sopenharmony_ci#define XFS_BIGTIME_TIME_MAX	((int64_t)((-1ULL / NSEC_PER_SEC) & ~0x3ULL))
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_ci/*
9158c2ecf20Sopenharmony_ci * Bigtime epoch is set exactly to the minimum time value that a traditional
9168c2ecf20Sopenharmony_ci * 32-bit timestamp can represent when using the Unix epoch as a reference.
9178c2ecf20Sopenharmony_ci * Hence the Unix epoch is at a fixed offset into the supported bigtime
9188c2ecf20Sopenharmony_ci * timestamp range.
9198c2ecf20Sopenharmony_ci *
9208c2ecf20Sopenharmony_ci * The bigtime epoch also matches the minimum value an on-disk 32-bit XFS
9218c2ecf20Sopenharmony_ci * timestamp can represent so we will not lose any fidelity in converting
9228c2ecf20Sopenharmony_ci * to/from unix and bigtime timestamps.
9238c2ecf20Sopenharmony_ci *
9248c2ecf20Sopenharmony_ci * The following conversion factor converts a seconds counter from the Unix
9258c2ecf20Sopenharmony_ci * epoch to the bigtime epoch.
9268c2ecf20Sopenharmony_ci */
9278c2ecf20Sopenharmony_ci#define XFS_BIGTIME_EPOCH_OFFSET	(-(int64_t)S32_MIN)
9288c2ecf20Sopenharmony_ci
9298c2ecf20Sopenharmony_ci/* Convert a timestamp from the Unix epoch to the bigtime epoch. */
9308c2ecf20Sopenharmony_cistatic inline uint64_t xfs_unix_to_bigtime(time64_t unix_seconds)
9318c2ecf20Sopenharmony_ci{
9328c2ecf20Sopenharmony_ci	return (uint64_t)unix_seconds + XFS_BIGTIME_EPOCH_OFFSET;
9338c2ecf20Sopenharmony_ci}
9348c2ecf20Sopenharmony_ci
9358c2ecf20Sopenharmony_ci/* Convert a timestamp from the bigtime epoch to the Unix epoch. */
9368c2ecf20Sopenharmony_cistatic inline time64_t xfs_bigtime_to_unix(uint64_t ondisk_seconds)
9378c2ecf20Sopenharmony_ci{
9388c2ecf20Sopenharmony_ci	return (time64_t)ondisk_seconds - XFS_BIGTIME_EPOCH_OFFSET;
9398c2ecf20Sopenharmony_ci}
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_ci/*
9428c2ecf20Sopenharmony_ci * On-disk inode structure.
9438c2ecf20Sopenharmony_ci *
9448c2ecf20Sopenharmony_ci * This is just the header or "dinode core", the inode is expanded to fill a
9458c2ecf20Sopenharmony_ci * variable size the leftover area split into a data and an attribute fork.
9468c2ecf20Sopenharmony_ci * The format of the data and attribute fork depends on the format of the
9478c2ecf20Sopenharmony_ci * inode as indicated by di_format and di_aformat.  To access the data and
9488c2ecf20Sopenharmony_ci * attribute use the XFS_DFORK_DPTR, XFS_DFORK_APTR, and XFS_DFORK_PTR macros
9498c2ecf20Sopenharmony_ci * below.
9508c2ecf20Sopenharmony_ci *
9518c2ecf20Sopenharmony_ci * There is a very similar struct icdinode in xfs_inode which matches the
9528c2ecf20Sopenharmony_ci * layout of the first 96 bytes of this structure, but is kept in native
9538c2ecf20Sopenharmony_ci * format instead of big endian.
9548c2ecf20Sopenharmony_ci *
9558c2ecf20Sopenharmony_ci * Note: di_flushiter is only used by v1/2 inodes - it's effectively a zeroed
9568c2ecf20Sopenharmony_ci * padding field for v3 inodes.
9578c2ecf20Sopenharmony_ci */
9588c2ecf20Sopenharmony_ci#define	XFS_DINODE_MAGIC		0x494e	/* 'IN' */
9598c2ecf20Sopenharmony_citypedef struct xfs_dinode {
9608c2ecf20Sopenharmony_ci	__be16		di_magic;	/* inode magic # = XFS_DINODE_MAGIC */
9618c2ecf20Sopenharmony_ci	__be16		di_mode;	/* mode and type of file */
9628c2ecf20Sopenharmony_ci	__u8		di_version;	/* inode version */
9638c2ecf20Sopenharmony_ci	__u8		di_format;	/* format of di_c data */
9648c2ecf20Sopenharmony_ci	__be16		di_onlink;	/* old number of links to file */
9658c2ecf20Sopenharmony_ci	__be32		di_uid;		/* owner's user id */
9668c2ecf20Sopenharmony_ci	__be32		di_gid;		/* owner's group id */
9678c2ecf20Sopenharmony_ci	__be32		di_nlink;	/* number of links to file */
9688c2ecf20Sopenharmony_ci	__be16		di_projid_lo;	/* lower part of owner's project id */
9698c2ecf20Sopenharmony_ci	__be16		di_projid_hi;	/* higher part owner's project id */
9708c2ecf20Sopenharmony_ci	__u8		di_pad[6];	/* unused, zeroed space */
9718c2ecf20Sopenharmony_ci	__be16		di_flushiter;	/* incremented on flush */
9728c2ecf20Sopenharmony_ci	xfs_timestamp_t	di_atime;	/* time last accessed */
9738c2ecf20Sopenharmony_ci	xfs_timestamp_t	di_mtime;	/* time last modified */
9748c2ecf20Sopenharmony_ci	xfs_timestamp_t	di_ctime;	/* time created/inode modified */
9758c2ecf20Sopenharmony_ci	__be64		di_size;	/* number of bytes in file */
9768c2ecf20Sopenharmony_ci	__be64		di_nblocks;	/* # of direct & btree blocks used */
9778c2ecf20Sopenharmony_ci	__be32		di_extsize;	/* basic/minimum extent size for file */
9788c2ecf20Sopenharmony_ci	__be32		di_nextents;	/* number of extents in data fork */
9798c2ecf20Sopenharmony_ci	__be16		di_anextents;	/* number of extents in attribute fork*/
9808c2ecf20Sopenharmony_ci	__u8		di_forkoff;	/* attr fork offs, <<3 for 64b align */
9818c2ecf20Sopenharmony_ci	__s8		di_aformat;	/* format of attr fork's data */
9828c2ecf20Sopenharmony_ci	__be32		di_dmevmask;	/* DMIG event mask */
9838c2ecf20Sopenharmony_ci	__be16		di_dmstate;	/* DMIG state info */
9848c2ecf20Sopenharmony_ci	__be16		di_flags;	/* random flags, XFS_DIFLAG_... */
9858c2ecf20Sopenharmony_ci	__be32		di_gen;		/* generation number */
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci	/* di_next_unlinked is the only non-core field in the old dinode */
9888c2ecf20Sopenharmony_ci	__be32		di_next_unlinked;/* agi unlinked list ptr */
9898c2ecf20Sopenharmony_ci
9908c2ecf20Sopenharmony_ci	/* start of the extended dinode, writable fields */
9918c2ecf20Sopenharmony_ci	__le32		di_crc;		/* CRC of the inode */
9928c2ecf20Sopenharmony_ci	__be64		di_changecount;	/* number of attribute changes */
9938c2ecf20Sopenharmony_ci	__be64		di_lsn;		/* flush sequence */
9948c2ecf20Sopenharmony_ci	__be64		di_flags2;	/* more random flags */
9958c2ecf20Sopenharmony_ci	__be32		di_cowextsize;	/* basic cow extent size for file */
9968c2ecf20Sopenharmony_ci	__u8		di_pad2[12];	/* more padding for future expansion */
9978c2ecf20Sopenharmony_ci
9988c2ecf20Sopenharmony_ci	/* fields only written to during inode creation */
9998c2ecf20Sopenharmony_ci	xfs_timestamp_t	di_crtime;	/* time created */
10008c2ecf20Sopenharmony_ci	__be64		di_ino;		/* inode number */
10018c2ecf20Sopenharmony_ci	uuid_t		di_uuid;	/* UUID of the filesystem */
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci	/* structure must be padded to 64 bit alignment */
10048c2ecf20Sopenharmony_ci} xfs_dinode_t;
10058c2ecf20Sopenharmony_ci
10068c2ecf20Sopenharmony_ci#define XFS_DINODE_CRC_OFF	offsetof(struct xfs_dinode, di_crc)
10078c2ecf20Sopenharmony_ci
10088c2ecf20Sopenharmony_ci#define DI_MAX_FLUSH 0xffff
10098c2ecf20Sopenharmony_ci
10108c2ecf20Sopenharmony_ci/*
10118c2ecf20Sopenharmony_ci * Size of the core inode on disk.  Version 1 and 2 inodes have
10128c2ecf20Sopenharmony_ci * the same size, but version 3 has grown a few additional fields.
10138c2ecf20Sopenharmony_ci */
10148c2ecf20Sopenharmony_cistatic inline uint xfs_dinode_size(int version)
10158c2ecf20Sopenharmony_ci{
10168c2ecf20Sopenharmony_ci	if (version == 3)
10178c2ecf20Sopenharmony_ci		return sizeof(struct xfs_dinode);
10188c2ecf20Sopenharmony_ci	return offsetof(struct xfs_dinode, di_crc);
10198c2ecf20Sopenharmony_ci}
10208c2ecf20Sopenharmony_ci
10218c2ecf20Sopenharmony_ci/*
10228c2ecf20Sopenharmony_ci * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
10238c2ecf20Sopenharmony_ci * Since the pathconf interface is signed, we use 2^31 - 1 instead.
10248c2ecf20Sopenharmony_ci */
10258c2ecf20Sopenharmony_ci#define	XFS_MAXLINK		((1U << 31) - 1U)
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci/*
10288c2ecf20Sopenharmony_ci * Values for di_format
10298c2ecf20Sopenharmony_ci *
10308c2ecf20Sopenharmony_ci * This enum is used in string mapping in xfs_trace.h; please keep the
10318c2ecf20Sopenharmony_ci * TRACE_DEFINE_ENUMs for it up to date.
10328c2ecf20Sopenharmony_ci */
10338c2ecf20Sopenharmony_cienum xfs_dinode_fmt {
10348c2ecf20Sopenharmony_ci	XFS_DINODE_FMT_DEV,		/* xfs_dev_t */
10358c2ecf20Sopenharmony_ci	XFS_DINODE_FMT_LOCAL,		/* bulk data */
10368c2ecf20Sopenharmony_ci	XFS_DINODE_FMT_EXTENTS,		/* struct xfs_bmbt_rec */
10378c2ecf20Sopenharmony_ci	XFS_DINODE_FMT_BTREE,		/* struct xfs_bmdr_block */
10388c2ecf20Sopenharmony_ci	XFS_DINODE_FMT_UUID		/* added long ago, but never used */
10398c2ecf20Sopenharmony_ci};
10408c2ecf20Sopenharmony_ci
10418c2ecf20Sopenharmony_ci#define XFS_INODE_FORMAT_STR \
10428c2ecf20Sopenharmony_ci	{ XFS_DINODE_FMT_DEV,		"dev" }, \
10438c2ecf20Sopenharmony_ci	{ XFS_DINODE_FMT_LOCAL,		"local" }, \
10448c2ecf20Sopenharmony_ci	{ XFS_DINODE_FMT_EXTENTS,	"extent" }, \
10458c2ecf20Sopenharmony_ci	{ XFS_DINODE_FMT_BTREE,		"btree" }, \
10468c2ecf20Sopenharmony_ci	{ XFS_DINODE_FMT_UUID,		"uuid" }
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ci/*
10498c2ecf20Sopenharmony_ci * Inode minimum and maximum sizes.
10508c2ecf20Sopenharmony_ci */
10518c2ecf20Sopenharmony_ci#define	XFS_DINODE_MIN_LOG	8
10528c2ecf20Sopenharmony_ci#define	XFS_DINODE_MAX_LOG	11
10538c2ecf20Sopenharmony_ci#define	XFS_DINODE_MIN_SIZE	(1 << XFS_DINODE_MIN_LOG)
10548c2ecf20Sopenharmony_ci#define	XFS_DINODE_MAX_SIZE	(1 << XFS_DINODE_MAX_LOG)
10558c2ecf20Sopenharmony_ci
10568c2ecf20Sopenharmony_ci/*
10578c2ecf20Sopenharmony_ci * Inode size for given fs.
10588c2ecf20Sopenharmony_ci */
10598c2ecf20Sopenharmony_ci#define XFS_DINODE_SIZE(sbp) \
10608c2ecf20Sopenharmony_ci	(xfs_sb_version_has_v3inode(sbp) ? \
10618c2ecf20Sopenharmony_ci		sizeof(struct xfs_dinode) : \
10628c2ecf20Sopenharmony_ci		offsetof(struct xfs_dinode, di_crc))
10638c2ecf20Sopenharmony_ci#define XFS_LITINO(mp) \
10648c2ecf20Sopenharmony_ci	((mp)->m_sb.sb_inodesize - XFS_DINODE_SIZE(&(mp)->m_sb))
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci/*
10678c2ecf20Sopenharmony_ci * Inode data & attribute fork sizes, per inode.
10688c2ecf20Sopenharmony_ci */
10698c2ecf20Sopenharmony_ci#define XFS_DFORK_BOFF(dip)		((int)((dip)->di_forkoff << 3))
10708c2ecf20Sopenharmony_ci
10718c2ecf20Sopenharmony_ci#define XFS_DFORK_DSIZE(dip,mp) \
10728c2ecf20Sopenharmony_ci	((dip)->di_forkoff ? XFS_DFORK_BOFF(dip) : XFS_LITINO(mp))
10738c2ecf20Sopenharmony_ci#define XFS_DFORK_ASIZE(dip,mp) \
10748c2ecf20Sopenharmony_ci	((dip)->di_forkoff ? XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : 0)
10758c2ecf20Sopenharmony_ci#define XFS_DFORK_SIZE(dip,mp,w) \
10768c2ecf20Sopenharmony_ci	((w) == XFS_DATA_FORK ? \
10778c2ecf20Sopenharmony_ci		XFS_DFORK_DSIZE(dip, mp) : \
10788c2ecf20Sopenharmony_ci		XFS_DFORK_ASIZE(dip, mp))
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_ci#define XFS_DFORK_MAXEXT(dip, mp, w) \
10818c2ecf20Sopenharmony_ci	(XFS_DFORK_SIZE(dip, mp, w) / sizeof(struct xfs_bmbt_rec))
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_ci/*
10848c2ecf20Sopenharmony_ci * Return pointers to the data or attribute forks.
10858c2ecf20Sopenharmony_ci */
10868c2ecf20Sopenharmony_ci#define XFS_DFORK_DPTR(dip) \
10878c2ecf20Sopenharmony_ci	((char *)dip + xfs_dinode_size(dip->di_version))
10888c2ecf20Sopenharmony_ci#define XFS_DFORK_APTR(dip)	\
10898c2ecf20Sopenharmony_ci	(XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip))
10908c2ecf20Sopenharmony_ci#define XFS_DFORK_PTR(dip,w)	\
10918c2ecf20Sopenharmony_ci	((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_ci#define XFS_DFORK_FORMAT(dip,w) \
10948c2ecf20Sopenharmony_ci	((w) == XFS_DATA_FORK ? \
10958c2ecf20Sopenharmony_ci		(dip)->di_format : \
10968c2ecf20Sopenharmony_ci		(dip)->di_aformat)
10978c2ecf20Sopenharmony_ci#define XFS_DFORK_NEXTENTS(dip,w) \
10988c2ecf20Sopenharmony_ci	((w) == XFS_DATA_FORK ? \
10998c2ecf20Sopenharmony_ci		be32_to_cpu((dip)->di_nextents) : \
11008c2ecf20Sopenharmony_ci		be16_to_cpu((dip)->di_anextents))
11018c2ecf20Sopenharmony_ci
11028c2ecf20Sopenharmony_ci/*
11038c2ecf20Sopenharmony_ci * For block and character special files the 32bit dev_t is stored at the
11048c2ecf20Sopenharmony_ci * beginning of the data fork.
11058c2ecf20Sopenharmony_ci */
11068c2ecf20Sopenharmony_cistatic inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip)
11078c2ecf20Sopenharmony_ci{
11088c2ecf20Sopenharmony_ci	return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip));
11098c2ecf20Sopenharmony_ci}
11108c2ecf20Sopenharmony_ci
11118c2ecf20Sopenharmony_cistatic inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
11128c2ecf20Sopenharmony_ci{
11138c2ecf20Sopenharmony_ci	*(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev);
11148c2ecf20Sopenharmony_ci}
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ci/*
11178c2ecf20Sopenharmony_ci * Values for di_flags
11188c2ecf20Sopenharmony_ci */
11198c2ecf20Sopenharmony_ci#define XFS_DIFLAG_REALTIME_BIT  0	/* file's blocks come from rt area */
11208c2ecf20Sopenharmony_ci#define XFS_DIFLAG_PREALLOC_BIT  1	/* file space has been preallocated */
11218c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NEWRTBM_BIT   2	/* for rtbitmap inode, new format */
11228c2ecf20Sopenharmony_ci#define XFS_DIFLAG_IMMUTABLE_BIT 3	/* inode is immutable */
11238c2ecf20Sopenharmony_ci#define XFS_DIFLAG_APPEND_BIT    4	/* inode is append-only */
11248c2ecf20Sopenharmony_ci#define XFS_DIFLAG_SYNC_BIT      5	/* inode is written synchronously */
11258c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NOATIME_BIT   6	/* do not update atime */
11268c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NODUMP_BIT    7	/* do not dump */
11278c2ecf20Sopenharmony_ci#define XFS_DIFLAG_RTINHERIT_BIT 8	/* create with realtime bit set */
11288c2ecf20Sopenharmony_ci#define XFS_DIFLAG_PROJINHERIT_BIT   9	/* create with parents projid */
11298c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NOSYMLINKS_BIT   10	/* disallow symlink creation */
11308c2ecf20Sopenharmony_ci#define XFS_DIFLAG_EXTSIZE_BIT      11	/* inode extent size allocator hint */
11318c2ecf20Sopenharmony_ci#define XFS_DIFLAG_EXTSZINHERIT_BIT 12	/* inherit inode extent size */
11328c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NODEFRAG_BIT     13	/* do not reorganize/defragment */
11338c2ecf20Sopenharmony_ci#define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
11348c2ecf20Sopenharmony_ci/* Do not use bit 15, di_flags is legacy and unchanging now */
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci#define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
11378c2ecf20Sopenharmony_ci#define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
11388c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
11398c2ecf20Sopenharmony_ci#define XFS_DIFLAG_IMMUTABLE     (1 << XFS_DIFLAG_IMMUTABLE_BIT)
11408c2ecf20Sopenharmony_ci#define XFS_DIFLAG_APPEND        (1 << XFS_DIFLAG_APPEND_BIT)
11418c2ecf20Sopenharmony_ci#define XFS_DIFLAG_SYNC          (1 << XFS_DIFLAG_SYNC_BIT)
11428c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NOATIME       (1 << XFS_DIFLAG_NOATIME_BIT)
11438c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NODUMP        (1 << XFS_DIFLAG_NODUMP_BIT)
11448c2ecf20Sopenharmony_ci#define XFS_DIFLAG_RTINHERIT     (1 << XFS_DIFLAG_RTINHERIT_BIT)
11458c2ecf20Sopenharmony_ci#define XFS_DIFLAG_PROJINHERIT   (1 << XFS_DIFLAG_PROJINHERIT_BIT)
11468c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NOSYMLINKS    (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
11478c2ecf20Sopenharmony_ci#define XFS_DIFLAG_EXTSIZE       (1 << XFS_DIFLAG_EXTSIZE_BIT)
11488c2ecf20Sopenharmony_ci#define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
11498c2ecf20Sopenharmony_ci#define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
11508c2ecf20Sopenharmony_ci#define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
11518c2ecf20Sopenharmony_ci
11528c2ecf20Sopenharmony_ci#define XFS_DIFLAG_ANY \
11538c2ecf20Sopenharmony_ci	(XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
11548c2ecf20Sopenharmony_ci	 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
11558c2ecf20Sopenharmony_ci	 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
11568c2ecf20Sopenharmony_ci	 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
11578c2ecf20Sopenharmony_ci	 XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci/*
11608c2ecf20Sopenharmony_ci * Values for di_flags2 These start by being exposed to userspace in the upper
11618c2ecf20Sopenharmony_ci * 16 bits of the XFS_XFLAG_s range.
11628c2ecf20Sopenharmony_ci */
11638c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_DAX_BIT	0	/* use DAX for this inode */
11648c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_REFLINK_BIT	1	/* file's blocks may be shared */
11658c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_COWEXTSIZE_BIT   2  /* copy on write extent size hint */
11668c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_BIGTIME_BIT	3	/* big timestamps */
11678c2ecf20Sopenharmony_ci
11688c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_DAX		(1 << XFS_DIFLAG2_DAX_BIT)
11698c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_REFLINK     (1 << XFS_DIFLAG2_REFLINK_BIT)
11708c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_COWEXTSIZE  (1 << XFS_DIFLAG2_COWEXTSIZE_BIT)
11718c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_BIGTIME	(1 << XFS_DIFLAG2_BIGTIME_BIT)
11728c2ecf20Sopenharmony_ci
11738c2ecf20Sopenharmony_ci#define XFS_DIFLAG2_ANY \
11748c2ecf20Sopenharmony_ci	(XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \
11758c2ecf20Sopenharmony_ci	 XFS_DIFLAG2_BIGTIME)
11768c2ecf20Sopenharmony_ci
11778c2ecf20Sopenharmony_cistatic inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
11788c2ecf20Sopenharmony_ci{
11798c2ecf20Sopenharmony_ci	return dip->di_version >= 3 &&
11808c2ecf20Sopenharmony_ci	       (dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_BIGTIME));
11818c2ecf20Sopenharmony_ci}
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci/*
11848c2ecf20Sopenharmony_ci * Inode number format:
11858c2ecf20Sopenharmony_ci * low inopblog bits - offset in block
11868c2ecf20Sopenharmony_ci * next agblklog bits - block number in ag
11878c2ecf20Sopenharmony_ci * next agno_log bits - ag number
11888c2ecf20Sopenharmony_ci * high agno_log-agblklog-inopblog bits - 0
11898c2ecf20Sopenharmony_ci */
11908c2ecf20Sopenharmony_ci#define	XFS_INO_MASK(k)			(uint32_t)((1ULL << (k)) - 1)
11918c2ecf20Sopenharmony_ci#define	XFS_INO_OFFSET_BITS(mp)		(mp)->m_sb.sb_inopblog
11928c2ecf20Sopenharmony_ci#define	XFS_INO_AGBNO_BITS(mp)		(mp)->m_sb.sb_agblklog
11938c2ecf20Sopenharmony_ci#define	XFS_INO_AGINO_BITS(mp)		((mp)->m_ino_geo.agino_log)
11948c2ecf20Sopenharmony_ci#define	XFS_INO_AGNO_BITS(mp)		(mp)->m_agno_log
11958c2ecf20Sopenharmony_ci#define	XFS_INO_BITS(mp)		\
11968c2ecf20Sopenharmony_ci	XFS_INO_AGNO_BITS(mp) + XFS_INO_AGINO_BITS(mp)
11978c2ecf20Sopenharmony_ci#define	XFS_INO_TO_AGNO(mp,i)		\
11988c2ecf20Sopenharmony_ci	((xfs_agnumber_t)((i) >> XFS_INO_AGINO_BITS(mp)))
11998c2ecf20Sopenharmony_ci#define	XFS_INO_TO_AGINO(mp,i)		\
12008c2ecf20Sopenharmony_ci	((xfs_agino_t)(i) & XFS_INO_MASK(XFS_INO_AGINO_BITS(mp)))
12018c2ecf20Sopenharmony_ci#define	XFS_INO_TO_AGBNO(mp,i)		\
12028c2ecf20Sopenharmony_ci	(((xfs_agblock_t)(i) >> XFS_INO_OFFSET_BITS(mp)) & \
12038c2ecf20Sopenharmony_ci		XFS_INO_MASK(XFS_INO_AGBNO_BITS(mp)))
12048c2ecf20Sopenharmony_ci#define	XFS_INO_TO_OFFSET(mp,i)		\
12058c2ecf20Sopenharmony_ci	((int)(i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
12068c2ecf20Sopenharmony_ci#define	XFS_INO_TO_FSB(mp,i)		\
12078c2ecf20Sopenharmony_ci	XFS_AGB_TO_FSB(mp, XFS_INO_TO_AGNO(mp,i), XFS_INO_TO_AGBNO(mp,i))
12088c2ecf20Sopenharmony_ci#define	XFS_AGINO_TO_INO(mp,a,i)	\
12098c2ecf20Sopenharmony_ci	(((xfs_ino_t)(a) << XFS_INO_AGINO_BITS(mp)) | (i))
12108c2ecf20Sopenharmony_ci#define	XFS_AGINO_TO_AGBNO(mp,i)	((i) >> XFS_INO_OFFSET_BITS(mp))
12118c2ecf20Sopenharmony_ci#define	XFS_AGINO_TO_OFFSET(mp,i)	\
12128c2ecf20Sopenharmony_ci	((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
12138c2ecf20Sopenharmony_ci#define	XFS_OFFBNO_TO_AGINO(mp,b,o)	\
12148c2ecf20Sopenharmony_ci	((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o)))
12158c2ecf20Sopenharmony_ci#define	XFS_FSB_TO_INO(mp, b)	((xfs_ino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
12168c2ecf20Sopenharmony_ci#define	XFS_AGB_TO_AGINO(mp, b)	((xfs_agino_t)((b) << XFS_INO_OFFSET_BITS(mp)))
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci#define	XFS_MAXINUMBER		((xfs_ino_t)((1ULL << 56) - 1ULL))
12198c2ecf20Sopenharmony_ci#define	XFS_MAXINUMBER_32	((xfs_ino_t)((1ULL << 32) - 1ULL))
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci/*
12228c2ecf20Sopenharmony_ci * RealTime Device format definitions
12238c2ecf20Sopenharmony_ci */
12248c2ecf20Sopenharmony_ci
12258c2ecf20Sopenharmony_ci/* Min and max rt extent sizes, specified in bytes */
12268c2ecf20Sopenharmony_ci#define	XFS_MAX_RTEXTSIZE	(1024 * 1024 * 1024)	/* 1GB */
12278c2ecf20Sopenharmony_ci#define	XFS_DFL_RTEXTSIZE	(64 * 1024)	        /* 64kB */
12288c2ecf20Sopenharmony_ci#define	XFS_MIN_RTEXTSIZE	(4 * 1024)		/* 4kB */
12298c2ecf20Sopenharmony_ci
12308c2ecf20Sopenharmony_ci#define	XFS_BLOCKSIZE(mp)	((mp)->m_sb.sb_blocksize)
12318c2ecf20Sopenharmony_ci#define	XFS_BLOCKMASK(mp)	((mp)->m_blockmask)
12328c2ecf20Sopenharmony_ci#define	XFS_BLOCKWSIZE(mp)	((mp)->m_blockwsize)
12338c2ecf20Sopenharmony_ci#define	XFS_BLOCKWMASK(mp)	((mp)->m_blockwmask)
12348c2ecf20Sopenharmony_ci
12358c2ecf20Sopenharmony_ci/*
12368c2ecf20Sopenharmony_ci * RT Summary and bit manipulation macros.
12378c2ecf20Sopenharmony_ci */
12388c2ecf20Sopenharmony_ci#define	XFS_SUMOFFS(mp,ls,bb)	((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
12398c2ecf20Sopenharmony_ci#define	XFS_SUMOFFSTOBLOCK(mp,s)	\
12408c2ecf20Sopenharmony_ci	(((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
12418c2ecf20Sopenharmony_ci#define	XFS_SUMPTR(mp,bp,so)	\
12428c2ecf20Sopenharmony_ci	((xfs_suminfo_t *)((bp)->b_addr + \
12438c2ecf20Sopenharmony_ci		(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
12448c2ecf20Sopenharmony_ci
12458c2ecf20Sopenharmony_ci#define	XFS_BITTOBLOCK(mp,bi)	((bi) >> (mp)->m_blkbit_log)
12468c2ecf20Sopenharmony_ci#define	XFS_BLOCKTOBIT(mp,bb)	((bb) << (mp)->m_blkbit_log)
12478c2ecf20Sopenharmony_ci#define	XFS_BITTOWORD(mp,bi)	\
12488c2ecf20Sopenharmony_ci	((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
12498c2ecf20Sopenharmony_ci
12508c2ecf20Sopenharmony_ci#define	XFS_RTMIN(a,b)	((a) < (b) ? (a) : (b))
12518c2ecf20Sopenharmony_ci#define	XFS_RTMAX(a,b)	((a) > (b) ? (a) : (b))
12528c2ecf20Sopenharmony_ci
12538c2ecf20Sopenharmony_ci#define	XFS_RTLOBIT(w)	xfs_lowbit32(w)
12548c2ecf20Sopenharmony_ci#define	XFS_RTHIBIT(w)	xfs_highbit32(w)
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_ci#define	XFS_RTBLOCKLOG(b)	xfs_highbit64(b)
12578c2ecf20Sopenharmony_ci
12588c2ecf20Sopenharmony_ci/*
12598c2ecf20Sopenharmony_ci * Dquot and dquot block format definitions
12608c2ecf20Sopenharmony_ci */
12618c2ecf20Sopenharmony_ci#define XFS_DQUOT_MAGIC		0x4451		/* 'DQ' */
12628c2ecf20Sopenharmony_ci#define XFS_DQUOT_VERSION	(uint8_t)0x01	/* latest version number */
12638c2ecf20Sopenharmony_ci
12648c2ecf20Sopenharmony_ci#define XFS_DQTYPE_USER		0x01		/* user dquot record */
12658c2ecf20Sopenharmony_ci#define XFS_DQTYPE_PROJ		0x02		/* project dquot record */
12668c2ecf20Sopenharmony_ci#define XFS_DQTYPE_GROUP	0x04		/* group dquot record */
12678c2ecf20Sopenharmony_ci#define XFS_DQTYPE_BIGTIME	0x80		/* large expiry timestamps */
12688c2ecf20Sopenharmony_ci
12698c2ecf20Sopenharmony_ci/* bitmask to determine if this is a user/group/project dquot */
12708c2ecf20Sopenharmony_ci#define XFS_DQTYPE_REC_MASK	(XFS_DQTYPE_USER | \
12718c2ecf20Sopenharmony_ci				 XFS_DQTYPE_PROJ | \
12728c2ecf20Sopenharmony_ci				 XFS_DQTYPE_GROUP)
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_ci#define XFS_DQTYPE_ANY		(XFS_DQTYPE_REC_MASK | \
12758c2ecf20Sopenharmony_ci				 XFS_DQTYPE_BIGTIME)
12768c2ecf20Sopenharmony_ci
12778c2ecf20Sopenharmony_ci/*
12788c2ecf20Sopenharmony_ci * XFS Quota Timers
12798c2ecf20Sopenharmony_ci * ================
12808c2ecf20Sopenharmony_ci *
12818c2ecf20Sopenharmony_ci * Traditional quota grace period expiration timers are an unsigned 32-bit
12828c2ecf20Sopenharmony_ci * seconds counter; time zero is the Unix epoch, Jan  1 00:00:01 UTC 1970.
12838c2ecf20Sopenharmony_ci * Note that an expiration value of zero means that the quota limit has not
12848c2ecf20Sopenharmony_ci * been reached, and therefore no expiration has been set.  Therefore, the
12858c2ecf20Sopenharmony_ci * ondisk min and max defined here can be used directly to constrain the incore
12868c2ecf20Sopenharmony_ci * quota expiration timestamps on a Unix system.
12878c2ecf20Sopenharmony_ci *
12888c2ecf20Sopenharmony_ci * When bigtime is enabled, we trade two bits of precision to expand the
12898c2ecf20Sopenharmony_ci * expiration timeout range to match that of big inode timestamps.  The min and
12908c2ecf20Sopenharmony_ci * max recorded here are the on-disk limits, not a Unix timestamp.
12918c2ecf20Sopenharmony_ci *
12928c2ecf20Sopenharmony_ci * The grace period for each quota type is stored in the root dquot (id = 0)
12938c2ecf20Sopenharmony_ci * and is applied to a non-root dquot when it exceeds the soft or hard limits.
12948c2ecf20Sopenharmony_ci * The length of quota grace periods are unsigned 32-bit quantities measured in
12958c2ecf20Sopenharmony_ci * units of seconds.  A value of zero means to use the default period.
12968c2ecf20Sopenharmony_ci */
12978c2ecf20Sopenharmony_ci
12988c2ecf20Sopenharmony_ci/*
12998c2ecf20Sopenharmony_ci * Smallest possible ondisk quota expiration value with traditional timestamps.
13008c2ecf20Sopenharmony_ci * This corresponds exactly with the incore expiration Jan  1 00:00:01 UTC 1970.
13018c2ecf20Sopenharmony_ci */
13028c2ecf20Sopenharmony_ci#define XFS_DQ_LEGACY_EXPIRY_MIN	((int64_t)1)
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_ci/*
13058c2ecf20Sopenharmony_ci * Largest possible ondisk quota expiration value with traditional timestamps.
13068c2ecf20Sopenharmony_ci * This corresponds exactly with the incore expiration Feb  7 06:28:15 UTC 2106.
13078c2ecf20Sopenharmony_ci */
13088c2ecf20Sopenharmony_ci#define XFS_DQ_LEGACY_EXPIRY_MAX	((int64_t)U32_MAX)
13098c2ecf20Sopenharmony_ci
13108c2ecf20Sopenharmony_ci/*
13118c2ecf20Sopenharmony_ci * Smallest possible ondisk quota expiration value with bigtime timestamps.
13128c2ecf20Sopenharmony_ci * This corresponds (after conversion to a Unix timestamp) with the incore
13138c2ecf20Sopenharmony_ci * expiration of Jan  1 00:00:04 UTC 1970.
13148c2ecf20Sopenharmony_ci */
13158c2ecf20Sopenharmony_ci#define XFS_DQ_BIGTIME_EXPIRY_MIN	(XFS_DQ_LEGACY_EXPIRY_MIN)
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci/*
13188c2ecf20Sopenharmony_ci * Largest supported ondisk quota expiration value with bigtime timestamps.
13198c2ecf20Sopenharmony_ci * This corresponds (after conversion to a Unix timestamp) with an incore
13208c2ecf20Sopenharmony_ci * expiration of Jul  2 20:20:24 UTC 2486.
13218c2ecf20Sopenharmony_ci *
13228c2ecf20Sopenharmony_ci * The ondisk field supports values up to -1U, which corresponds to an incore
13238c2ecf20Sopenharmony_ci * expiration in 2514.  This is beyond the maximum the bigtime inode timestamp,
13248c2ecf20Sopenharmony_ci * so we cap the maximum bigtime quota expiration to the max inode timestamp.
13258c2ecf20Sopenharmony_ci */
13268c2ecf20Sopenharmony_ci#define XFS_DQ_BIGTIME_EXPIRY_MAX	((int64_t)4074815106U)
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_ci/*
13298c2ecf20Sopenharmony_ci * The following conversion factors assist in converting a quota expiration
13308c2ecf20Sopenharmony_ci * timestamp between the incore and ondisk formats.
13318c2ecf20Sopenharmony_ci */
13328c2ecf20Sopenharmony_ci#define XFS_DQ_BIGTIME_SHIFT	(2)
13338c2ecf20Sopenharmony_ci#define XFS_DQ_BIGTIME_SLACK	((int64_t)(1ULL << XFS_DQ_BIGTIME_SHIFT) - 1)
13348c2ecf20Sopenharmony_ci
13358c2ecf20Sopenharmony_ci/* Convert an incore quota expiration timestamp to an ondisk bigtime value. */
13368c2ecf20Sopenharmony_cistatic inline uint32_t xfs_dq_unix_to_bigtime(time64_t unix_seconds)
13378c2ecf20Sopenharmony_ci{
13388c2ecf20Sopenharmony_ci	/*
13398c2ecf20Sopenharmony_ci	 * Round the expiration timestamp up to the nearest bigtime timestamp
13408c2ecf20Sopenharmony_ci	 * that we can store, to give users the most time to fix problems.
13418c2ecf20Sopenharmony_ci	 */
13428c2ecf20Sopenharmony_ci	return ((uint64_t)unix_seconds + XFS_DQ_BIGTIME_SLACK) >>
13438c2ecf20Sopenharmony_ci			XFS_DQ_BIGTIME_SHIFT;
13448c2ecf20Sopenharmony_ci}
13458c2ecf20Sopenharmony_ci
13468c2ecf20Sopenharmony_ci/* Convert an ondisk bigtime quota expiration value to an incore timestamp. */
13478c2ecf20Sopenharmony_cistatic inline time64_t xfs_dq_bigtime_to_unix(uint32_t ondisk_seconds)
13488c2ecf20Sopenharmony_ci{
13498c2ecf20Sopenharmony_ci	return (time64_t)ondisk_seconds << XFS_DQ_BIGTIME_SHIFT;
13508c2ecf20Sopenharmony_ci}
13518c2ecf20Sopenharmony_ci
13528c2ecf20Sopenharmony_ci/*
13538c2ecf20Sopenharmony_ci * Default quota grace periods, ranging from zero (use the compiled defaults)
13548c2ecf20Sopenharmony_ci * to ~136 years.  These are applied to a non-root dquot that has exceeded
13558c2ecf20Sopenharmony_ci * either limit.
13568c2ecf20Sopenharmony_ci */
13578c2ecf20Sopenharmony_ci#define XFS_DQ_GRACE_MIN		((int64_t)0)
13588c2ecf20Sopenharmony_ci#define XFS_DQ_GRACE_MAX		((int64_t)U32_MAX)
13598c2ecf20Sopenharmony_ci
13608c2ecf20Sopenharmony_ci/*
13618c2ecf20Sopenharmony_ci * This is the main portion of the on-disk representation of quota information
13628c2ecf20Sopenharmony_ci * for a user.  We pad this with some more expansion room to construct the on
13638c2ecf20Sopenharmony_ci * disk structure.
13648c2ecf20Sopenharmony_ci */
13658c2ecf20Sopenharmony_cistruct xfs_disk_dquot {
13668c2ecf20Sopenharmony_ci	__be16		d_magic;	/* dquot magic = XFS_DQUOT_MAGIC */
13678c2ecf20Sopenharmony_ci	__u8		d_version;	/* dquot version */
13688c2ecf20Sopenharmony_ci	__u8		d_type;		/* XFS_DQTYPE_USER/PROJ/GROUP */
13698c2ecf20Sopenharmony_ci	__be32		d_id;		/* user,project,group id */
13708c2ecf20Sopenharmony_ci	__be64		d_blk_hardlimit;/* absolute limit on disk blks */
13718c2ecf20Sopenharmony_ci	__be64		d_blk_softlimit;/* preferred limit on disk blks */
13728c2ecf20Sopenharmony_ci	__be64		d_ino_hardlimit;/* maximum # allocated inodes */
13738c2ecf20Sopenharmony_ci	__be64		d_ino_softlimit;/* preferred inode limit */
13748c2ecf20Sopenharmony_ci	__be64		d_bcount;	/* disk blocks owned by the user */
13758c2ecf20Sopenharmony_ci	__be64		d_icount;	/* inodes owned by the user */
13768c2ecf20Sopenharmony_ci	__be32		d_itimer;	/* zero if within inode limits if not,
13778c2ecf20Sopenharmony_ci					   this is when we refuse service */
13788c2ecf20Sopenharmony_ci	__be32		d_btimer;	/* similar to above; for disk blocks */
13798c2ecf20Sopenharmony_ci	__be16		d_iwarns;	/* warnings issued wrt num inodes */
13808c2ecf20Sopenharmony_ci	__be16		d_bwarns;	/* warnings issued wrt disk blocks */
13818c2ecf20Sopenharmony_ci	__be32		d_pad0;		/* 64 bit align */
13828c2ecf20Sopenharmony_ci	__be64		d_rtb_hardlimit;/* absolute limit on realtime blks */
13838c2ecf20Sopenharmony_ci	__be64		d_rtb_softlimit;/* preferred limit on RT disk blks */
13848c2ecf20Sopenharmony_ci	__be64		d_rtbcount;	/* realtime blocks owned */
13858c2ecf20Sopenharmony_ci	__be32		d_rtbtimer;	/* similar to above; for RT disk blocks */
13868c2ecf20Sopenharmony_ci	__be16		d_rtbwarns;	/* warnings issued wrt RT disk blocks */
13878c2ecf20Sopenharmony_ci	__be16		d_pad;
13888c2ecf20Sopenharmony_ci};
13898c2ecf20Sopenharmony_ci
13908c2ecf20Sopenharmony_ci/*
13918c2ecf20Sopenharmony_ci * This is what goes on disk. This is separated from the xfs_disk_dquot because
13928c2ecf20Sopenharmony_ci * carrying the unnecessary padding would be a waste of memory.
13938c2ecf20Sopenharmony_ci */
13948c2ecf20Sopenharmony_citypedef struct xfs_dqblk {
13958c2ecf20Sopenharmony_ci	struct xfs_disk_dquot	dd_diskdq; /* portion living incore as well */
13968c2ecf20Sopenharmony_ci	char			dd_fill[4];/* filling for posterity */
13978c2ecf20Sopenharmony_ci
13988c2ecf20Sopenharmony_ci	/*
13998c2ecf20Sopenharmony_ci	 * These two are only present on filesystems with the CRC bits set.
14008c2ecf20Sopenharmony_ci	 */
14018c2ecf20Sopenharmony_ci	__be32		  dd_crc;	/* checksum */
14028c2ecf20Sopenharmony_ci	__be64		  dd_lsn;	/* last modification in log */
14038c2ecf20Sopenharmony_ci	uuid_t		  dd_uuid;	/* location information */
14048c2ecf20Sopenharmony_ci} xfs_dqblk_t;
14058c2ecf20Sopenharmony_ci
14068c2ecf20Sopenharmony_ci#define XFS_DQUOT_CRC_OFF	offsetof(struct xfs_dqblk, dd_crc)
14078c2ecf20Sopenharmony_ci
14088c2ecf20Sopenharmony_ci/*
14098c2ecf20Sopenharmony_ci * This defines the unit of allocation of dquots.
14108c2ecf20Sopenharmony_ci *
14118c2ecf20Sopenharmony_ci * Currently, it is just one file system block, and a 4K blk contains 30
14128c2ecf20Sopenharmony_ci * (136 * 30 = 4080) dquots. It's probably not worth trying to make
14138c2ecf20Sopenharmony_ci * this more dynamic.
14148c2ecf20Sopenharmony_ci *
14158c2ecf20Sopenharmony_ci * However, if this number is changed, we have to make sure that we don't
14168c2ecf20Sopenharmony_ci * implicitly assume that we do allocations in chunks of a single filesystem
14178c2ecf20Sopenharmony_ci * block in the dquot/xqm code.
14188c2ecf20Sopenharmony_ci *
14198c2ecf20Sopenharmony_ci * This is part of the ondisk format because the structure size is not a power
14208c2ecf20Sopenharmony_ci * of two, which leaves slack at the end of the disk block.
14218c2ecf20Sopenharmony_ci */
14228c2ecf20Sopenharmony_ci#define XFS_DQUOT_CLUSTER_SIZE_FSB	(xfs_filblks_t)1
14238c2ecf20Sopenharmony_ci
14248c2ecf20Sopenharmony_ci/*
14258c2ecf20Sopenharmony_ci * Remote symlink format and access functions.
14268c2ecf20Sopenharmony_ci */
14278c2ecf20Sopenharmony_ci#define XFS_SYMLINK_MAGIC	0x58534c4d	/* XSLM */
14288c2ecf20Sopenharmony_ci
14298c2ecf20Sopenharmony_cistruct xfs_dsymlink_hdr {
14308c2ecf20Sopenharmony_ci	__be32	sl_magic;
14318c2ecf20Sopenharmony_ci	__be32	sl_offset;
14328c2ecf20Sopenharmony_ci	__be32	sl_bytes;
14338c2ecf20Sopenharmony_ci	__be32	sl_crc;
14348c2ecf20Sopenharmony_ci	uuid_t	sl_uuid;
14358c2ecf20Sopenharmony_ci	__be64	sl_owner;
14368c2ecf20Sopenharmony_ci	__be64	sl_blkno;
14378c2ecf20Sopenharmony_ci	__be64	sl_lsn;
14388c2ecf20Sopenharmony_ci};
14398c2ecf20Sopenharmony_ci
14408c2ecf20Sopenharmony_ci#define XFS_SYMLINK_CRC_OFF	offsetof(struct xfs_dsymlink_hdr, sl_crc)
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci#define XFS_SYMLINK_MAXLEN	1024
14438c2ecf20Sopenharmony_ci/*
14448c2ecf20Sopenharmony_ci * The maximum pathlen is 1024 bytes. Since the minimum file system
14458c2ecf20Sopenharmony_ci * blocksize is 512 bytes, we can get a max of 3 extents back from
14468c2ecf20Sopenharmony_ci * bmapi when crc headers are taken into account.
14478c2ecf20Sopenharmony_ci */
14488c2ecf20Sopenharmony_ci#define XFS_SYMLINK_MAPS 3
14498c2ecf20Sopenharmony_ci
14508c2ecf20Sopenharmony_ci#define XFS_SYMLINK_BUF_SPACE(mp, bufsize)	\
14518c2ecf20Sopenharmony_ci	((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
14528c2ecf20Sopenharmony_ci			sizeof(struct xfs_dsymlink_hdr) : 0))
14538c2ecf20Sopenharmony_ci
14548c2ecf20Sopenharmony_ci
14558c2ecf20Sopenharmony_ci/*
14568c2ecf20Sopenharmony_ci * Allocation Btree format definitions
14578c2ecf20Sopenharmony_ci *
14588c2ecf20Sopenharmony_ci * There are two on-disk btrees, one sorted by blockno and one sorted
14598c2ecf20Sopenharmony_ci * by blockcount and blockno.  All blocks look the same to make the code
14608c2ecf20Sopenharmony_ci * simpler; if we have time later, we'll make the optimizations.
14618c2ecf20Sopenharmony_ci */
14628c2ecf20Sopenharmony_ci#define	XFS_ABTB_MAGIC		0x41425442	/* 'ABTB' for bno tree */
14638c2ecf20Sopenharmony_ci#define	XFS_ABTB_CRC_MAGIC	0x41423342	/* 'AB3B' */
14648c2ecf20Sopenharmony_ci#define	XFS_ABTC_MAGIC		0x41425443	/* 'ABTC' for cnt tree */
14658c2ecf20Sopenharmony_ci#define	XFS_ABTC_CRC_MAGIC	0x41423343	/* 'AB3C' */
14668c2ecf20Sopenharmony_ci
14678c2ecf20Sopenharmony_ci/*
14688c2ecf20Sopenharmony_ci * Data record/key structure
14698c2ecf20Sopenharmony_ci */
14708c2ecf20Sopenharmony_citypedef struct xfs_alloc_rec {
14718c2ecf20Sopenharmony_ci	__be32		ar_startblock;	/* starting block number */
14728c2ecf20Sopenharmony_ci	__be32		ar_blockcount;	/* count of free blocks */
14738c2ecf20Sopenharmony_ci} xfs_alloc_rec_t, xfs_alloc_key_t;
14748c2ecf20Sopenharmony_ci
14758c2ecf20Sopenharmony_citypedef struct xfs_alloc_rec_incore {
14768c2ecf20Sopenharmony_ci	xfs_agblock_t	ar_startblock;	/* starting block number */
14778c2ecf20Sopenharmony_ci	xfs_extlen_t	ar_blockcount;	/* count of free blocks */
14788c2ecf20Sopenharmony_ci} xfs_alloc_rec_incore_t;
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_ci/* btree pointer type */
14818c2ecf20Sopenharmony_citypedef __be32 xfs_alloc_ptr_t;
14828c2ecf20Sopenharmony_ci
14838c2ecf20Sopenharmony_ci/*
14848c2ecf20Sopenharmony_ci * Block numbers in the AG:
14858c2ecf20Sopenharmony_ci * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
14868c2ecf20Sopenharmony_ci */
14878c2ecf20Sopenharmony_ci#define	XFS_BNO_BLOCK(mp)	((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
14888c2ecf20Sopenharmony_ci#define	XFS_CNT_BLOCK(mp)	((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
14898c2ecf20Sopenharmony_ci
14908c2ecf20Sopenharmony_ci
14918c2ecf20Sopenharmony_ci/*
14928c2ecf20Sopenharmony_ci * Inode Allocation Btree format definitions
14938c2ecf20Sopenharmony_ci *
14948c2ecf20Sopenharmony_ci * There is a btree for the inode map per allocation group.
14958c2ecf20Sopenharmony_ci */
14968c2ecf20Sopenharmony_ci#define	XFS_IBT_MAGIC		0x49414254	/* 'IABT' */
14978c2ecf20Sopenharmony_ci#define	XFS_IBT_CRC_MAGIC	0x49414233	/* 'IAB3' */
14988c2ecf20Sopenharmony_ci#define	XFS_FIBT_MAGIC		0x46494254	/* 'FIBT' */
14998c2ecf20Sopenharmony_ci#define	XFS_FIBT_CRC_MAGIC	0x46494233	/* 'FIB3' */
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_citypedef uint64_t	xfs_inofree_t;
15028c2ecf20Sopenharmony_ci#define	XFS_INODES_PER_CHUNK		(NBBY * sizeof(xfs_inofree_t))
15038c2ecf20Sopenharmony_ci#define	XFS_INODES_PER_CHUNK_LOG	(XFS_NBBYLOG + 3)
15048c2ecf20Sopenharmony_ci#define	XFS_INOBT_ALL_FREE		((xfs_inofree_t)-1)
15058c2ecf20Sopenharmony_ci#define	XFS_INOBT_MASK(i)		((xfs_inofree_t)1 << (i))
15068c2ecf20Sopenharmony_ci
15078c2ecf20Sopenharmony_ci#define XFS_INOBT_HOLEMASK_FULL		0	/* holemask for full chunk */
15088c2ecf20Sopenharmony_ci#define XFS_INOBT_HOLEMASK_BITS		(NBBY * sizeof(uint16_t))
15098c2ecf20Sopenharmony_ci#define XFS_INODES_PER_HOLEMASK_BIT	\
15108c2ecf20Sopenharmony_ci	(XFS_INODES_PER_CHUNK / (NBBY * sizeof(uint16_t)))
15118c2ecf20Sopenharmony_ci
15128c2ecf20Sopenharmony_cistatic inline xfs_inofree_t xfs_inobt_maskn(int i, int n)
15138c2ecf20Sopenharmony_ci{
15148c2ecf20Sopenharmony_ci	return ((n >= XFS_INODES_PER_CHUNK ? 0 : XFS_INOBT_MASK(n)) - 1) << i;
15158c2ecf20Sopenharmony_ci}
15168c2ecf20Sopenharmony_ci
15178c2ecf20Sopenharmony_ci/*
15188c2ecf20Sopenharmony_ci * The on-disk inode record structure has two formats. The original "full"
15198c2ecf20Sopenharmony_ci * format uses a 4-byte freecount. The "sparse" format uses a 1-byte freecount
15208c2ecf20Sopenharmony_ci * and replaces the 3 high-order freecount bytes wth the holemask and inode
15218c2ecf20Sopenharmony_ci * count.
15228c2ecf20Sopenharmony_ci *
15238c2ecf20Sopenharmony_ci * The holemask of the sparse record format allows an inode chunk to have holes
15248c2ecf20Sopenharmony_ci * that refer to blocks not owned by the inode record. This facilitates inode
15258c2ecf20Sopenharmony_ci * allocation in the event of severe free space fragmentation.
15268c2ecf20Sopenharmony_ci */
15278c2ecf20Sopenharmony_citypedef struct xfs_inobt_rec {
15288c2ecf20Sopenharmony_ci	__be32		ir_startino;	/* starting inode number */
15298c2ecf20Sopenharmony_ci	union {
15308c2ecf20Sopenharmony_ci		struct {
15318c2ecf20Sopenharmony_ci			__be32	ir_freecount;	/* count of free inodes */
15328c2ecf20Sopenharmony_ci		} f;
15338c2ecf20Sopenharmony_ci		struct {
15348c2ecf20Sopenharmony_ci			__be16	ir_holemask;/* hole mask for sparse chunks */
15358c2ecf20Sopenharmony_ci			__u8	ir_count;	/* total inode count */
15368c2ecf20Sopenharmony_ci			__u8	ir_freecount;	/* count of free inodes */
15378c2ecf20Sopenharmony_ci		} sp;
15388c2ecf20Sopenharmony_ci	} ir_u;
15398c2ecf20Sopenharmony_ci	__be64		ir_free;	/* free inode mask */
15408c2ecf20Sopenharmony_ci} xfs_inobt_rec_t;
15418c2ecf20Sopenharmony_ci
15428c2ecf20Sopenharmony_citypedef struct xfs_inobt_rec_incore {
15438c2ecf20Sopenharmony_ci	xfs_agino_t	ir_startino;	/* starting inode number */
15448c2ecf20Sopenharmony_ci	uint16_t	ir_holemask;	/* hole mask for sparse chunks */
15458c2ecf20Sopenharmony_ci	uint8_t		ir_count;	/* total inode count */
15468c2ecf20Sopenharmony_ci	uint8_t		ir_freecount;	/* count of free inodes (set bits) */
15478c2ecf20Sopenharmony_ci	xfs_inofree_t	ir_free;	/* free inode mask */
15488c2ecf20Sopenharmony_ci} xfs_inobt_rec_incore_t;
15498c2ecf20Sopenharmony_ci
15508c2ecf20Sopenharmony_cistatic inline bool xfs_inobt_issparse(uint16_t holemask)
15518c2ecf20Sopenharmony_ci{
15528c2ecf20Sopenharmony_ci	/* non-zero holemask represents a sparse rec. */
15538c2ecf20Sopenharmony_ci	return holemask;
15548c2ecf20Sopenharmony_ci}
15558c2ecf20Sopenharmony_ci
15568c2ecf20Sopenharmony_ci/*
15578c2ecf20Sopenharmony_ci * Key structure
15588c2ecf20Sopenharmony_ci */
15598c2ecf20Sopenharmony_citypedef struct xfs_inobt_key {
15608c2ecf20Sopenharmony_ci	__be32		ir_startino;	/* starting inode number */
15618c2ecf20Sopenharmony_ci} xfs_inobt_key_t;
15628c2ecf20Sopenharmony_ci
15638c2ecf20Sopenharmony_ci/* btree pointer type */
15648c2ecf20Sopenharmony_citypedef __be32 xfs_inobt_ptr_t;
15658c2ecf20Sopenharmony_ci
15668c2ecf20Sopenharmony_ci/*
15678c2ecf20Sopenharmony_ci * block numbers in the AG.
15688c2ecf20Sopenharmony_ci */
15698c2ecf20Sopenharmony_ci#define	XFS_IBT_BLOCK(mp)		((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
15708c2ecf20Sopenharmony_ci#define	XFS_FIBT_BLOCK(mp)		((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
15718c2ecf20Sopenharmony_ci
15728c2ecf20Sopenharmony_ci/*
15738c2ecf20Sopenharmony_ci * Reverse mapping btree format definitions
15748c2ecf20Sopenharmony_ci *
15758c2ecf20Sopenharmony_ci * There is a btree for the reverse map per allocation group
15768c2ecf20Sopenharmony_ci */
15778c2ecf20Sopenharmony_ci#define	XFS_RMAP_CRC_MAGIC	0x524d4233	/* 'RMB3' */
15788c2ecf20Sopenharmony_ci
15798c2ecf20Sopenharmony_ci/*
15808c2ecf20Sopenharmony_ci * Ownership info for an extent.  This is used to create reverse-mapping
15818c2ecf20Sopenharmony_ci * entries.
15828c2ecf20Sopenharmony_ci */
15838c2ecf20Sopenharmony_ci#define XFS_OWNER_INFO_ATTR_FORK	(1 << 0)
15848c2ecf20Sopenharmony_ci#define XFS_OWNER_INFO_BMBT_BLOCK	(1 << 1)
15858c2ecf20Sopenharmony_cistruct xfs_owner_info {
15868c2ecf20Sopenharmony_ci	uint64_t		oi_owner;
15878c2ecf20Sopenharmony_ci	xfs_fileoff_t		oi_offset;
15888c2ecf20Sopenharmony_ci	unsigned int		oi_flags;
15898c2ecf20Sopenharmony_ci};
15908c2ecf20Sopenharmony_ci
15918c2ecf20Sopenharmony_ci/*
15928c2ecf20Sopenharmony_ci * Special owner types.
15938c2ecf20Sopenharmony_ci *
15948c2ecf20Sopenharmony_ci * Seeing as we only support up to 8EB, we have the upper bit of the owner field
15958c2ecf20Sopenharmony_ci * to tell us we have a special owner value. We use these for static metadata
15968c2ecf20Sopenharmony_ci * allocated at mkfs/growfs time, as well as for freespace management metadata.
15978c2ecf20Sopenharmony_ci */
15988c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_NULL	(-1ULL)	/* No owner, for growfs */
15998c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_UNKNOWN	(-2ULL)	/* Unknown owner, for EFI recovery */
16008c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_FS		(-3ULL)	/* static fs metadata */
16018c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_LOG	(-4ULL)	/* static fs metadata */
16028c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_AG		(-5ULL)	/* AG freespace btree blocks */
16038c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_INOBT	(-6ULL)	/* Inode btree blocks */
16048c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_INODES	(-7ULL)	/* Inode chunk */
16058c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_REFC	(-8ULL) /* refcount tree */
16068c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_COW	(-9ULL) /* cow allocations */
16078c2ecf20Sopenharmony_ci#define XFS_RMAP_OWN_MIN	(-10ULL) /* guard */
16088c2ecf20Sopenharmony_ci
16098c2ecf20Sopenharmony_ci#define XFS_RMAP_NON_INODE_OWNER(owner)	(!!((owner) & (1ULL << 63)))
16108c2ecf20Sopenharmony_ci
16118c2ecf20Sopenharmony_ci/*
16128c2ecf20Sopenharmony_ci * Data record structure
16138c2ecf20Sopenharmony_ci */
16148c2ecf20Sopenharmony_cistruct xfs_rmap_rec {
16158c2ecf20Sopenharmony_ci	__be32		rm_startblock;	/* extent start block */
16168c2ecf20Sopenharmony_ci	__be32		rm_blockcount;	/* extent length */
16178c2ecf20Sopenharmony_ci	__be64		rm_owner;	/* extent owner */
16188c2ecf20Sopenharmony_ci	__be64		rm_offset;	/* offset within the owner */
16198c2ecf20Sopenharmony_ci};
16208c2ecf20Sopenharmony_ci
16218c2ecf20Sopenharmony_ci/*
16228c2ecf20Sopenharmony_ci * rmap btree record
16238c2ecf20Sopenharmony_ci *  rm_offset:63 is the attribute fork flag
16248c2ecf20Sopenharmony_ci *  rm_offset:62 is the bmbt block flag
16258c2ecf20Sopenharmony_ci *  rm_offset:61 is the unwritten extent flag (same as l0:63 in bmbt)
16268c2ecf20Sopenharmony_ci *  rm_offset:54-60 aren't used and should be zero
16278c2ecf20Sopenharmony_ci *  rm_offset:0-53 is the block offset within the inode
16288c2ecf20Sopenharmony_ci */
16298c2ecf20Sopenharmony_ci#define XFS_RMAP_OFF_ATTR_FORK	((uint64_t)1ULL << 63)
16308c2ecf20Sopenharmony_ci#define XFS_RMAP_OFF_BMBT_BLOCK	((uint64_t)1ULL << 62)
16318c2ecf20Sopenharmony_ci#define XFS_RMAP_OFF_UNWRITTEN	((uint64_t)1ULL << 61)
16328c2ecf20Sopenharmony_ci
16338c2ecf20Sopenharmony_ci#define XFS_RMAP_LEN_MAX	((uint32_t)~0U)
16348c2ecf20Sopenharmony_ci#define XFS_RMAP_OFF_FLAGS	(XFS_RMAP_OFF_ATTR_FORK | \
16358c2ecf20Sopenharmony_ci				 XFS_RMAP_OFF_BMBT_BLOCK | \
16368c2ecf20Sopenharmony_ci				 XFS_RMAP_OFF_UNWRITTEN)
16378c2ecf20Sopenharmony_ci#define XFS_RMAP_OFF_MASK	((uint64_t)0x3FFFFFFFFFFFFFULL)
16388c2ecf20Sopenharmony_ci
16398c2ecf20Sopenharmony_ci#define XFS_RMAP_OFF(off)		((off) & XFS_RMAP_OFF_MASK)
16408c2ecf20Sopenharmony_ci
16418c2ecf20Sopenharmony_ci#define XFS_RMAP_IS_BMBT_BLOCK(off)	(!!((off) & XFS_RMAP_OFF_BMBT_BLOCK))
16428c2ecf20Sopenharmony_ci#define XFS_RMAP_IS_ATTR_FORK(off)	(!!((off) & XFS_RMAP_OFF_ATTR_FORK))
16438c2ecf20Sopenharmony_ci#define XFS_RMAP_IS_UNWRITTEN(len)	(!!((off) & XFS_RMAP_OFF_UNWRITTEN))
16448c2ecf20Sopenharmony_ci
16458c2ecf20Sopenharmony_ci#define RMAPBT_STARTBLOCK_BITLEN	32
16468c2ecf20Sopenharmony_ci#define RMAPBT_BLOCKCOUNT_BITLEN	32
16478c2ecf20Sopenharmony_ci#define RMAPBT_OWNER_BITLEN		64
16488c2ecf20Sopenharmony_ci#define RMAPBT_ATTRFLAG_BITLEN		1
16498c2ecf20Sopenharmony_ci#define RMAPBT_BMBTFLAG_BITLEN		1
16508c2ecf20Sopenharmony_ci#define RMAPBT_EXNTFLAG_BITLEN		1
16518c2ecf20Sopenharmony_ci#define RMAPBT_UNUSED_OFFSET_BITLEN	7
16528c2ecf20Sopenharmony_ci#define RMAPBT_OFFSET_BITLEN		54
16538c2ecf20Sopenharmony_ci
16548c2ecf20Sopenharmony_ci#define XFS_RMAP_ATTR_FORK		(1 << 0)
16558c2ecf20Sopenharmony_ci#define XFS_RMAP_BMBT_BLOCK		(1 << 1)
16568c2ecf20Sopenharmony_ci#define XFS_RMAP_UNWRITTEN		(1 << 2)
16578c2ecf20Sopenharmony_ci#define XFS_RMAP_KEY_FLAGS		(XFS_RMAP_ATTR_FORK | \
16588c2ecf20Sopenharmony_ci					 XFS_RMAP_BMBT_BLOCK)
16598c2ecf20Sopenharmony_ci#define XFS_RMAP_REC_FLAGS		(XFS_RMAP_UNWRITTEN)
16608c2ecf20Sopenharmony_cistruct xfs_rmap_irec {
16618c2ecf20Sopenharmony_ci	xfs_agblock_t	rm_startblock;	/* extent start block */
16628c2ecf20Sopenharmony_ci	xfs_extlen_t	rm_blockcount;	/* extent length */
16638c2ecf20Sopenharmony_ci	uint64_t	rm_owner;	/* extent owner */
16648c2ecf20Sopenharmony_ci	uint64_t	rm_offset;	/* offset within the owner */
16658c2ecf20Sopenharmony_ci	unsigned int	rm_flags;	/* state flags */
16668c2ecf20Sopenharmony_ci};
16678c2ecf20Sopenharmony_ci
16688c2ecf20Sopenharmony_ci/*
16698c2ecf20Sopenharmony_ci * Key structure
16708c2ecf20Sopenharmony_ci *
16718c2ecf20Sopenharmony_ci * We don't use the length for lookups
16728c2ecf20Sopenharmony_ci */
16738c2ecf20Sopenharmony_cistruct xfs_rmap_key {
16748c2ecf20Sopenharmony_ci	__be32		rm_startblock;	/* extent start block */
16758c2ecf20Sopenharmony_ci	__be64		rm_owner;	/* extent owner */
16768c2ecf20Sopenharmony_ci	__be64		rm_offset;	/* offset within the owner */
16778c2ecf20Sopenharmony_ci} __attribute__((packed));
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci/* btree pointer type */
16808c2ecf20Sopenharmony_citypedef __be32 xfs_rmap_ptr_t;
16818c2ecf20Sopenharmony_ci
16828c2ecf20Sopenharmony_ci#define	XFS_RMAP_BLOCK(mp) \
16838c2ecf20Sopenharmony_ci	(xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \
16848c2ecf20Sopenharmony_ci	 XFS_FIBT_BLOCK(mp) + 1 : \
16858c2ecf20Sopenharmony_ci	 XFS_IBT_BLOCK(mp) + 1)
16868c2ecf20Sopenharmony_ci
16878c2ecf20Sopenharmony_ci/*
16888c2ecf20Sopenharmony_ci * Reference Count Btree format definitions
16898c2ecf20Sopenharmony_ci *
16908c2ecf20Sopenharmony_ci */
16918c2ecf20Sopenharmony_ci#define	XFS_REFC_CRC_MAGIC	0x52334643	/* 'R3FC' */
16928c2ecf20Sopenharmony_ci
16938c2ecf20Sopenharmony_ciunsigned int xfs_refc_block(struct xfs_mount *mp);
16948c2ecf20Sopenharmony_ci
16958c2ecf20Sopenharmony_ci/*
16968c2ecf20Sopenharmony_ci * Data record/key structure
16978c2ecf20Sopenharmony_ci *
16988c2ecf20Sopenharmony_ci * Each record associates a range of physical blocks (starting at
16998c2ecf20Sopenharmony_ci * rc_startblock and ending rc_blockcount blocks later) with a reference
17008c2ecf20Sopenharmony_ci * count (rc_refcount).  Extents that are being used to stage a copy on
17018c2ecf20Sopenharmony_ci * write (CoW) operation are recorded in the refcount btree with a
17028c2ecf20Sopenharmony_ci * refcount of 1.  All other records must have a refcount > 1 and must
17038c2ecf20Sopenharmony_ci * track an extent mapped only by file data forks.
17048c2ecf20Sopenharmony_ci *
17058c2ecf20Sopenharmony_ci * Extents with a single owner (attributes, metadata, non-shared file
17068c2ecf20Sopenharmony_ci * data) are not tracked here.  Free space is also not tracked here.
17078c2ecf20Sopenharmony_ci * This is consistent with pre-reflink XFS.
17088c2ecf20Sopenharmony_ci */
17098c2ecf20Sopenharmony_ci
17108c2ecf20Sopenharmony_ci/*
17118c2ecf20Sopenharmony_ci * Extents that are being used to stage a copy on write are stored
17128c2ecf20Sopenharmony_ci * in the refcount btree with a refcount of 1 and the upper bit set
17138c2ecf20Sopenharmony_ci * on the startblock.  This speeds up mount time deletion of stale
17148c2ecf20Sopenharmony_ci * staging extents because they're all at the right side of the tree.
17158c2ecf20Sopenharmony_ci */
17168c2ecf20Sopenharmony_ci#define XFS_REFC_COW_START		((xfs_agblock_t)(1U << 31))
17178c2ecf20Sopenharmony_ci#define REFCNTBT_COWFLAG_BITLEN		1
17188c2ecf20Sopenharmony_ci#define REFCNTBT_AGBLOCK_BITLEN		31
17198c2ecf20Sopenharmony_ci
17208c2ecf20Sopenharmony_cistruct xfs_refcount_rec {
17218c2ecf20Sopenharmony_ci	__be32		rc_startblock;	/* starting block number */
17228c2ecf20Sopenharmony_ci	__be32		rc_blockcount;	/* count of blocks */
17238c2ecf20Sopenharmony_ci	__be32		rc_refcount;	/* number of inodes linked here */
17248c2ecf20Sopenharmony_ci};
17258c2ecf20Sopenharmony_ci
17268c2ecf20Sopenharmony_cistruct xfs_refcount_key {
17278c2ecf20Sopenharmony_ci	__be32		rc_startblock;	/* starting block number */
17288c2ecf20Sopenharmony_ci};
17298c2ecf20Sopenharmony_ci
17308c2ecf20Sopenharmony_cistruct xfs_refcount_irec {
17318c2ecf20Sopenharmony_ci	xfs_agblock_t	rc_startblock;	/* starting block number */
17328c2ecf20Sopenharmony_ci	xfs_extlen_t	rc_blockcount;	/* count of free blocks */
17338c2ecf20Sopenharmony_ci	xfs_nlink_t	rc_refcount;	/* number of inodes linked here */
17348c2ecf20Sopenharmony_ci};
17358c2ecf20Sopenharmony_ci
17368c2ecf20Sopenharmony_ci#define MAXREFCOUNT	((xfs_nlink_t)~0U)
17378c2ecf20Sopenharmony_ci#define MAXREFCEXTLEN	((xfs_extlen_t)~0U)
17388c2ecf20Sopenharmony_ci
17398c2ecf20Sopenharmony_ci/* btree pointer type */
17408c2ecf20Sopenharmony_citypedef __be32 xfs_refcount_ptr_t;
17418c2ecf20Sopenharmony_ci
17428c2ecf20Sopenharmony_ci
17438c2ecf20Sopenharmony_ci/*
17448c2ecf20Sopenharmony_ci * BMAP Btree format definitions
17458c2ecf20Sopenharmony_ci *
17468c2ecf20Sopenharmony_ci * This includes both the root block definition that sits inside an inode fork
17478c2ecf20Sopenharmony_ci * and the record/pointer formats for the leaf/node in the blocks.
17488c2ecf20Sopenharmony_ci */
17498c2ecf20Sopenharmony_ci#define XFS_BMAP_MAGIC		0x424d4150	/* 'BMAP' */
17508c2ecf20Sopenharmony_ci#define XFS_BMAP_CRC_MAGIC	0x424d4133	/* 'BMA3' */
17518c2ecf20Sopenharmony_ci
17528c2ecf20Sopenharmony_ci/*
17538c2ecf20Sopenharmony_ci * Bmap root header, on-disk form only.
17548c2ecf20Sopenharmony_ci */
17558c2ecf20Sopenharmony_citypedef struct xfs_bmdr_block {
17568c2ecf20Sopenharmony_ci	__be16		bb_level;	/* 0 is a leaf */
17578c2ecf20Sopenharmony_ci	__be16		bb_numrecs;	/* current # of data records */
17588c2ecf20Sopenharmony_ci} xfs_bmdr_block_t;
17598c2ecf20Sopenharmony_ci
17608c2ecf20Sopenharmony_ci/*
17618c2ecf20Sopenharmony_ci * Bmap btree record and extent descriptor.
17628c2ecf20Sopenharmony_ci *  l0:63 is an extent flag (value 1 indicates non-normal).
17638c2ecf20Sopenharmony_ci *  l0:9-62 are startoff.
17648c2ecf20Sopenharmony_ci *  l0:0-8 and l1:21-63 are startblock.
17658c2ecf20Sopenharmony_ci *  l1:0-20 are blockcount.
17668c2ecf20Sopenharmony_ci */
17678c2ecf20Sopenharmony_ci#define BMBT_EXNTFLAG_BITLEN	1
17688c2ecf20Sopenharmony_ci#define BMBT_STARTOFF_BITLEN	54
17698c2ecf20Sopenharmony_ci#define BMBT_STARTBLOCK_BITLEN	52
17708c2ecf20Sopenharmony_ci#define BMBT_BLOCKCOUNT_BITLEN	21
17718c2ecf20Sopenharmony_ci
17728c2ecf20Sopenharmony_ci#define BMBT_STARTOFF_MASK	((1ULL << BMBT_STARTOFF_BITLEN) - 1)
17738c2ecf20Sopenharmony_ci#define BMBT_BLOCKCOUNT_MASK	((1ULL << BMBT_BLOCKCOUNT_BITLEN) - 1)
17748c2ecf20Sopenharmony_ci
17758c2ecf20Sopenharmony_ci/*
17768c2ecf20Sopenharmony_ci * bmbt records have a file offset (block) field that is 54 bits wide, so this
17778c2ecf20Sopenharmony_ci * is the largest xfs_fileoff_t that we ever expect to see.
17788c2ecf20Sopenharmony_ci */
17798c2ecf20Sopenharmony_ci#define XFS_MAX_FILEOFF		(BMBT_STARTOFF_MASK + BMBT_BLOCKCOUNT_MASK)
17808c2ecf20Sopenharmony_ci
17818c2ecf20Sopenharmony_citypedef struct xfs_bmbt_rec {
17828c2ecf20Sopenharmony_ci	__be64			l0, l1;
17838c2ecf20Sopenharmony_ci} xfs_bmbt_rec_t;
17848c2ecf20Sopenharmony_ci
17858c2ecf20Sopenharmony_citypedef uint64_t	xfs_bmbt_rec_base_t;	/* use this for casts */
17868c2ecf20Sopenharmony_citypedef xfs_bmbt_rec_t xfs_bmdr_rec_t;
17878c2ecf20Sopenharmony_ci
17888c2ecf20Sopenharmony_ci/*
17898c2ecf20Sopenharmony_ci * Values and macros for delayed-allocation startblock fields.
17908c2ecf20Sopenharmony_ci */
17918c2ecf20Sopenharmony_ci#define STARTBLOCKVALBITS	17
17928c2ecf20Sopenharmony_ci#define STARTBLOCKMASKBITS	(15 + 20)
17938c2ecf20Sopenharmony_ci#define STARTBLOCKMASK		\
17948c2ecf20Sopenharmony_ci	(((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
17958c2ecf20Sopenharmony_ci
17968c2ecf20Sopenharmony_cistatic inline int isnullstartblock(xfs_fsblock_t x)
17978c2ecf20Sopenharmony_ci{
17988c2ecf20Sopenharmony_ci	return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
17998c2ecf20Sopenharmony_ci}
18008c2ecf20Sopenharmony_ci
18018c2ecf20Sopenharmony_cistatic inline xfs_fsblock_t nullstartblock(int k)
18028c2ecf20Sopenharmony_ci{
18038c2ecf20Sopenharmony_ci	ASSERT(k < (1 << STARTBLOCKVALBITS));
18048c2ecf20Sopenharmony_ci	return STARTBLOCKMASK | (k);
18058c2ecf20Sopenharmony_ci}
18068c2ecf20Sopenharmony_ci
18078c2ecf20Sopenharmony_cistatic inline xfs_filblks_t startblockval(xfs_fsblock_t x)
18088c2ecf20Sopenharmony_ci{
18098c2ecf20Sopenharmony_ci	return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
18108c2ecf20Sopenharmony_ci}
18118c2ecf20Sopenharmony_ci
18128c2ecf20Sopenharmony_ci/*
18138c2ecf20Sopenharmony_ci * Key structure for non-leaf levels of the tree.
18148c2ecf20Sopenharmony_ci */
18158c2ecf20Sopenharmony_citypedef struct xfs_bmbt_key {
18168c2ecf20Sopenharmony_ci	__be64		br_startoff;	/* starting file offset */
18178c2ecf20Sopenharmony_ci} xfs_bmbt_key_t, xfs_bmdr_key_t;
18188c2ecf20Sopenharmony_ci
18198c2ecf20Sopenharmony_ci/* btree pointer type */
18208c2ecf20Sopenharmony_citypedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
18218c2ecf20Sopenharmony_ci
18228c2ecf20Sopenharmony_ci
18238c2ecf20Sopenharmony_ci/*
18248c2ecf20Sopenharmony_ci * Generic Btree block format definitions
18258c2ecf20Sopenharmony_ci *
18268c2ecf20Sopenharmony_ci * This is a combination of the actual format used on disk for short and long
18278c2ecf20Sopenharmony_ci * format btrees.  The first three fields are shared by both format, but the
18288c2ecf20Sopenharmony_ci * pointers are different and should be used with care.
18298c2ecf20Sopenharmony_ci *
18308c2ecf20Sopenharmony_ci * To get the size of the actual short or long form headers please use the size
18318c2ecf20Sopenharmony_ci * macros below.  Never use sizeof(xfs_btree_block).
18328c2ecf20Sopenharmony_ci *
18338c2ecf20Sopenharmony_ci * The blkno, crc, lsn, owner and uuid fields are only available in filesystems
18348c2ecf20Sopenharmony_ci * with the crc feature bit, and all accesses to them must be conditional on
18358c2ecf20Sopenharmony_ci * that flag.
18368c2ecf20Sopenharmony_ci */
18378c2ecf20Sopenharmony_ci/* short form block header */
18388c2ecf20Sopenharmony_cistruct xfs_btree_block_shdr {
18398c2ecf20Sopenharmony_ci	__be32		bb_leftsib;
18408c2ecf20Sopenharmony_ci	__be32		bb_rightsib;
18418c2ecf20Sopenharmony_ci
18428c2ecf20Sopenharmony_ci	__be64		bb_blkno;
18438c2ecf20Sopenharmony_ci	__be64		bb_lsn;
18448c2ecf20Sopenharmony_ci	uuid_t		bb_uuid;
18458c2ecf20Sopenharmony_ci	__be32		bb_owner;
18468c2ecf20Sopenharmony_ci	__le32		bb_crc;
18478c2ecf20Sopenharmony_ci};
18488c2ecf20Sopenharmony_ci
18498c2ecf20Sopenharmony_ci/* long form block header */
18508c2ecf20Sopenharmony_cistruct xfs_btree_block_lhdr {
18518c2ecf20Sopenharmony_ci	__be64		bb_leftsib;
18528c2ecf20Sopenharmony_ci	__be64		bb_rightsib;
18538c2ecf20Sopenharmony_ci
18548c2ecf20Sopenharmony_ci	__be64		bb_blkno;
18558c2ecf20Sopenharmony_ci	__be64		bb_lsn;
18568c2ecf20Sopenharmony_ci	uuid_t		bb_uuid;
18578c2ecf20Sopenharmony_ci	__be64		bb_owner;
18588c2ecf20Sopenharmony_ci	__le32		bb_crc;
18598c2ecf20Sopenharmony_ci	__be32		bb_pad; /* padding for alignment */
18608c2ecf20Sopenharmony_ci};
18618c2ecf20Sopenharmony_ci
18628c2ecf20Sopenharmony_cistruct xfs_btree_block {
18638c2ecf20Sopenharmony_ci	__be32		bb_magic;	/* magic number for block type */
18648c2ecf20Sopenharmony_ci	__be16		bb_level;	/* 0 is a leaf */
18658c2ecf20Sopenharmony_ci	__be16		bb_numrecs;	/* current # of data records */
18668c2ecf20Sopenharmony_ci	union {
18678c2ecf20Sopenharmony_ci		struct xfs_btree_block_shdr s;
18688c2ecf20Sopenharmony_ci		struct xfs_btree_block_lhdr l;
18698c2ecf20Sopenharmony_ci	} bb_u;				/* rest */
18708c2ecf20Sopenharmony_ci};
18718c2ecf20Sopenharmony_ci
18728c2ecf20Sopenharmony_ci/* size of a short form block */
18738c2ecf20Sopenharmony_ci#define XFS_BTREE_SBLOCK_LEN \
18748c2ecf20Sopenharmony_ci	(offsetof(struct xfs_btree_block, bb_u) + \
18758c2ecf20Sopenharmony_ci	 offsetof(struct xfs_btree_block_shdr, bb_blkno))
18768c2ecf20Sopenharmony_ci/* size of a long form block */
18778c2ecf20Sopenharmony_ci#define XFS_BTREE_LBLOCK_LEN \
18788c2ecf20Sopenharmony_ci	(offsetof(struct xfs_btree_block, bb_u) + \
18798c2ecf20Sopenharmony_ci	 offsetof(struct xfs_btree_block_lhdr, bb_blkno))
18808c2ecf20Sopenharmony_ci
18818c2ecf20Sopenharmony_ci/* sizes of CRC enabled btree blocks */
18828c2ecf20Sopenharmony_ci#define XFS_BTREE_SBLOCK_CRC_LEN \
18838c2ecf20Sopenharmony_ci	(offsetof(struct xfs_btree_block, bb_u) + \
18848c2ecf20Sopenharmony_ci	 sizeof(struct xfs_btree_block_shdr))
18858c2ecf20Sopenharmony_ci#define XFS_BTREE_LBLOCK_CRC_LEN \
18868c2ecf20Sopenharmony_ci	(offsetof(struct xfs_btree_block, bb_u) + \
18878c2ecf20Sopenharmony_ci	 sizeof(struct xfs_btree_block_lhdr))
18888c2ecf20Sopenharmony_ci
18898c2ecf20Sopenharmony_ci#define XFS_BTREE_SBLOCK_CRC_OFF \
18908c2ecf20Sopenharmony_ci	offsetof(struct xfs_btree_block, bb_u.s.bb_crc)
18918c2ecf20Sopenharmony_ci#define XFS_BTREE_LBLOCK_CRC_OFF \
18928c2ecf20Sopenharmony_ci	offsetof(struct xfs_btree_block, bb_u.l.bb_crc)
18938c2ecf20Sopenharmony_ci
18948c2ecf20Sopenharmony_ci/*
18958c2ecf20Sopenharmony_ci * On-disk XFS access control list structure.
18968c2ecf20Sopenharmony_ci */
18978c2ecf20Sopenharmony_cistruct xfs_acl_entry {
18988c2ecf20Sopenharmony_ci	__be32	ae_tag;
18998c2ecf20Sopenharmony_ci	__be32	ae_id;
19008c2ecf20Sopenharmony_ci	__be16	ae_perm;
19018c2ecf20Sopenharmony_ci	__be16	ae_pad;		/* fill the implicit hole in the structure */
19028c2ecf20Sopenharmony_ci};
19038c2ecf20Sopenharmony_ci
19048c2ecf20Sopenharmony_cistruct xfs_acl {
19058c2ecf20Sopenharmony_ci	__be32			acl_cnt;
19068c2ecf20Sopenharmony_ci	struct xfs_acl_entry	acl_entry[];
19078c2ecf20Sopenharmony_ci};
19088c2ecf20Sopenharmony_ci
19098c2ecf20Sopenharmony_ci/*
19108c2ecf20Sopenharmony_ci * The number of ACL entries allowed is defined by the on-disk format.
19118c2ecf20Sopenharmony_ci * For v4 superblocks, that is limited to 25 entries. For v5 superblocks, it is
19128c2ecf20Sopenharmony_ci * limited only by the maximum size of the xattr that stores the information.
19138c2ecf20Sopenharmony_ci */
19148c2ecf20Sopenharmony_ci#define XFS_ACL_MAX_ENTRIES(mp)	\
19158c2ecf20Sopenharmony_ci	(xfs_sb_version_hascrc(&mp->m_sb) \
19168c2ecf20Sopenharmony_ci		?  (XFS_XATTR_SIZE_MAX - sizeof(struct xfs_acl)) / \
19178c2ecf20Sopenharmony_ci						sizeof(struct xfs_acl_entry) \
19188c2ecf20Sopenharmony_ci		: 25)
19198c2ecf20Sopenharmony_ci
19208c2ecf20Sopenharmony_ci#define XFS_ACL_SIZE(cnt) \
19218c2ecf20Sopenharmony_ci	(sizeof(struct xfs_acl) + \
19228c2ecf20Sopenharmony_ci		sizeof(struct xfs_acl_entry) * cnt)
19238c2ecf20Sopenharmony_ci
19248c2ecf20Sopenharmony_ci#define XFS_ACL_MAX_SIZE(mp) \
19258c2ecf20Sopenharmony_ci	XFS_ACL_SIZE(XFS_ACL_MAX_ENTRIES((mp)))
19268c2ecf20Sopenharmony_ci
19278c2ecf20Sopenharmony_ci
19288c2ecf20Sopenharmony_ci/* On-disk XFS extended attribute names */
19298c2ecf20Sopenharmony_ci#define SGI_ACL_FILE		"SGI_ACL_FILE"
19308c2ecf20Sopenharmony_ci#define SGI_ACL_DEFAULT		"SGI_ACL_DEFAULT"
19318c2ecf20Sopenharmony_ci#define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
19328c2ecf20Sopenharmony_ci#define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
19338c2ecf20Sopenharmony_ci
19348c2ecf20Sopenharmony_ci#endif /* __XFS_FORMAT_H__ */
1935