]>
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 | ||
6b803e5a CH |
10 | #include "libxfs_api_defs.h" |
11 | #include "platform_defs.h" | |
dcabd4e7 | 12 | #include "xfs.h" |
2bd0ea18 | 13 | |
6b803e5a CH |
14 | #include "list.h" |
15 | #include "hlist.h" | |
16 | #include "cache.h" | |
17 | #include "bitops.h" | |
18 | #include "kmem.h" | |
19 | #include "radix-tree.h" | |
20 | #include "atomic.h" | |
f1b058f9 | 21 | |
6b803e5a CH |
22 | #include "xfs_types.h" |
23 | #include "xfs_fs.h" | |
24 | #include "xfs_arch.h" | |
2d4bfb91 | 25 | |
6b803e5a CH |
26 | #include "xfs_shared.h" |
27 | #include "xfs_format.h" | |
28 | #include "xfs_log_format.h" | |
29 | #include "xfs_quota_defs.h" | |
30 | #include "xfs_trans_resv.h" | |
2d4bfb91 | 31 | |
b626fb59 DC |
32 | |
33 | /* CRC stuff, buffer API dependent on it */ | |
b626fb59 | 34 | extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len); |
b626fb59 DC |
35 | #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l)) |
36 | ||
6b803e5a | 37 | #include "xfs_cksum.h" |
b626fb59 DC |
38 | |
39 | /* | |
40 | * This mirrors the kernel include for xfs_buf.h - it's implicitly included in | |
41 | * every files via a similar include in the kernel xfs_linux.h. | |
42 | */ | |
6b803e5a CH |
43 | #include "libxfs_io.h" |
44 | ||
45 | #include "xfs_bit.h" | |
46 | #include "xfs_sb.h" | |
47 | #include "xfs_mount.h" | |
f944d3d0 | 48 | #include "xfs_defer.h" |
904d9719 | 49 | #include "xfs_errortag.h" |
6b803e5a CH |
50 | #include "xfs_da_format.h" |
51 | #include "xfs_da_btree.h" | |
52 | #include "xfs_dir2.h" | |
53 | #include "xfs_bmap_btree.h" | |
54 | #include "xfs_alloc_btree.h" | |
55 | #include "xfs_ialloc_btree.h" | |
56 | #include "xfs_attr_sf.h" | |
57 | #include "xfs_inode_fork.h" | |
58 | #include "xfs_inode_buf.h" | |
59 | #include "xfs_inode.h" | |
60 | #include "xfs_alloc.h" | |
61 | #include "xfs_btree.h" | |
62 | #include "xfs_btree_trace.h" | |
63 | #include "xfs_bmap.h" | |
64 | #include "xfs_trace.h" | |
65 | #include "xfs_trans.h" | |
631ac87a | 66 | #include "xfs_rmap_btree.h" |
794a5604 | 67 | #include "xfs_rmap.h" |
e7be6330 | 68 | #include "xfs_refcount_btree.h" |
db17bb0e | 69 | #include "xfs_refcount.h" |
cc085d77 | 70 | |
1167ddc4 AE |
71 | #ifndef ARRAY_SIZE |
72 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | |
73 | #endif | |
2bd0ea18 | 74 | |
b391b7cd NS |
75 | #ifndef XFS_SUPER_MAGIC |
76 | #define XFS_SUPER_MAGIC 0x58465342 | |
77 | #endif | |
78 | ||
de2f203d | 79 | #define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY)))) |
a580302f | 80 | |
2bd0ea18 NS |
81 | /* |
82 | * Argument structure for libxfs_init(). | |
83 | */ | |
cf627f3c | 84 | typedef struct libxfs_xinit { |
dfc130f3 RC |
85 | /* input parameters */ |
86 | char *volname; /* pathname of volume */ | |
87 | char *dname; /* pathname of data "subvolume" */ | |
88 | char *logname; /* pathname of log "subvolume" */ | |
89 | char *rtname; /* pathname of realtime "subvolume" */ | |
90 | int isreadonly; /* filesystem is only read in applic */ | |
b74a1f6a | 91 | int isdirect; /* we can attempt to use direct I/O */ |
d0572de5 BN |
92 | int disfile; /* data "subvolume" is a regular file */ |
93 | int dcreat; /* try to create data subvolume */ | |
dfc130f3 RC |
94 | int lisfile; /* log "subvolume" is a regular file */ |
95 | int lcreat; /* try to create log subvolume */ | |
d0572de5 BN |
96 | int risfile; /* realtime "subvolume" is a reg file */ |
97 | int rcreat; /* try to create realtime subvolume */ | |
74668075 | 98 | int setblksize; /* attempt to set device blksize */ |
d0572de5 | 99 | int usebuflock; /* lock xfs_buf_t's - for MT usage */ |
dfc130f3 RC |
100 | /* output results */ |
101 | dev_t ddev; /* device for data subvolume */ | |
102 | dev_t logdev; /* device for log subvolume */ | |
103 | dev_t rtdev; /* device for realtime subvolume */ | |
104 | long long dsize; /* size of data subvolume (BBs) */ | |
105 | long long logBBsize; /* size of log subvolume (BBs) */ | |
106 | /* (blocks allocated for use as | |
107 | * log is stored in mount structure) */ | |
74668075 NS |
108 | long long logBBstart; /* start block of log subvolume (BBs) */ |
109 | long long rtsize; /* size of realtime subvolume (BBs) */ | |
110 | int dbsize; /* data subvolume device blksize */ | |
111 | int lbsize; /* log subvolume device blksize */ | |
112 | int rtbsize; /* realtime subvolume device blksize */ | |
dfc130f3 RC |
113 | int dfd; /* data subvolume file descriptor */ |
114 | int logfd; /* log subvolume file descriptor */ | |
115 | int rtfd; /* realtime subvolume file descriptor */ | |
ba9ecd40 DC |
116 | int icache_flags; /* cache init flags */ |
117 | int bcache_flags; /* cache init flags */ | |
2bd0ea18 NS |
118 | } libxfs_init_t; |
119 | ||
9440d84d NS |
120 | #define LIBXFS_EXIT_ON_FAILURE 0x0001 /* exit the program if a call fails */ |
121 | #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */ | |
122 | #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */ | |
7eb6693f NS |
123 | #define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */ |
124 | #define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */ | |
b74a1f6a | 125 | #define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */ |
2bd0ea18 NS |
126 | |
127 | extern char *progname; | |
7d77349c | 128 | extern xfs_lsn_t libxfs_max_lsn; |
2bd0ea18 | 129 | extern int libxfs_init (libxfs_init_t *); |
f1b058f9 | 130 | extern void libxfs_destroy (void); |
2bd0ea18 | 131 | extern int libxfs_device_to_fd (dev_t); |
c5907b96 | 132 | extern dev_t libxfs_device_open (char *, int, int, int); |
2bd0ea18 | 133 | extern void libxfs_device_close (dev_t); |
b74a1f6a | 134 | extern int libxfs_device_alignment (void); |
b6281496 | 135 | extern void libxfs_report(FILE *); |
fd5eda53 | 136 | extern void platform_findsizes(char *path, int fd, long long *sz, int *bsz); |
12b55baf | 137 | extern int platform_nproc(void); |
2bd0ea18 NS |
138 | |
139 | /* check or write log footer: specify device, log size in blocks & uuid */ | |
d60ba955 | 140 | typedef char *(libxfs_get_block_t)(char *, int, void *); |
989b74bc | 141 | |
0c12ba5f BF |
142 | /* |
143 | * Helpers to clear the log to a particular log cycle. | |
144 | */ | |
145 | #define XLOG_INIT_CYCLE 1 | |
1c12a814 | 146 | extern int libxfs_log_clear(struct xfs_buftarg *, char *, xfs_daddr_t, |
571a78a7 | 147 | uint, uuid_t *, int, int, int, int, bool); |
0c12ba5f BF |
148 | extern int libxfs_log_header(char *, uuid_t *, int, int, int, xfs_lsn_t, |
149 | xfs_lsn_t, libxfs_get_block_t *, void *); | |
989b74bc | 150 | |
75c8b434 | 151 | |
5e656dbb | 152 | /* Shared utility routines */ |
2bd0ea18 | 153 | |
b626fb59 | 154 | extern int libxfs_alloc_file_space (struct xfs_inode *, xfs_off_t, |
2bd0ea18 NS |
155 | xfs_off_t, int, int); |
156 | ||
6f530e9a | 157 | extern void libxfs_fs_repair_cmn_err(int, struct xfs_mount *, char *, ...); |
5e656dbb | 158 | extern void libxfs_fs_cmn_err(int, struct xfs_mount *, char *, ...); |
2bd0ea18 | 159 | |
b626fb59 DC |
160 | /* XXX: this is messy and needs fixing */ |
161 | #ifndef __LIBXFS_INTERNAL_XFS_H__ | |
1552a820 NS |
162 | extern void cmn_err(int, char *, ...); |
163 | enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC }; | |
b626fb59 | 164 | #endif |
f302e9e4 | 165 | |
cb5b3ef4 | 166 | |
2556c98b BN |
167 | extern int libxfs_nproc(void); |
168 | extern unsigned long libxfs_physmem(void); /* in kilobytes */ | |
cb5b3ef4 | 169 | |
6b803e5a | 170 | #include "xfs_ialloc.h" |
f302e9e4 | 171 | |
6b803e5a CH |
172 | #include "xfs_attr_leaf.h" |
173 | #include "xfs_attr_remote.h" | |
174 | #include "xfs_trans_space.h" | |
f302e9e4 | 175 | |
5e656dbb BN |
176 | #define XFS_INOBT_IS_FREE_DISK(rp,i) \ |
177 | ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0) | |
56b2de80 | 178 | |
c749bd55 BF |
179 | static inline bool |
180 | xfs_inobt_is_sparse_disk( | |
181 | struct xfs_inobt_rec *rp, | |
182 | int offset) | |
183 | { | |
184 | int spshift; | |
185 | uint16_t holemask; | |
186 | ||
187 | holemask = be16_to_cpu(rp->ir_u.sp.ir_holemask); | |
188 | spshift = offset / XFS_INODES_PER_HOLEMASK_BIT; | |
189 | if ((1 << spshift) & holemask) | |
190 | return true; | |
191 | ||
192 | return false; | |
193 | } | |
194 | ||
ff105f75 DC |
195 | static inline void |
196 | libxfs_bmbt_disk_get_all( | |
b37d753d | 197 | struct xfs_bmbt_rec *rec, |
ff105f75 DC |
198 | struct xfs_bmbt_irec *irec) |
199 | { | |
b37d753d CH |
200 | uint64_t l0 = get_unaligned_be64(&rec->l0); |
201 | uint64_t l1 = get_unaligned_be64(&rec->l1); | |
202 | ||
203 | irec->br_startoff = (l0 & xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9; | |
204 | irec->br_startblock = ((l0 & xfs_mask64lo(9)) << 43) | (l1 >> 21); | |
205 | irec->br_blockcount = l1 & xfs_mask64lo(21); | |
206 | if (l0 >> (64 - BMBT_EXNTFLAG_BITLEN)) | |
207 | irec->br_state = XFS_EXT_UNWRITTEN; | |
208 | else | |
209 | irec->br_state = XFS_EXT_NORM; | |
ff105f75 | 210 | } |
5e656dbb | 211 | |
f616e2bf | 212 | /* XXX: this is clearly a bug - a shared header needs to export this */ |
5e656dbb BN |
213 | /* xfs_rtalloc.c */ |
214 | int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t); | |
0cf6a3a9 | 215 | bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno); |
5e656dbb | 216 | |
e515cca1 DC |
217 | /* XXX: need parts of xfs_attr.h in userspace */ |
218 | #define LIBXFS_ATTR_ROOT 0x0002 /* use attrs in root namespace */ | |
219 | #define LIBXFS_ATTR_SECURE 0x0008 /* use attrs in security namespace */ | |
220 | #define LIBXFS_ATTR_CREATE 0x0010 /* create, but fail if attr exists */ | |
221 | #define LIBXFS_ATTR_REPLACE 0x0020 /* set, but fail if attr not exists */ | |
222 | ||
223 | int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags); | |
224 | int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name, | |
225 | unsigned char *value, int valuelen, int flags); | |
226 | ||
2bd0ea18 | 227 | #endif /* __LIBXFS_H__ */ |