]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/libxfs_priv.h
libfrog: move crc32c.h to libfrog/
[thirdparty/xfsprogs-dev.git] / libxfs / libxfs_priv.h
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
2bd0ea18 2/*
da23017d
NS
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
2bd0ea18
NS
5 */
6
7/*
8 * This header is effectively a "namespace multiplexor" for the
9 * user level XFS code. It provides all of the necessary stuff
10 * such that we can build some parts of the XFS kernel code in
11 * user space in a controlled fashion, and translates the names
12 * used in the kernel into the names which libxfs is going to
13 * make available to user tools.
14 *
15 * It should only ever be #include'd by XFS "kernel" code being
16 * compiled in user space.
dfc130f3 17 *
2bd0ea18
NS
18 * Our goals here are to...
19 * o "share" large amounts of complex code between user and
20 * kernel space;
21 * o shield the user tools from changes in the bleeding
22 * edge kernel code, merging source changes when
23 * convenient and not immediately (no symlinks);
24 * o i.e. be able to merge changes to the kernel source back
25 * into the affected user tools in a controlled fashion;
26 * o provide a _minimalist_ life-support system for kernel
27 * code in user land, not the "everything + the kitchen
28 * sink" model which libsim had mutated into;
29 * o allow the kernel code to be completely free of code
30 * specifically there to support the user level build.
31 */
32
f616e2bf
DC
33/*
34 * define a guard and something we can check to determine what include context
35 * we are running from.
36 */
b626fb59
DC
37#ifndef __LIBXFS_INTERNAL_XFS_H__
38#define __LIBXFS_INTERNAL_XFS_H__
f616e2bf 39
e515cca1 40#include "libxfs_api_defs.h"
6b803e5a 41#include "platform_defs.h"
dcabd4e7 42#include "xfs.h"
b626fb59 43
6b803e5a
CH
44#include "list.h"
45#include "hlist.h"
46#include "cache.h"
47#include "bitops.h"
48#include "kmem.h"
8bf7924e 49#include "libfrog/radix-tree.h"
6b803e5a 50#include "atomic.h"
b626fb59 51
6b803e5a
CH
52#include "xfs_types.h"
53#include "xfs_arch.h"
b626fb59 54
6b803e5a 55#include "xfs_fs.h"
63153a95 56#include "libfrog/crc32c.h"
b626fb59 57
4e006361
ES
58/* Zones used in libxfs allocations that aren't in shared header files */
59extern kmem_zone_t *xfs_buf_item_zone;
60extern kmem_zone_t *xfs_ili_zone;
61extern kmem_zone_t *xfs_buf_zone;
62extern kmem_zone_t *xfs_inode_zone;
63extern kmem_zone_t *xfs_trans_zone;
64
b626fb59 65/* CRC stuff, buffer API dependent on it */
b626fb59
DC
66#define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
67
6b803e5a 68#include "xfs_cksum.h"
b626fb59
DC
69
70/*
71 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
72 * every files via a similar include in the kernel xfs_linux.h.
73 */
897853d5 74#include "libxfs_io.h"
b626fb59
DC
75
76/* for all the support code that uses progname in error messages */
77extern char *progname;
2bd0ea18 78
a2ceac1f
DC
79#undef ASSERT
80#define ASSERT(ex) assert(ex)
5e656dbb 81
dc9b1f58
CH
82/*
83 * We have no need for the "linux" dev_t in userspace, so these
84 * are no-ops, and an xfs_dev_t is stored in VFS_I(ip)->i_rdev
85 */
86#define xfs_to_linux_dev_t(dev) dev
87#define linux_to_xfs_dev_t(dev) dev
551174eb 88
a2ceac1f
DC
89#ifndef EWRONGFS
90#define EWRONGFS EINVAL
91#endif
5e656dbb 92
56b2de80 93#define xfs_error_level 0
5e656dbb
BN
94
95#define STATIC static
5e656dbb 96
d7e71605
DW
97/*
98 * Starting in Linux 4.15, the %p (raw pointer value) printk modifier
99 * prints a hashed version of the pointer to avoid leaking kernel
100 * pointers into dmesg. If we're trying to debug the kernel we want the
101 * raw values, so override this behavior as best we can.
102 *
103 * In userspace we don't have this problem.
104 */
105#define PTR_FMT "%p"
106
5dcd1db5
DC
107#define XFS_IGET_CREATE 0x1
108#define XFS_IGET_UNTRUSTED 0x2
109
b626fb59
DC
110extern void cmn_err(int, char *, ...);
111enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
112
113#define xfs_notice(mp,fmt,args...) cmn_err(CE_NOTE,fmt, ## args)
114#define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
7cf9f816
DW
115#define xfs_err(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
116#define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
7cf9f816 117
b626fb59 118#define xfs_hex_dump(d,n) ((void) 0)
8791bf6b
ES
119#define xfs_stack_trace() ((void) 0)
120
b626fb59 121
6f4c54a4 122#define xfs_force_shutdown(d,n) ((void) 0)
f73690fe 123#define xfs_mod_delalloc(a,b) ((void) 0)
b626fb59 124
a2ceac1f 125/* stop unused var warnings by assigning mp to itself */
15348e04 126
3177b915 127#define xfs_corruption_error(e,l,mp,b,sz,fi,ln,fa) do { \
15348e04
DW
128 (mp) = (mp); \
129 cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e)); \
130} while (0)
131
3177b915 132#define XFS_CORRUPTION_ERROR(e, lvl, mp, buf, bufsize) do { \
e0607266
DC
133 (mp) = (mp); \
134 cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e)); \
135} while (0)
136
137#define XFS_ERROR_REPORT(e,l,mp) do { \
138 (mp) = (mp); \
139 cmn_err(CE_ALERT, "%s: XFS_ERROR_REPORT", (e)); \
140} while (0)
141
5e656dbb
BN
142#define XFS_ERRLEVEL_LOW 1
143#define XFS_FORCED_SHUTDOWN(mp) 0
144#define XFS_ILOCK_EXCL 0
ece930fa
CH
145#define XFS_STATS_INC(mp, count) do { (mp) = (mp); } while (0)
146#define XFS_STATS_DEC(mp, count, x) do { (mp) = (mp); } while (0)
147#define XFS_STATS_ADD(mp, count, x) do { (mp) = (mp); } while (0)
e2a190dd 148#define XFS_TEST_ERROR(expr,a,b) ( expr )
23639f77
ES
149#define XFS_WANT_CORRUPTED_GOTO(mp, expr, l) \
150{ \
151 if (!(expr)) { \
152 if ((mp)->m_flags & LIBXFS_MOUNT_WANT_CORRUPTED) \
153 printf("WANT_CORRUPTED_GOTO at %s:%d\n", \
154 __func__, __LINE__); \
155 error = -EFSCORRUPTED; \
156 goto l; \
157 } \
158}
159#define XFS_WANT_CORRUPTED_RETURN(mp, expr) \
160{ \
161 if (!(expr)) { \
162 if ((mp)->m_flags & LIBXFS_MOUNT_WANT_CORRUPTED) \
163 printf("WANT_CORRUPTED_RETURN at %s:%d\n", \
164 __func__, __LINE__); \
165 return -EFSCORRUPTED; \
166 } \
167}
5e656dbb 168
5e656dbb
BN
169#ifdef __GNUC__
170#define __return_address __builtin_return_address(0)
b47beff8
DW
171
172/*
173 * Return the address of a label. Use barrier() so that the optimizer
174 * won't reorder code to refactor the error jumpouts into a single
175 * return, which throws off the reported address.
176 */
177#define __this_address ({ __label__ __here; __here: barrier(); &&__here; })
178/* Optimization barrier */
179
180/* The "volatile" is due to gcc bugs */
181#define barrier() __asm__ __volatile__("": : :"memory")
182#endif
183
184/* Optimization barrier */
185#ifndef barrier
186# define barrier() __memory_barrier()
5e656dbb
BN
187#endif
188
189/* miscellaneous kernel routines not in user space */
5e656dbb
BN
190#define spin_lock_init(a) ((void) 0)
191#define spin_lock(a) ((void) 0)
192#define spin_unlock(a) ((void) 0)
193#define likely(x) (x)
194#define unlikely(x) (x)
56b2de80
DC
195#define rcu_read_lock() ((void) 0)
196#define rcu_read_unlock() ((void) 0)
c1587ecf 197/* Need to be able to handle this bare or in control flow */
c08793bd 198static inline bool WARN_ON(bool expr) {
c1587ecf
CH
199 return (expr);
200}
19ebedcf 201
c08793bd 202#define WARN_ON_ONCE(e) WARN_ON(e)
cbf3beaa
GW
203#define percpu_counter_read(x) (*x)
204#define percpu_counter_read_positive(x) ((*x) > 0 ? (*x) : 0)
205#define percpu_counter_sum(x) (*x)
5e656dbb 206
c02e0341
CH
207#define READ_ONCE(x) (x)
208#define WRITE_ONCE(x, val) ((x) = (val))
209
2bd0ea18 210/*
49f693fa 211 * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs
5e656dbb 212 * or all sorts of badness can occur!
2bd0ea18 213 */
49f693fa 214#define prandom_u32() 0
2bd0ea18 215
b2327e1a 216#define PAGE_SIZE getpagesize()
2bd0ea18 217
d5105a89
JL
218#define inode_peek_iversion(inode) (inode)->i_version
219#define inode_set_iversion_queried(inode, version) do { \
220 (inode)->i_version = (version); \
221} while (0)
222
5e656dbb
BN
223static inline int __do_div(unsigned long long *n, unsigned base)
224{
225 int __res;
226 __res = (int)(((unsigned long) *n) % (unsigned) base);
227 *n = ((unsigned long) *n) / (unsigned) base;
228 return __res;
229}
230
231#define do_div(n,base) (__do_div((unsigned long long *)&(n), (base)))
232#define do_mod(a, b) ((a) % (b))
233#define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
2bd0ea18 234
e91df844
DW
235/**
236 * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
237 * @dividend: unsigned 64bit dividend
238 * @divisor: unsigned 32bit divisor
239 * @remainder: pointer to unsigned 32bit remainder
240 *
241 * Return: sets ``*remainder``, then returns dividend / divisor
242 *
243 * This is commonly provided by 32bit archs to provide an optimized 64bit
244 * divide.
245 */
246static inline uint64_t
247div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
248{
249 *remainder = dividend % divisor;
250 return dividend / divisor;
251}
252
5e656dbb
BN
253#define min_t(type,x,y) \
254 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
255#define max_t(type,x,y) \
256 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
57c9fccb 257
50c8d191
GS
258/**
259 * swap - swap values of @a and @b
260 * @a: first value
261 * @b: second value
262 */
263#define swap(a, b) \
264 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
91eba724 265
7338c4b8
BF
266#define __round_mask(x, y) ((__typeof__(x))((y)-1))
267#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
268#define round_down(x, y) ((x) & ~__round_mask(x, y))
269#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
270
271/*
272 * Handling for kernel bitmap types.
273 */
274#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, NBBY * sizeof(long))
275#define DECLARE_BITMAP(name,bits) \
276 unsigned long name[BITS_TO_LONGS(bits)]
277#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
278
279/*
280 * This is a common helper function for find_next_bit and
281 * find_next_zero_bit. The difference is the "invert" argument, which
282 * is XORed with each fetched word before searching it for one bits.
283 */
284static inline unsigned long
285_find_next_bit(const unsigned long *addr, unsigned long nbits,
286 unsigned long start, unsigned long invert)
287{
288 unsigned long tmp;
289
290 if (!nbits || start >= nbits)
291 return nbits;
292
293 tmp = addr[start / BITS_PER_LONG] ^ invert;
294
295 /* Handle 1st word. */
296 tmp &= BITMAP_FIRST_WORD_MASK(start);
297 start = round_down(start, BITS_PER_LONG);
298
299 while (!tmp) {
300 start += BITS_PER_LONG;
301 if (start >= nbits)
302 return nbits;
303
304 tmp = addr[start / BITS_PER_LONG] ^ invert;
305 }
306
307 return min(start + ffs(tmp), nbits);
308}
309
310/*
311 * Find the next set bit in a memory region.
312 */
313static inline unsigned long
314find_next_bit(const unsigned long *addr, unsigned long size,
315 unsigned long offset)
316{
317 return _find_next_bit(addr, size, offset, 0UL);
318}
319static inline unsigned long
320find_next_zero_bit(const unsigned long *addr, unsigned long size,
321 unsigned long offset)
322{
323 return _find_next_bit(addr, size, offset, ~0UL);
324}
325#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
91eba724 326
5e656dbb
BN
327static inline __attribute__((const))
328int is_power_of_2(unsigned long n)
329{
330 return (n != 0 && ((n & (n - 1)) == 0));
331}
2bd0ea18
NS
332
333/*
5e656dbb 334 * xfs_iroundup: round up argument to next power of two
2bd0ea18 335 */
5e656dbb
BN
336static inline uint
337roundup_pow_of_two(uint v)
338{
339 int i;
340 uint m;
341
342 if ((v & (v - 1)) == 0)
343 return v;
344 ASSERT((v & 0x80000000) == 0);
345 if ((v & (v + 1)) == 0)
346 return v + 1;
347 for (i = 0, m = 1; i < 31; i++, m <<= 1) {
348 if (v & m)
349 continue;
350 v |= m;
351 if ((v & (v + 1)) == 0)
352 return v + 1;
353 }
354 ASSERT(0);
355 return 0;
356}
2bd0ea18 357
14f8b681
DW
358static inline uint64_t
359roundup_64(uint64_t x, uint32_t y)
88cd79be
DC
360{
361 x += y - 1;
362 do_div(x, y);
363 return x * y;
364}
365
2bd0ea18 366/* buffer management */
e8a1c983 367#define XBF_TRYLOCK 0
a2ceac1f 368#define XBF_UNMAPPED 0
e9d35108 369#define XBF_DONE 0
a2ceac1f 370#define xfs_buf_stale(bp) ((bp)->b_flags |= LIBXFS_B_STALE)
f1b058f9 371#define XFS_BUF_UNDELAYWRITE(bp) ((bp)->b_flags &= ~LIBXFS_B_DIRTY)
2bd0ea18 372#define XFS_BUF_SET_BDSTRAT_FUNC(a,b) ((void) 0)
5e656dbb 373
9d6fabc0 374/* avoid gcc warning */
ce50fc05 375#define xfs_buf_incore(bt,blkno,len,lockit) ({ \
9d6fabc0 376 typeof(blkno) __foo = (blkno); \
6bddecbc 377 typeof(len) __bar = (len); \
9d6fabc0 378 (blkno) = __foo; \
6bddecbc 379 (len) = __bar; /* no set-but-unused warning */ \
9d6fabc0
DC
380 NULL; \
381})
971ce259
DC
382#define xfs_buf_get_uncached(t,n,f) \
383 libxfs_getbufr((t), XFS_BUF_DADDR_NULL, (n));
2bd0ea18 384#define xfs_buf_relse(bp) libxfs_putbuf(bp)
4aa01a59 385#define xfs_buf_get(devp,blkno,len) (libxfs_getbuf((devp), (blkno), (len)))
9d6fabc0 386#define xfs_bwrite(bp) libxfs_writebuf((bp), 0)
e9d35108 387#define xfs_buf_delwri_queue(bp, bl) libxfs_writebuf((bp), 0)
971ce259
DC
388#define xfs_buf_delwri_submit(bl) (0)
389#define xfs_buf_oneshot(bp) ((void) 0)
57c9fccb 390
56b2de80
DC
391#define XBRW_READ LIBXFS_BREAD
392#define XBRW_WRITE LIBXFS_BWRITE
3dd2705a 393#define xfs_buf_zero(bp,off,len) libxfs_iomove(bp,off,len,NULL,LIBXFS_BZERO)
2bd0ea18 394
5e656dbb
BN
395/* mount stuff */
396#define XFS_MOUNT_32BITINODES LIBXFS_MOUNT_32BITINODES
397#define XFS_MOUNT_ATTR2 LIBXFS_MOUNT_ATTR2
398#define XFS_MOUNT_SMALL_INUMS 0 /* ignored in userspace */
399#define XFS_MOUNT_WSYNC 0 /* ignored in userspace */
400#define XFS_MOUNT_NOALIGN 0 /* ignored in userspace */
3439d03a 401#define XFS_MOUNT_IKEEP 0 /* ignored in userspace */
ff105f75
DC
402#define XFS_MOUNT_SWALLOC 0 /* ignored in userspace */
403#define XFS_MOUNT_RDONLY 0 /* ignored in userspace */
52f4e126 404#define XFS_MOUNT_BAD_SUMMARY 0 /* ignored in userspace */
5e656dbb 405
5e656dbb
BN
406#define xfs_trans_set_sync(tp) ((void) 0)
407#define xfs_trans_agblocks_delta(tp, d)
408#define xfs_trans_agflist_delta(tp, d)
409#define xfs_trans_agbtree_delta(tp, d)
6bddecbc
DC
410#define xfs_trans_buf_set_type(tp, bp, t) ({ \
411 int __t = (t); \
412 __t = __t; /* no set-but-unused warning */ \
fca3ed92 413 tp = tp; /* no set-but-unused warning */ \
6bddecbc
DC
414})
415
8b4dc4a9 416#define xfs_trans_buf_copy_type(dbp, sbp)
5e656dbb 417
10851b18
DC
418/* no readahead, need to avoid set-but-unused var warnings. */
419#define xfs_buf_readahead(a,d,c,ops) ({ \
420 xfs_daddr_t __d = d; \
421 __d = __d; /* no set-but-unused warning */ \
422})
a2ceac1f 423#define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */
5e656dbb 424
5e656dbb 425#define xfs_sort qsort
2bd0ea18 426
5e656dbb 427#define xfs_ilock(ip,mode) ((void) 0)
ff105f75
DC
428#define xfs_ilock_data_map_shared(ip) (0)
429#define xfs_ilock_attr_map_shared(ip) (0)
430#define xfs_iunlock(ip,mode) ({ \
431 typeof(mode) __mode = mode; \
432 __mode = __mode; /* no set-but-unused warning */ \
433})
2bd0ea18 434
5e656dbb 435/* space allocation */
3a13f959
BF
436#define XFS_EXTENT_BUSY_DISCARDED 0x01 /* undergoing a discard op. */
437#define XFS_EXTENT_BUSY_SKIP_DISCARD 0x02 /* do not discard */
438
a2ceac1f 439#define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0)
aefc06c1
ES
440/* avoid unused variable warning */
441#define xfs_extent_busy_insert(tp,ag,bno,len,flags)({ \
442 xfs_agnumber_t __foo = ag; \
443 __foo = __foo; /* no set-but-unused warning */ \
444})
cd80de04
CH
445#define xfs_extent_busy_trim(args,bno,len,busy_gen) ({ \
446 unsigned __foo = *(busy_gen); \
447 *(busy_gen) = __foo; \
448 false; \
449})
b0a898fe 450#define xfs_extent_busy_flush(mp,pag,busy_gen) ((void)(0))
a2ceac1f 451
5e656dbb 452#define xfs_rotorstep 1
1f2ace68 453#define xfs_bmap_rtalloc(a) (-ENOSYS)
5e656dbb 454#define xfs_get_extsz_hint(ip) (0)
10460994 455#define xfs_get_cowextsz_hint(ip) (0)
5e656dbb
BN
456#define xfs_inode_is_filestream(ip) (0)
457#define xfs_filestream_lookup_ag(ip) (0)
458#define xfs_filestream_new_ag(ip,ag) (0)
2bd0ea18 459
a2ceac1f
DC
460/* quota bits */
461#define xfs_trans_mod_dquot_byino(t,i,f,d) ((void) 0)
462#define xfs_trans_reserve_quota_nblks(t,i,b,n,f) (0)
463#define xfs_trans_unreserve_quota_nblks(t,i,b,n,f) ((void) 0)
43cf369d 464#define xfs_qm_dqattach(i) (0)
a2ceac1f 465
5dfa5cd2
DC
466#define uuid_copy(s,d) platform_uuid_copy((s),(d))
467#define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
468
e9d35108 469#define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0)
4896e6c8 470#define xfs_sb_validate_fsb_count(sbp, nblks) (0)
e9d35108 471
2bd0ea18 472/*
5e656dbb 473 * Prototypes for kernel static functions that are aren't in their
b626fb59 474 * associated header files.
2bd0ea18 475 */
b626fb59
DC
476struct xfs_da_args;
477struct xfs_bmap_free;
478struct xfs_bmap_free_item;
479struct xfs_mount;
480struct xfs_sb;
481struct xfs_trans;
482struct xfs_inode;
483struct xfs_log_item;
484struct xfs_buf;
485struct xfs_buf_map;
486struct xfs_buf_log_item;
487struct xfs_buftarg;
2bd0ea18 488
5e656dbb
BN
489/* xfs_attr.c */
490int xfs_attr_rmtval_get(struct xfs_da_args *);
2bd0ea18
NS
491
492/* xfs_bmap.c */
2cf6d225 493void xfs_bmap_del_free(struct xfs_bmap_free *, struct xfs_bmap_free_item *);
5e656dbb
BN
494
495/* xfs_mount.c */
b626fb59
DC
496int xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
497void xfs_mount_common(struct xfs_mount *, struct xfs_sb *);
5e656dbb
BN
498
499/*
500 * logitem.c and trans.c prototypes
501 */
4329aa4c 502void xfs_trans_init(struct xfs_mount *);
d67406c9 503int xfs_trans_roll(struct xfs_trans **);
2bd0ea18
NS
504
505/* xfs_trans_item.c */
c40bdaa2
DC
506void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
507void xfs_trans_del_item(struct xfs_log_item *);
2bd0ea18 508
2bd0ea18 509/* xfs_inode_item.c */
b626fb59 510void xfs_inode_item_init(struct xfs_inode *, struct xfs_mount *);
2bd0ea18
NS
511
512/* xfs_buf_item.c */
b626fb59
DC
513void xfs_buf_item_init(struct xfs_buf *, struct xfs_mount *);
514void xfs_buf_item_log(struct xfs_buf_log_item *, uint, uint);
2bd0ea18 515
5e656dbb 516/* xfs_trans_buf.c */
b626fb59
DC
517struct xfs_buf *xfs_trans_buf_item_match(struct xfs_trans *,
518 struct xfs_buftarg *, struct xfs_buf_map *, int);
5e656dbb 519
2bd0ea18 520/* local source files */
19ebedcf
DC
521#define xfs_mod_fdblocks(mp, delta, rsvd) \
522 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, rsvd)
523#define xfs_mod_frextents(mp, delta) \
524 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, delta, 0)
525int libxfs_mod_incore_sb(struct xfs_mount *, int, int64_t, int);
2dd13604
ES
526/* percpu counters in mp are #defined to the superblock sb_ counters */
527#define xfs_reinit_percpu_counters(mp)
19ebedcf 528
b626fb59 529void xfs_trans_mod_sb(struct xfs_trans *, uint, long);
15348e04 530
1d3bac1f
DW
531void xfs_verifier_error(struct xfs_buf *bp, int error,
532 xfs_failaddr_t failaddr);
533void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
534 const char *name, void *buf, size_t bufsz,
535 xfs_failaddr_t failaddr);
f616e2bf 536
43f7ceb5
DW
537#define xfs_buf_verifier_error(bp,e,n,bu,bus,fa) \
538 xfs_verifier_error(bp, e, fa)
539
b626fb59
DC
540/* XXX: this is clearly a bug - a shared header needs to export this */
541/* xfs_rtalloc.c */
542int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
0cf6a3a9 543bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
b626fb59 544
0b10a7f4 545struct xfs_rtalloc_rec {
858ae338
DW
546 xfs_rtblock_t ar_startext;
547 xfs_rtblock_t ar_extcount;
0b10a7f4
DW
548};
549
550typedef int (*xfs_rtalloc_query_range_fn)(
551 struct xfs_trans *tp,
552 struct xfs_rtalloc_rec *rec,
553 void *priv);
554
9542ae13
DC
555int libxfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
556 xfs_off_t count_fsb);
557
d780a2f2 558
a65d8d29 559bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
fb34b2d1 560void xfs_log_item_init(struct xfs_mount *, struct xfs_log_item *, int);
d780a2f2 561#define xfs_log_in_recovery(mp) (false)
a65d8d29 562
f7b1a8b1 563/* xfs_icache.c */
9587a34c
DW
564#define xfs_inode_set_cowblocks_tag(ip) do { } while (0)
565#define xfs_inode_set_eofblocks_tag(ip) do { } while (0)
f7b1a8b1 566
5d8acc46
DC
567/* xfs_stats.h */
568#define XFS_STATS_CALC_INDEX(member) 0
569#define XFS_STATS_INC_OFF(mp, off)
570#define XFS_STATS_ADD_OFF(mp, off, val)
571
4a492e72 572typedef unsigned char u8;
c7a710b7 573unsigned int hweight8(unsigned int w);
ec291989
DC
574unsigned int hweight32(unsigned int w);
575unsigned int hweight64(__u64 w);
5d8acc46 576
2fdd378a
DC
577#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
578#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
579
580static inline void set_bit(int nr, volatile unsigned long *addr)
581{
582 unsigned long mask = BIT_MASK(nr);
583 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
584
585 *p |= mask;
586}
587
588static inline void clear_bit(int nr, volatile unsigned long *addr)
589{
590 unsigned long mask = BIT_MASK(nr);
591 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
592
593 *p &= ~mask;
594}
595
596static inline int test_bit(int nr, const volatile unsigned long *addr)
597{
598 unsigned long mask = BIT_MASK(nr);
599 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
600
601 return *p & mask;
602}
603
5539639c
ES
604/* Sets and returns original value of the bit */
605static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
606{
607 if (test_bit(nr, addr))
608 return 1;
609 set_bit(nr, addr);
610 return 0;
611}
612
5f56a561
ES
613/* Keep static checkers quiet about nonstatic functions by exporting */
614int xfs_inode_hasattr(struct xfs_inode *ip);
615int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
616int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
617 unsigned char *value, int *valuelenp, int flags);
618int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
619 unsigned char *value, int valuelen, int flags);
620int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
621
622int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
623 xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
624int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
625 xfs_rtblock_t start, xfs_extlen_t len, int val,
626 xfs_rtblock_t *new, int *stat);
627int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
628 xfs_rtblock_t start, xfs_rtblock_t limit,
629 xfs_rtblock_t *rtblock);
630int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
631 xfs_rtblock_t start, xfs_rtblock_t limit,
632 xfs_rtblock_t *rtblock);
633int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
634 xfs_rtblock_t start, xfs_extlen_t len, int val);
635int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
636 int log, xfs_rtblock_t bbno, int delta,
637 xfs_buf_t **rbpp, xfs_fsblock_t *rsb,
638 xfs_suminfo_t *sum);
639int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
640 xfs_rtblock_t bbno, int delta, xfs_buf_t **rbpp,
641 xfs_fsblock_t *rsb);
642int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
643 xfs_rtblock_t start, xfs_extlen_t len,
644 struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
645int xfs_rtalloc_query_range(struct xfs_trans *tp,
646 struct xfs_rtalloc_rec *low_rec,
647 struct xfs_rtalloc_rec *high_rec,
648 xfs_rtalloc_query_range_fn fn,
649 void *priv);
650int xfs_rtalloc_query_all(struct xfs_trans *tp,
651 xfs_rtalloc_query_range_fn fn,
652 void *priv);
653bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
654int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
655 xfs_rtblock_t start, xfs_extlen_t len,
656 bool *is_free);
657/* xfs_bmap_util.h */
658struct xfs_bmalloca;
659int xfs_bmap_extsize_align(struct xfs_mount *mp, struct xfs_bmbt_irec *gotp,
660 struct xfs_bmbt_irec *prevp, xfs_extlen_t extsz,
661 int rt, int eof, int delay, int convert,
662 xfs_fileoff_t *offp, xfs_extlen_t *lenp);
663void xfs_bmap_adjacent(struct xfs_bmalloca *ap);
664int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
665 int whichfork, struct xfs_bmbt_irec *rec,
666 int *is_empty);
2fdd378a 667
b626fb59 668#endif /* __LIBXFS_INTERNAL_XFS_H__ */