]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/xfs_types.h
xfs: convert rt extent numbers to xfs_rtxnum_t
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_types.h
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_rtword_t; /* word type for bitmap manipulations */
23
24 typedef int64_t xfs_lsn_t; /* log sequence number */
25 typedef int64_t xfs_csn_t; /* CIL sequence number */
26
27 typedef uint32_t xfs_dablk_t; /* dir/attr block number (in file) */
28 typedef uint32_t xfs_dahash_t; /* dir/attr hash value */
29
30 typedef uint64_t xfs_fsblock_t; /* blockno in filesystem (agno|agbno) */
31 typedef uint64_t xfs_rfsblock_t; /* blockno in filesystem (raw) */
32 typedef uint64_t xfs_rtblock_t; /* extent (block) in realtime area */
33 typedef uint64_t xfs_fileoff_t; /* block number in a file */
34 typedef uint64_t xfs_filblks_t; /* number of blocks in a file */
35 typedef uint64_t xfs_rtxnum_t; /* rtextent number */
36 typedef uint64_t xfs_rtbxlen_t; /* rtbitmap extent length in rtextents */
37
38 typedef int64_t xfs_srtblock_t; /* signed version of xfs_rtblock_t */
39
40 /*
41 * New verifiers will return the instruction address of the failing check.
42 * NULL means everything is ok.
43 */
44 typedef void * xfs_failaddr_t;
45
46 /*
47 * Null values for the types.
48 */
49 #define NULLFSBLOCK ((xfs_fsblock_t)-1)
50 #define NULLRFSBLOCK ((xfs_rfsblock_t)-1)
51 #define NULLRTBLOCK ((xfs_rtblock_t)-1)
52 #define NULLFILEOFF ((xfs_fileoff_t)-1)
53 #define NULLRTEXTNO ((xfs_rtxnum_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_DATA_FORK 0
84 #define XFS_ATTR_FORK 1
85 #define XFS_COW_FORK 2
86
87 #define XFS_WHICHFORK_STRINGS \
88 { XFS_DATA_FORK, "data" }, \
89 { XFS_ATTR_FORK, "attr" }, \
90 { XFS_COW_FORK, "cow" }
91
92 /*
93 * Min numbers of data/attr fork btree root pointers.
94 */
95 #define MINDBTPTRS 3
96 #define MINABTPTRS 2
97
98 /*
99 * MAXNAMELEN is the length (including the terminating null) of
100 * the longest permissible file (component) name.
101 */
102 #define MAXNAMELEN 256
103
104 /*
105 * This enum is used in string mapping in xfs_trace.h; please keep the
106 * TRACE_DEFINE_ENUMs for it up to date.
107 */
108 typedef enum {
109 XFS_LOOKUP_EQi, XFS_LOOKUP_LEi, XFS_LOOKUP_GEi
110 } xfs_lookup_t;
111
112 #define XFS_AG_BTREE_CMP_FORMAT_STR \
113 { XFS_LOOKUP_EQi, "eq" }, \
114 { XFS_LOOKUP_LEi, "le" }, \
115 { XFS_LOOKUP_GEi, "ge" }
116
117 /*
118 * This enum is used in string mapping in xfs_trace.h and scrub/trace.h;
119 * please keep the TRACE_DEFINE_ENUMs for it up to date.
120 */
121 typedef enum {
122 XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi,
123 XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi, XFS_BTNUM_MAX
124 } xfs_btnum_t;
125
126 #define XFS_BTNUM_STRINGS \
127 { XFS_BTNUM_BNOi, "bnobt" }, \
128 { XFS_BTNUM_CNTi, "cntbt" }, \
129 { XFS_BTNUM_RMAPi, "rmapbt" }, \
130 { XFS_BTNUM_BMAPi, "bmbt" }, \
131 { XFS_BTNUM_INOi, "inobt" }, \
132 { XFS_BTNUM_FINOi, "finobt" }, \
133 { XFS_BTNUM_REFCi, "refcbt" }
134
135 struct xfs_name {
136 const unsigned char *name;
137 int len;
138 int type;
139 };
140
141 /*
142 * uid_t and gid_t are hard-coded to 32 bits in the inode.
143 * Hence, an 'id' in a dquot is 32 bits..
144 */
145 typedef uint32_t xfs_dqid_t;
146
147 /*
148 * Constants for bit manipulations.
149 */
150 #define XFS_NBBYLOG 3 /* log2(NBBY) */
151 #define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */
152 #define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG)
153 #define XFS_NBWORD (1 << XFS_NBWORDLOG)
154 #define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1)
155
156 struct xfs_iext_cursor {
157 struct xfs_iext_leaf *leaf;
158 int pos;
159 };
160
161 typedef enum {
162 XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
163 } xfs_exntst_t;
164
165 typedef struct xfs_bmbt_irec
166 {
167 xfs_fileoff_t br_startoff; /* starting file offset */
168 xfs_fsblock_t br_startblock; /* starting block number */
169 xfs_filblks_t br_blockcount; /* number of blocks */
170 xfs_exntst_t br_state; /* extent state */
171 } xfs_bmbt_irec_t;
172
173 enum xfs_refc_domain {
174 XFS_REFC_DOMAIN_SHARED = 0,
175 XFS_REFC_DOMAIN_COW,
176 };
177
178 #define XFS_REFC_DOMAIN_STRINGS \
179 { XFS_REFC_DOMAIN_SHARED, "shared" }, \
180 { XFS_REFC_DOMAIN_COW, "cow" }
181
182 struct xfs_refcount_irec {
183 xfs_agblock_t rc_startblock; /* starting block number */
184 xfs_extlen_t rc_blockcount; /* count of free blocks */
185 xfs_nlink_t rc_refcount; /* number of inodes linked here */
186 enum xfs_refc_domain rc_domain; /* shared or cow staging extent? */
187 };
188
189 #define XFS_RMAP_ATTR_FORK (1 << 0)
190 #define XFS_RMAP_BMBT_BLOCK (1 << 1)
191 #define XFS_RMAP_UNWRITTEN (1 << 2)
192 #define XFS_RMAP_KEY_FLAGS (XFS_RMAP_ATTR_FORK | \
193 XFS_RMAP_BMBT_BLOCK)
194 #define XFS_RMAP_REC_FLAGS (XFS_RMAP_UNWRITTEN)
195 struct xfs_rmap_irec {
196 xfs_agblock_t rm_startblock; /* extent start block */
197 xfs_extlen_t rm_blockcount; /* extent length */
198 uint64_t rm_owner; /* extent owner */
199 uint64_t rm_offset; /* offset within the owner */
200 unsigned int rm_flags; /* state flags */
201 };
202
203 /* per-AG block reservation types */
204 enum xfs_ag_resv_type {
205 XFS_AG_RESV_NONE = 0,
206 XFS_AG_RESV_AGFL,
207 XFS_AG_RESV_METADATA,
208 XFS_AG_RESV_RMAPBT,
209 };
210
211 /* Results of scanning a btree keyspace to check occupancy. */
212 enum xbtree_recpacking {
213 /* None of the keyspace maps to records. */
214 XBTREE_RECPACKING_EMPTY = 0,
215
216 /* Some, but not all, of the keyspace maps to records. */
217 XBTREE_RECPACKING_SPARSE,
218
219 /* The entire keyspace maps to records. */
220 XBTREE_RECPACKING_FULL,
221 };
222
223 /*
224 * Type verifier functions
225 */
226 struct xfs_mount;
227
228 bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
229 bool xfs_verify_fsbext(struct xfs_mount *mp, xfs_fsblock_t fsbno,
230 xfs_fsblock_t len);
231
232 bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
233 bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
234 bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
235 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
236 bool xfs_verify_rtbext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
237 xfs_filblks_t len);
238 bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
239 bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
240 void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
241 unsigned long long *max);
242 bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off);
243 bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off,
244 xfs_fileoff_t len);
245
246 #endif /* __XFS_TYPES_H__ */