xref: /openbmc/linux/fs/xfs/libxfs/xfs_types.h (revision ea01221f)
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 uint64_t	xfs_extnum_t;	/* # of extents in a file */
16 typedef uint32_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 int64_t		xfs_csn_t;	/* CIL sequence number */
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 typedef uint64_t	xfs_rtbxlen_t;	/* rtbitmap extent length in rtextents */
35 
36 typedef int64_t		xfs_srtblock_t;	/* signed version of xfs_rtblock_t */
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  * Minimum and maximum blocksize and sectorsize.
62  * The blocksize upper limit is pretty much arbitrary.
63  * The sectorsize upper limit is due to sizeof(sb_sectsize).
64  * CRC enable filesystems use 512 byte inodes, meaning 512 byte block sizes
65  * cannot be used.
66  */
67 #define XFS_MIN_BLOCKSIZE_LOG	9	/* i.e. 512 bytes */
68 #define XFS_MAX_BLOCKSIZE_LOG	16	/* i.e. 65536 bytes */
69 #define XFS_MIN_BLOCKSIZE	(1 << XFS_MIN_BLOCKSIZE_LOG)
70 #define XFS_MAX_BLOCKSIZE	(1 << XFS_MAX_BLOCKSIZE_LOG)
71 #define XFS_MIN_CRC_BLOCKSIZE	(1 << (XFS_MIN_BLOCKSIZE_LOG + 1))
72 #define XFS_MIN_SECTORSIZE_LOG	9	/* i.e. 512 bytes */
73 #define XFS_MAX_SECTORSIZE_LOG	15	/* i.e. 32768 bytes */
74 #define XFS_MIN_SECTORSIZE	(1 << XFS_MIN_SECTORSIZE_LOG)
75 #define XFS_MAX_SECTORSIZE	(1 << XFS_MAX_SECTORSIZE_LOG)
76 
77 /*
78  * Inode fork identifiers.
79  */
80 #define	XFS_DATA_FORK	0
81 #define	XFS_ATTR_FORK	1
82 #define	XFS_COW_FORK	2
83 
84 #define XFS_WHICHFORK_STRINGS \
85 	{ XFS_DATA_FORK, 	"data" }, \
86 	{ XFS_ATTR_FORK,	"attr" }, \
87 	{ XFS_COW_FORK,		"cow" }
88 
89 /*
90  * Min numbers of data/attr fork btree root pointers.
91  */
92 #define MINDBTPTRS	3
93 #define MINABTPTRS	2
94 
95 /*
96  * MAXNAMELEN is the length (including the terminating null) of
97  * the longest permissible file (component) name.
98  */
99 #define MAXNAMELEN	256
100 
101 /*
102  * This enum is used in string mapping in xfs_trace.h; please keep the
103  * TRACE_DEFINE_ENUMs for it up to date.
104  */
105 typedef enum {
106 	XFS_LOOKUP_EQi, XFS_LOOKUP_LEi, XFS_LOOKUP_GEi
107 } xfs_lookup_t;
108 
109 #define XFS_AG_BTREE_CMP_FORMAT_STR \
110 	{ XFS_LOOKUP_EQi,	"eq" }, \
111 	{ XFS_LOOKUP_LEi,	"le" }, \
112 	{ XFS_LOOKUP_GEi,	"ge" }
113 
114 /*
115  * This enum is used in string mapping in xfs_trace.h and scrub/trace.h;
116  * please keep the TRACE_DEFINE_ENUMs for it up to date.
117  */
118 typedef enum {
119 	XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi,
120 	XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi, XFS_BTNUM_MAX
121 } xfs_btnum_t;
122 
123 #define XFS_BTNUM_STRINGS \
124 	{ XFS_BTNUM_BNOi,	"bnobt" }, \
125 	{ XFS_BTNUM_CNTi,	"cntbt" }, \
126 	{ XFS_BTNUM_RMAPi,	"rmapbt" }, \
127 	{ XFS_BTNUM_BMAPi,	"bmbt" }, \
128 	{ XFS_BTNUM_INOi,	"inobt" }, \
129 	{ XFS_BTNUM_FINOi,	"finobt" }, \
130 	{ XFS_BTNUM_REFCi,	"refcbt" }
131 
132 struct xfs_name {
133 	const unsigned char	*name;
134 	int			len;
135 	int			type;
136 };
137 
138 /*
139  * uid_t and gid_t are hard-coded to 32 bits in the inode.
140  * Hence, an 'id' in a dquot is 32 bits..
141  */
142 typedef uint32_t	xfs_dqid_t;
143 
144 /*
145  * Constants for bit manipulations.
146  */
147 #define	XFS_NBBYLOG	3		/* log2(NBBY) */
148 #define	XFS_WORDLOG	2		/* log2(sizeof(xfs_rtword_t)) */
149 #define	XFS_NBWORDLOG	(XFS_NBBYLOG + XFS_WORDLOG)
150 #define	XFS_NBWORD	(1 << XFS_NBWORDLOG)
151 #define	XFS_WORDMASK	((1 << XFS_WORDLOG) - 1)
152 
153 struct xfs_iext_cursor {
154 	struct xfs_iext_leaf	*leaf;
155 	int			pos;
156 };
157 
158 typedef enum {
159 	XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
160 } xfs_exntst_t;
161 
162 typedef struct xfs_bmbt_irec
163 {
164 	xfs_fileoff_t	br_startoff;	/* starting file offset */
165 	xfs_fsblock_t	br_startblock;	/* starting block number */
166 	xfs_filblks_t	br_blockcount;	/* number of blocks */
167 	xfs_exntst_t	br_state;	/* extent state */
168 } xfs_bmbt_irec_t;
169 
170 enum xfs_refc_domain {
171 	XFS_REFC_DOMAIN_SHARED = 0,
172 	XFS_REFC_DOMAIN_COW,
173 };
174 
175 #define XFS_REFC_DOMAIN_STRINGS \
176 	{ XFS_REFC_DOMAIN_SHARED,	"shared" }, \
177 	{ XFS_REFC_DOMAIN_COW,		"cow" }
178 
179 struct xfs_refcount_irec {
180 	xfs_agblock_t	rc_startblock;	/* starting block number */
181 	xfs_extlen_t	rc_blockcount;	/* count of free blocks */
182 	xfs_nlink_t	rc_refcount;	/* number of inodes linked here */
183 	enum xfs_refc_domain	rc_domain; /* shared or cow staging extent? */
184 };
185 
186 #define XFS_RMAP_ATTR_FORK		(1 << 0)
187 #define XFS_RMAP_BMBT_BLOCK		(1 << 1)
188 #define XFS_RMAP_UNWRITTEN		(1 << 2)
189 #define XFS_RMAP_KEY_FLAGS		(XFS_RMAP_ATTR_FORK | \
190 					 XFS_RMAP_BMBT_BLOCK)
191 #define XFS_RMAP_REC_FLAGS		(XFS_RMAP_UNWRITTEN)
192 struct xfs_rmap_irec {
193 	xfs_agblock_t	rm_startblock;	/* extent start block */
194 	xfs_extlen_t	rm_blockcount;	/* extent length */
195 	uint64_t	rm_owner;	/* extent owner */
196 	uint64_t	rm_offset;	/* offset within the owner */
197 	unsigned int	rm_flags;	/* state flags */
198 };
199 
200 /* per-AG block reservation types */
201 enum xfs_ag_resv_type {
202 	XFS_AG_RESV_NONE = 0,
203 	XFS_AG_RESV_AGFL,
204 	XFS_AG_RESV_METADATA,
205 	XFS_AG_RESV_RMAPBT,
206 };
207 
208 /* Results of scanning a btree keyspace to check occupancy. */
209 enum xbtree_recpacking {
210 	/* None of the keyspace maps to records. */
211 	XBTREE_RECPACKING_EMPTY = 0,
212 
213 	/* Some, but not all, of the keyspace maps to records. */
214 	XBTREE_RECPACKING_SPARSE,
215 
216 	/* The entire keyspace maps to records. */
217 	XBTREE_RECPACKING_FULL,
218 };
219 
220 /*
221  * Type verifier functions
222  */
223 struct xfs_mount;
224 
225 bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
226 bool xfs_verify_fsbext(struct xfs_mount *mp, xfs_fsblock_t fsbno,
227 		xfs_fsblock_t len);
228 
229 bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
230 bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
231 bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
232 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
233 bool xfs_verify_rtext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
234 		xfs_rtblock_t len);
235 bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
236 bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
237 void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
238 		unsigned long long *max);
239 bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off);
240 bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off,
241 		xfs_fileoff_t len);
242 
243 /* Do we support an rt volume having this number of rtextents? */
244 static inline bool
xfs_validate_rtextents(xfs_rtbxlen_t rtextents)245 xfs_validate_rtextents(
246 	xfs_rtbxlen_t		rtextents)
247 {
248 	/* No runt rt volumes */
249 	if (rtextents == 0)
250 		return false;
251 
252 	return true;
253 }
254 
255 #endif	/* __XFS_TYPES_H__ */
256