1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_TYPES_H__
7 #define	__XFS_TYPES_H__
8 
9 typedef uint32_t	prid_t;		/* project ID */
10 
11 typedef uint32_t	xfs_agblock_t;	/* blockno in alloc. group */
12 typedef uint32_t	xfs_agino_t;	/* inode # within allocation grp */
13 typedef uint32_t	xfs_extlen_t;	/* extent length in blocks */
14 typedef uint32_t	xfs_agnumber_t;	/* allocation group number */
15 typedef int32_t		xfs_extnum_t;	/* # of extents in a file */
16 typedef int16_t		xfs_aextnum_t;	/* # extents in an attribute fork */
17 typedef int64_t		xfs_fsize_t;	/* bytes in a file */
18 typedef uint64_t	xfs_ufsize_t;	/* unsigned bytes in a file */
19 
20 typedef int32_t		xfs_suminfo_t;	/* type of bitmap summary info */
21 typedef uint32_t	xfs_rtword_t;	/* word type for bitmap manipulations */
22 
23 typedef int64_t		xfs_lsn_t;	/* log sequence number */
24 typedef int32_t		xfs_tid_t;	/* transaction identifier */
25 
26 typedef uint32_t	xfs_dablk_t;	/* dir/attr block number (in file) */
27 typedef uint32_t	xfs_dahash_t;	/* dir/attr hash value */
28 
29 typedef uint64_t	xfs_fsblock_t;	/* blockno in filesystem (agno|agbno) */
30 typedef uint64_t	xfs_rfsblock_t;	/* blockno in filesystem (raw) */
31 typedef uint64_t	xfs_rtblock_t;	/* extent (block) in realtime area */
32 typedef uint64_t	xfs_fileoff_t;	/* block number in a file */
33 typedef uint64_t	xfs_filblks_t;	/* number of blocks in a file */
34 
35 typedef int64_t		xfs_srtblock_t;	/* signed version of xfs_rtblock_t */
36 typedef int64_t		xfs_sfiloff_t;	/* signed block number in a file */
37 
38 /*
39  * New verifiers will return the instruction address of the failing check.
40  * NULL means everything is ok.
41  */
42 typedef void *		xfs_failaddr_t;
43 
44 /*
45  * Null values for the types.
46  */
47 #define	NULLFSBLOCK	((xfs_fsblock_t)-1)
48 #define	NULLRFSBLOCK	((xfs_rfsblock_t)-1)
49 #define	NULLRTBLOCK	((xfs_rtblock_t)-1)
50 #define	NULLFILEOFF	((xfs_fileoff_t)-1)
51 
52 #define	NULLAGBLOCK	((xfs_agblock_t)-1)
53 #define	NULLAGNUMBER	((xfs_agnumber_t)-1)
54 
55 #define NULLCOMMITLSN	((xfs_lsn_t)-1)
56 
57 #define	NULLFSINO	((xfs_ino_t)-1)
58 #define	NULLAGINO	((xfs_agino_t)-1)
59 
60 /*
61  * Max values for extlen, extnum, aextnum.
62  */
63 #define	MAXEXTLEN	((xfs_extlen_t)0x001fffff)	/* 21 bits */
64 #define	MAXEXTNUM	((xfs_extnum_t)0x7fffffff)	/* signed int */
65 #define	MAXAEXTNUM	((xfs_aextnum_t)0x7fff)		/* signed short */
66 
67 /*
68  * Minimum and maximum blocksize and sectorsize.
69  * The blocksize upper limit is pretty much arbitrary.
70  * The sectorsize upper limit is due to sizeof(sb_sectsize).
71  * CRC enable filesystems use 512 byte inodes, meaning 512 byte block sizes
72  * cannot be used.
73  */
74 #define XFS_MIN_BLOCKSIZE_LOG	9	/* i.e. 512 bytes */
75 #define XFS_MAX_BLOCKSIZE_LOG	16	/* i.e. 65536 bytes */
76 #define XFS_MIN_BLOCKSIZE	(1 << XFS_MIN_BLOCKSIZE_LOG)
77 #define XFS_MAX_BLOCKSIZE	(1 << XFS_MAX_BLOCKSIZE_LOG)
78 #define XFS_MIN_CRC_BLOCKSIZE	(1 << (XFS_MIN_BLOCKSIZE_LOG + 1))
79 #define XFS_MIN_SECTORSIZE_LOG	9	/* i.e. 512 bytes */
80 #define XFS_MAX_SECTORSIZE_LOG	15	/* i.e. 32768 bytes */
81 #define XFS_MIN_SECTORSIZE	(1 << XFS_MIN_SECTORSIZE_LOG)
82 #define XFS_MAX_SECTORSIZE	(1 << XFS_MAX_SECTORSIZE_LOG)
83 
84 /*
85  * Inode fork identifiers.
86  */
87 #define	XFS_DATA_FORK	0
88 #define	XFS_ATTR_FORK	1
89 #define	XFS_COW_FORK	2
90 
91 /*
92  * Min numbers of data/attr fork btree root pointers.
93  */
94 #define MINDBTPTRS	3
95 #define MINABTPTRS	2
96 
97 /*
98  * MAXNAMELEN is the length (including the terminating null) of
99  * the longest permissible file (component) name.
100  */
101 #define MAXNAMELEN	256
102 
103 typedef enum {
104 	XFS_LOOKUP_EQi, XFS_LOOKUP_LEi, XFS_LOOKUP_GEi
105 } xfs_lookup_t;
106 
107 typedef enum {
108 	XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi,
109 	XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi, XFS_BTNUM_MAX
110 } xfs_btnum_t;
111 
112 struct xfs_name {
113 	const unsigned char	*name;
114 	int			len;
115 	int			type;
116 };
117 
118 /*
119  * uid_t and gid_t are hard-coded to 32 bits in the inode.
120  * Hence, an 'id' in a dquot is 32 bits..
121  */
122 typedef uint32_t	xfs_dqid_t;
123 
124 /*
125  * Constants for bit manipulations.
126  */
127 #define	XFS_NBBYLOG	3		/* log2(NBBY) */
128 #define	XFS_WORDLOG	2		/* log2(sizeof(xfs_rtword_t)) */
129 #define	XFS_NBWORDLOG	(XFS_NBBYLOG + XFS_WORDLOG)
130 #define	XFS_NBWORD	(1 << XFS_NBWORDLOG)
131 #define	XFS_WORDMASK	((1 << XFS_WORDLOG) - 1)
132 
133 struct xfs_iext_cursor {
134 	struct xfs_iext_leaf	*leaf;
135 	int			pos;
136 };
137 
138 typedef enum {
139 	XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
140 } xfs_exntst_t;
141 
142 typedef struct xfs_bmbt_irec
143 {
144 	xfs_fileoff_t	br_startoff;	/* starting file offset */
145 	xfs_fsblock_t	br_startblock;	/* starting block number */
146 	xfs_filblks_t	br_blockcount;	/* number of blocks */
147 	xfs_exntst_t	br_state;	/* extent state */
148 } xfs_bmbt_irec_t;
149 
150 /*
151  * Type verifier functions
152  */
153 struct xfs_mount;
154 
155 xfs_agblock_t xfs_ag_block_count(struct xfs_mount *mp, xfs_agnumber_t agno);
156 bool xfs_verify_agbno(struct xfs_mount *mp, xfs_agnumber_t agno,
157 		xfs_agblock_t agbno);
158 bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
159 
160 void xfs_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno,
161 		xfs_agino_t *first, xfs_agino_t *last);
162 bool xfs_verify_agino(struct xfs_mount *mp, xfs_agnumber_t agno,
163 		xfs_agino_t agino);
164 bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
165 bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
166 bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
167 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
168 bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
169 
170 #endif	/* __XFS_TYPES_H__ */
171