]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2bd0ea18 | 2 | /* |
f302e9e4 NS |
3 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
2bd0ea18 | 5 | */ |
5e656dbb | 6 | |
2bd0ea18 NS |
7 | #ifndef __LIBXFS_H__ |
8 | #define __LIBXFS_H__ | |
9 | ||
3a7e14f9 DW |
10 | /* CONFIG_XFS_* must be defined to 1 to work with IS_ENABLED() */ |
11 | ||
d27e715c | 12 | /* For userspace XFS_RT is always defined */ |
3a7e14f9 | 13 | #define CONFIG_XFS_RT 1 |
d466c866 | 14 | /* Ditto in-memory btrees */ |
3a7e14f9 | 15 | #define CONFIG_XFS_BTREE_IN_MEM 1 |
d27e715c | 16 | |
6b803e5a CH |
17 | #include "libxfs_api_defs.h" |
18 | #include "platform_defs.h" | |
dcabd4e7 | 19 | #include "xfs.h" |
2bd0ea18 | 20 | |
6b803e5a CH |
21 | #include "list.h" |
22 | #include "hlist.h" | |
23 | #include "cache.h" | |
24 | #include "bitops.h" | |
25 | #include "kmem.h" | |
8bf7924e | 26 | #include "libfrog/radix-tree.h" |
03dc2ef2 | 27 | #include "libfrog/bitmask.h" |
af71e8c1 | 28 | #include "libfrog/div64.h" |
6b803e5a | 29 | #include "atomic.h" |
686bddf9 | 30 | #include "spinlock.h" |
f1b058f9 | 31 | |
6b803e5a CH |
32 | #include "xfs_types.h" |
33 | #include "xfs_fs.h" | |
34 | #include "xfs_arch.h" | |
2d4bfb91 | 35 | |
6b803e5a CH |
36 | #include "xfs_shared.h" |
37 | #include "xfs_format.h" | |
38 | #include "xfs_log_format.h" | |
39 | #include "xfs_quota_defs.h" | |
40 | #include "xfs_trans_resv.h" | |
2d4bfb91 | 41 | |
b626fb59 DC |
42 | |
43 | /* CRC stuff, buffer API dependent on it */ | |
b626fb59 | 44 | extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len); |
b626fb59 DC |
45 | #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l)) |
46 | ||
75f533e6 CH |
47 | /* fake up kernel's iomap, (not) used in xfs_bmap.[ch] */ |
48 | struct iomap; | |
6b803e5a | 49 | #include "xfs_cksum.h" |
b626fb59 | 50 | |
e778c95d CH |
51 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) |
52 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) | |
e169cc9b | 53 | #define unlikely(x) (x) |
ccffd2f9 | 54 | #define likely(x) (x) |
e778c95d | 55 | |
b626fb59 DC |
56 | /* |
57 | * This mirrors the kernel include for xfs_buf.h - it's implicitly included in | |
58 | * every files via a similar include in the kernel xfs_linux.h. | |
59 | */ | |
6b803e5a CH |
60 | #include "libxfs_io.h" |
61 | ||
62 | #include "xfs_bit.h" | |
63 | #include "xfs_sb.h" | |
64 | #include "xfs_mount.h" | |
f944d3d0 | 65 | #include "xfs_defer.h" |
904d9719 | 66 | #include "xfs_errortag.h" |
6b803e5a CH |
67 | #include "xfs_da_format.h" |
68 | #include "xfs_da_btree.h" | |
e169cc9b | 69 | #include "xfs_inode.h" |
6b803e5a | 70 | #include "xfs_dir2.h" |
bd045c51 | 71 | #include "xfs_dir2_priv.h" |
6b803e5a CH |
72 | #include "xfs_bmap_btree.h" |
73 | #include "xfs_alloc_btree.h" | |
74 | #include "xfs_ialloc_btree.h" | |
c749b4e1 | 75 | #include "xfs_attr.h" |
6b803e5a CH |
76 | #include "xfs_attr_sf.h" |
77 | #include "xfs_inode_fork.h" | |
78 | #include "xfs_inode_buf.h" | |
fadb819b | 79 | #include "xfs_inode_util.h" |
6b803e5a CH |
80 | #include "xfs_alloc.h" |
81 | #include "xfs_btree.h" | |
6b803e5a CH |
82 | #include "xfs_bmap.h" |
83 | #include "xfs_trace.h" | |
84 | #include "xfs_trans.h" | |
7b754805 | 85 | #include "xfs_ag.h" |
631ac87a | 86 | #include "xfs_rmap_btree.h" |
794a5604 | 87 | #include "xfs_rmap.h" |
e7be6330 | 88 | #include "xfs_refcount_btree.h" |
4b7bd081 | 89 | #include "xfs_rtrefcount_btree.h" |
db17bb0e | 90 | #include "xfs_refcount.h" |
49031e66 | 91 | #include "xfs_btree_staging.h" |
d27e715c | 92 | #include "xfs_rtbitmap.h" |
ce160fd9 | 93 | #include "xfs_symlink_remote.h" |
6de18ea1 DW |
94 | #include "libxfs/xfile.h" |
95 | #include "libxfs/buf_mem.h" | |
96 | #include "xfs_btree_mem.h" | |
4bba3a07 | 97 | #include "xfs_parent.h" |
1bb554e3 | 98 | #include "xfs_ag_resv.h" |
3c2daed2 | 99 | #include "xfs_metafile.h" |
1be54c61 | 100 | #include "xfs_metadir.h" |
001b79f0 | 101 | #include "xfs_rtgroup.h" |
1278e817 | 102 | #include "xfs_rtbitmap.h" |
17b28712 | 103 | #include "xfs_rtrmap_btree.h" |
40c35393 | 104 | #include "xfs_ag_resv.h" |
cc085d77 | 105 | |
1167ddc4 AE |
106 | #ifndef ARRAY_SIZE |
107 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | |
108 | #endif | |
2bd0ea18 | 109 | |
b391b7cd NS |
110 | #ifndef XFS_SUPER_MAGIC |
111 | #define XFS_SUPER_MAGIC 0x58465342 | |
112 | #endif | |
113 | ||
de2f203d | 114 | #define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY)))) |
a580302f | 115 | |
fc83c757 CH |
116 | struct libxfs_dev { |
117 | /* input parameters */ | |
118 | char *name; /* pathname of the device */ | |
119 | bool isfile; /* is the device a file? */ | |
120 | bool create; /* create file if it doesn't exist */ | |
121 | ||
122 | /* output parameters */ | |
123 | dev_t dev; /* device name for the device */ | |
124 | long long size; /* size of subvolume (BBs) */ | |
125 | int bsize; /* device blksize */ | |
126 | int fd; /* file descriptor */ | |
127 | }; | |
128 | ||
2bd0ea18 NS |
129 | /* |
130 | * Argument structure for libxfs_init(). | |
131 | */ | |
01dcfd9e | 132 | struct libxfs_init { |
fc83c757 CH |
133 | struct libxfs_dev data; |
134 | struct libxfs_dev log; | |
135 | struct libxfs_dev rt; | |
136 | ||
137 | /* input parameters */ | |
23d88955 | 138 | unsigned flags; /* LIBXFS_* flags below */ |
ba9ecd40 | 139 | int bcache_flags; /* cache init flags */ |
fc83c757 | 140 | int setblksize; /* value to set device blksizes to */ |
01dcfd9e | 141 | }; |
2bd0ea18 | 142 | |
23d88955 CH |
143 | /* disallow all mounted filesystems: */ |
144 | #define LIBXFS_ISREADONLY (1U << 0) | |
145 | ||
146 | /* allow mounted only if mounted ro: */ | |
147 | #define LIBXFS_ISINACTIVE (1U << 1) | |
148 | ||
149 | /* repairing a device mounted ro: */ | |
150 | #define LIBXFS_DANGEROUSLY (1U << 2) | |
151 | ||
152 | /* disallow other accesses (O_EXCL): */ | |
153 | #define LIBXFS_EXCLUSIVELY (1U << 3) | |
154 | ||
155 | /* can use direct I/O, not buffered: */ | |
156 | #define LIBXFS_DIRECT (1U << 4) | |
157 | ||
158 | /* lock xfs_buf's - for MT usage */ | |
159 | #define LIBXFS_USEBUFLOCK (1U << 5) | |
2bd0ea18 NS |
160 | |
161 | extern char *progname; | |
7d77349c | 162 | extern xfs_lsn_t libxfs_max_lsn; |
01dcfd9e CH |
163 | |
164 | int libxfs_init(struct libxfs_init *); | |
165 | void libxfs_destroy(struct libxfs_init *li); | |
166 | ||
b74a1f6a | 167 | extern int libxfs_device_alignment (void); |
2bd0ea18 NS |
168 | |
169 | /* check or write log footer: specify device, log size in blocks & uuid */ | |
d60ba955 | 170 | typedef char *(libxfs_get_block_t)(char *, int, void *); |
989b74bc | 171 | |
0c12ba5f BF |
172 | /* |
173 | * Helpers to clear the log to a particular log cycle. | |
174 | */ | |
175 | #define XLOG_INIT_CYCLE 1 | |
1c12a814 | 176 | extern int libxfs_log_clear(struct xfs_buftarg *, char *, xfs_daddr_t, |
571a78a7 | 177 | uint, uuid_t *, int, int, int, int, bool); |
0c12ba5f BF |
178 | extern int libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t, |
179 | xfs_lsn_t, libxfs_get_block_t *, void *); | |
989b74bc | 180 | |
75c8b434 | 181 | |
5e656dbb | 182 | /* Shared utility routines */ |
2bd0ea18 | 183 | |
b48164b8 DW |
184 | int libxfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset, |
185 | xfs_off_t len, uint32_t bmapi_flags); | |
73fb78e5 DW |
186 | int libxfs_file_write(struct xfs_inode *ip, void *buf, off_t pos, |
187 | size_t len); | |
2bd0ea18 | 188 | |
b626fb59 DC |
189 | /* XXX: this is messy and needs fixing */ |
190 | #ifndef __LIBXFS_INTERNAL_XFS_H__ | |
1552a820 NS |
191 | extern void cmn_err(int, char *, ...); |
192 | enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC }; | |
b626fb59 | 193 | #endif |
f302e9e4 | 194 | |
6b803e5a | 195 | #include "xfs_ialloc.h" |
f302e9e4 | 196 | |
6b803e5a CH |
197 | #include "xfs_attr_leaf.h" |
198 | #include "xfs_attr_remote.h" | |
199 | #include "xfs_trans_space.h" | |
f302e9e4 | 200 | |
5e656dbb BN |
201 | #define XFS_INOBT_IS_FREE_DISK(rp,i) \ |
202 | ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0) | |
56b2de80 | 203 | |
c749bd55 BF |
204 | static inline bool |
205 | xfs_inobt_is_sparse_disk( | |
206 | struct xfs_inobt_rec *rp, | |
207 | int offset) | |
208 | { | |
209 | int spshift; | |
210 | uint16_t holemask; | |
211 | ||
212 | holemask = be16_to_cpu(rp->ir_u.sp.ir_holemask); | |
213 | spshift = offset / XFS_INODES_PER_HOLEMASK_BIT; | |
214 | if ((1 << spshift) & holemask) | |
215 | return true; | |
216 | ||
217 | return false; | |
218 | } | |
219 | ||
ff105f75 DC |
220 | static inline void |
221 | libxfs_bmbt_disk_get_all( | |
b37d753d | 222 | struct xfs_bmbt_rec *rec, |
ff105f75 DC |
223 | struct xfs_bmbt_irec *irec) |
224 | { | |
b37d753d CH |
225 | uint64_t l0 = get_unaligned_be64(&rec->l0); |
226 | uint64_t l1 = get_unaligned_be64(&rec->l1); | |
227 | ||
228 | irec->br_startoff = (l0 & xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9; | |
229 | irec->br_startblock = ((l0 & xfs_mask64lo(9)) << 43) | (l1 >> 21); | |
230 | irec->br_blockcount = l1 & xfs_mask64lo(21); | |
231 | if (l0 >> (64 - BMBT_EXNTFLAG_BITLEN)) | |
232 | irec->br_state = XFS_EXT_UNWRITTEN; | |
233 | else | |
234 | irec->br_state = XFS_EXT_NORM; | |
ff105f75 | 235 | } |
5e656dbb | 236 | |
6778635b | 237 | #include "xfs_attr.h" |
6bc3531c | 238 | #include "topology.h" |
e515cca1 | 239 | |
586d90c3 DC |
240 | /* |
241 | * Superblock helpers for programs that act on independent superblock | |
242 | * structures. These used to be part of xfs_format.h. | |
243 | */ | |
244 | static inline bool xfs_sb_version_haslazysbcount(struct xfs_sb *sbp) | |
245 | { | |
246 | return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) || | |
247 | (xfs_sb_version_hasmorebits(sbp) && | |
248 | (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT)); | |
249 | } | |
250 | ||
251 | static inline bool xfs_sb_version_hascrc(struct xfs_sb *sbp) | |
252 | { | |
253 | return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5; | |
254 | } | |
255 | ||
256 | static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) | |
257 | { | |
258 | return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) && | |
259 | (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_META_UUID); | |
260 | } | |
261 | ||
262 | static inline bool xfs_sb_version_hasalign(struct xfs_sb *sbp) | |
263 | { | |
264 | return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 || | |
265 | (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT)); | |
266 | } | |
267 | ||
268 | static inline bool xfs_sb_version_hasdalign(struct xfs_sb *sbp) | |
269 | { | |
270 | return (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT); | |
271 | } | |
272 | ||
273 | static inline bool xfs_sb_version_haslogv2(struct xfs_sb *sbp) | |
274 | { | |
275 | return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 || | |
276 | (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT); | |
277 | } | |
278 | ||
279 | static inline bool xfs_sb_version_hassector(struct xfs_sb *sbp) | |
280 | { | |
281 | return (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT); | |
282 | } | |
283 | ||
284 | static inline bool xfs_sb_version_needsrepair(struct xfs_sb *sbp) | |
285 | { | |
286 | return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 && | |
287 | (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR); | |
288 | } | |
289 | ||
290 | static inline bool xfs_sb_version_hassparseinodes(struct xfs_sb *sbp) | |
291 | { | |
292 | return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 && | |
293 | xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_SPINODES); | |
294 | } | |
295 | ||
9840f7e0 CH |
296 | static inline bool xfs_sb_version_haszoned(struct xfs_sb *sbp) |
297 | { | |
298 | return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 && | |
299 | xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_ZONED); | |
300 | } | |
301 | ||
2bd0ea18 | 302 | #endif /* __LIBXFS_H__ */ |