xref: /linux/fs/xfs/libxfs/xfs_types.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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_rtxlen_t;	/* file extent length in rtextents */
15 typedef uint32_t	xfs_agnumber_t;	/* allocation group number */
16 typedef uint64_t	xfs_extnum_t;	/* # of extents in a file */
17 typedef uint32_t	xfs_aextnum_t;	/* # extents in an attribute fork */
18 typedef int64_t		xfs_fsize_t;	/* bytes in a file */
19 typedef uint64_t	xfs_ufsize_t;	/* unsigned bytes in a file */
20 
21 typedef int32_t		xfs_suminfo_t;	/* type of bitmap summary info */
22 typedef uint32_t	xfs_rtsumoff_t;	/* offset of an rtsummary info word */
23 typedef uint32_t	xfs_rtword_t;	/* word type for bitmap manipulations */
24 
25 typedef int64_t		xfs_lsn_t;	/* log sequence number */
26 typedef int64_t		xfs_csn_t;	/* CIL sequence number */
27 
28 typedef uint32_t	xfs_dablk_t;	/* dir/attr block number (in file) */
29 typedef uint32_t	xfs_dahash_t;	/* dir/attr hash value */
30 
31 typedef uint64_t	xfs_fsblock_t;	/* blockno in filesystem (agno|agbno) */
32 typedef uint64_t	xfs_rfsblock_t;	/* blockno in filesystem (raw) */
33 typedef uint64_t	xfs_rtblock_t;	/* extent (block) in realtime area */
34 typedef uint64_t	xfs_fileoff_t;	/* block number in a file */
35 typedef uint64_t	xfs_filblks_t;	/* number of blocks in a file */
36 typedef uint64_t	xfs_rtxnum_t;	/* rtextent number */
37 typedef uint64_t	xfs_rtbxlen_t;	/* rtbitmap extent length in rtextents */
38 
39 typedef int64_t		xfs_srtblock_t;	/* signed version of xfs_rtblock_t */
40 
41 /*
42  * New verifiers will return the instruction address of the failing check.
43  * NULL means everything is ok.
44  */
45 typedef void *		xfs_failaddr_t;
46 
47 /*
48  * Null values for the types.
49  */
50 #define	NULLFSBLOCK	((xfs_fsblock_t)-1)
51 #define	NULLRFSBLOCK	((xfs_rfsblock_t)-1)
52 #define	NULLRTBLOCK	((xfs_rtblock_t)-1)
53 #define	NULLFILEOFF	((xfs_fileoff_t)-1)
54 
55 #define	NULLAGBLOCK	((xfs_agblock_t)-1)
56 #define	NULLAGNUMBER	((xfs_agnumber_t)-1)
57 
58 #define NULLCOMMITLSN	((xfs_lsn_t)-1)
59 
60 #define	NULLFSINO	((xfs_ino_t)-1)
61 #define	NULLAGINO	((xfs_agino_t)-1)
62 
63 /*
64  * Minimum and maximum blocksize and sectorsize.
65  * The blocksize upper limit is pretty much arbitrary.
66  * The sectorsize upper limit is due to sizeof(sb_sectsize).
67  * CRC enable filesystems use 512 byte inodes, meaning 512 byte block sizes
68  * cannot be used.
69  */
70 #define XFS_MIN_BLOCKSIZE_LOG	9	/* i.e. 512 bytes */
71 #define XFS_MAX_BLOCKSIZE_LOG	16	/* i.e. 65536 bytes */
72 #define XFS_MIN_BLOCKSIZE	(1 << XFS_MIN_BLOCKSIZE_LOG)
73 #define XFS_MAX_BLOCKSIZE	(1 << XFS_MAX_BLOCKSIZE_LOG)
74 #define XFS_MIN_CRC_BLOCKSIZE	(1 << (XFS_MIN_BLOCKSIZE_LOG + 1))
75 #define XFS_MIN_SECTORSIZE_LOG	9	/* i.e. 512 bytes */
76 #define XFS_MAX_SECTORSIZE_LOG	15	/* i.e. 32768 bytes */
77 #define XFS_MIN_SECTORSIZE	(1 << XFS_MIN_SECTORSIZE_LOG)
78 #define XFS_MAX_SECTORSIZE	(1 << XFS_MAX_SECTORSIZE_LOG)
79 
80 /*
81  * Inode fork identifiers.
82  */
83 #define XFS_STAGING_FORK	(-1)	/* fake fork for staging a btree */
84 #define	XFS_DATA_FORK		(0)
85 #define	XFS_ATTR_FORK		(1)
86 #define	XFS_COW_FORK		(2)
87 
88 #define XFS_WHICHFORK_STRINGS \
89 	{ XFS_STAGING_FORK, 	"staging" }, \
90 	{ XFS_DATA_FORK, 	"data" }, \
91 	{ XFS_ATTR_FORK,	"attr" }, \
92 	{ XFS_COW_FORK,		"cow" }
93 
94 /*
95  * Min numbers of data/attr fork btree root pointers.
96  */
97 #define MINDBTPTRS	3
98 #define MINABTPTRS	2
99 
100 /*
101  * MAXNAMELEN is the length (including the terminating null) of
102  * the longest permissible file (component) name.
103  */
104 #define MAXNAMELEN	256
105 
106 /*
107  * This enum is used in string mapping in xfs_trace.h; please keep the
108  * TRACE_DEFINE_ENUMs for it up to date.
109  */
110 typedef enum {
111 	XFS_LOOKUP_EQi, XFS_LOOKUP_LEi, XFS_LOOKUP_GEi
112 } xfs_lookup_t;
113 
114 #define XFS_AG_BTREE_CMP_FORMAT_STR \
115 	{ XFS_LOOKUP_EQi,	"eq" }, \
116 	{ XFS_LOOKUP_LEi,	"le" }, \
117 	{ XFS_LOOKUP_GEi,	"ge" }
118 
119 struct xfs_name {
120 	const unsigned char	*name;
121 	int			len;
122 	int			type;
123 };
124 
125 /*
126  * uid_t and gid_t are hard-coded to 32 bits in the inode.
127  * Hence, an 'id' in a dquot is 32 bits..
128  */
129 typedef uint32_t	xfs_dqid_t;
130 
131 /*
132  * Constants for bit manipulations.
133  */
134 #define	XFS_NBBYLOG	3		/* log2(NBBY) */
135 #define	XFS_WORDLOG	2		/* log2(sizeof(xfs_rtword_t)) */
136 #define	XFS_SUMINFOLOG	2		/* log2(sizeof(xfs_suminfo_t)) */
137 #define	XFS_NBWORDLOG	(XFS_NBBYLOG + XFS_WORDLOG)
138 #define	XFS_NBWORD	(1 << XFS_NBWORDLOG)
139 #define	XFS_WORDMASK	((1 << XFS_WORDLOG) - 1)
140 
141 struct xfs_iext_cursor {
142 	struct xfs_iext_leaf	*leaf;
143 	int			pos;
144 };
145 
146 typedef enum {
147 	XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
148 } xfs_exntst_t;
149 
150 typedef struct xfs_bmbt_irec
151 {
152 	xfs_fileoff_t	br_startoff;	/* starting file offset */
153 	xfs_fsblock_t	br_startblock;	/* starting block number */
154 	xfs_filblks_t	br_blockcount;	/* number of blocks */
155 	xfs_exntst_t	br_state;	/* extent state */
156 } xfs_bmbt_irec_t;
157 
158 enum xfs_refc_domain {
159 	XFS_REFC_DOMAIN_SHARED = 0,
160 	XFS_REFC_DOMAIN_COW,
161 };
162 
163 #define XFS_REFC_DOMAIN_STRINGS \
164 	{ XFS_REFC_DOMAIN_SHARED,	"shared" }, \
165 	{ XFS_REFC_DOMAIN_COW,		"cow" }
166 
167 struct xfs_refcount_irec {
168 	xfs_agblock_t	rc_startblock;	/* starting block number */
169 	xfs_extlen_t	rc_blockcount;	/* count of free blocks */
170 	xfs_nlink_t	rc_refcount;	/* number of inodes linked here */
171 	enum xfs_refc_domain	rc_domain; /* shared or cow staging extent? */
172 };
173 
174 #define XFS_RMAP_ATTR_FORK		(1 << 0)
175 #define XFS_RMAP_BMBT_BLOCK		(1 << 1)
176 #define XFS_RMAP_UNWRITTEN		(1 << 2)
177 #define XFS_RMAP_KEY_FLAGS		(XFS_RMAP_ATTR_FORK | \
178 					 XFS_RMAP_BMBT_BLOCK)
179 #define XFS_RMAP_REC_FLAGS		(XFS_RMAP_UNWRITTEN)
180 struct xfs_rmap_irec {
181 	xfs_agblock_t	rm_startblock;	/* extent start block */
182 	xfs_extlen_t	rm_blockcount;	/* extent length */
183 	uint64_t	rm_owner;	/* extent owner */
184 	uint64_t	rm_offset;	/* offset within the owner */
185 	unsigned int	rm_flags;	/* state flags */
186 };
187 
188 /* per-AG block reservation types */
189 enum xfs_ag_resv_type {
190 	XFS_AG_RESV_NONE = 0,
191 	XFS_AG_RESV_AGFL,
192 	XFS_AG_RESV_METADATA,
193 	XFS_AG_RESV_RMAPBT,
194 
195 	/*
196 	 * Don't increase fdblocks when freeing extent.  This is a pony for
197 	 * the bnobt repair functions to re-free the free space without
198 	 * altering fdblocks.  If you think you need this you're wrong.
199 	 */
200 	XFS_AG_RESV_IGNORE,
201 };
202 
203 /* Results of scanning a btree keyspace to check occupancy. */
204 enum xbtree_recpacking {
205 	/* None of the keyspace maps to records. */
206 	XBTREE_RECPACKING_EMPTY = 0,
207 
208 	/* Some, but not all, of the keyspace maps to records. */
209 	XBTREE_RECPACKING_SPARSE,
210 
211 	/* The entire keyspace maps to records. */
212 	XBTREE_RECPACKING_FULL,
213 };
214 
215 /*
216  * Type verifier functions
217  */
218 struct xfs_mount;
219 
220 bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
221 bool xfs_verify_fsbext(struct xfs_mount *mp, xfs_fsblock_t fsbno,
222 		xfs_fsblock_t len);
223 
224 bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
225 bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
226 bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
227 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
228 bool xfs_verify_rtbext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
229 		xfs_filblks_t len);
230 bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
231 bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
232 void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
233 		unsigned long long *max);
234 bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off);
235 bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off,
236 		xfs_fileoff_t len);
237 
238 #endif	/* __XFS_TYPES_H__ */
239