]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/libxfs_priv.h
xfs: allocate xattr buffer on demand
[thirdparty/xfsprogs-dev.git] / libxfs / libxfs_priv.h
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
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.
17 *
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
33 /*
34 * define a guard and something we can check to determine what include context
35 * we are running from.
36 */
37 #ifndef __LIBXFS_INTERNAL_XFS_H__
38 #define __LIBXFS_INTERNAL_XFS_H__
39
40 #include "libxfs_api_defs.h"
41 #include "platform_defs.h"
42 #include "xfs.h"
43
44 #include "list.h"
45 #include "hlist.h"
46 #include "cache.h"
47 #include "bitops.h"
48 #include "kmem.h"
49 #include "libfrog/radix-tree.h"
50 #include "atomic.h"
51
52 #include "xfs_types.h"
53 #include "xfs_arch.h"
54
55 #include "xfs_fs.h"
56 #include "libfrog/crc32c.h"
57
58 /* Zones used in libxfs allocations that aren't in shared header files */
59 extern kmem_zone_t *xfs_buf_item_zone;
60 extern kmem_zone_t *xfs_ili_zone;
61 extern kmem_zone_t *xfs_buf_zone;
62 extern kmem_zone_t *xfs_inode_zone;
63 extern kmem_zone_t *xfs_trans_zone;
64
65 /* CRC stuff, buffer API dependent on it */
66 #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
67
68 #include "xfs_cksum.h"
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 */
74 #include "libxfs_io.h"
75
76 /* for all the support code that uses progname in error messages */
77 extern char *progname;
78
79 #undef ASSERT
80 #define ASSERT(ex) assert(ex)
81
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
88
89 #ifndef EWRONGFS
90 #define EWRONGFS EINVAL
91 #endif
92
93 #define xfs_error_level 0
94
95 #define STATIC static
96
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
107 #define XFS_IGET_CREATE 0x1
108 #define XFS_IGET_UNTRUSTED 0x2
109
110 extern void cmn_err(int, char *, ...);
111 enum 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)
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)
117
118 #define xfs_hex_dump(d,n) ((void) 0)
119 #define xfs_stack_trace() ((void) 0)
120
121
122 #define xfs_force_shutdown(d,n) ((void) 0)
123 #define xfs_mod_delalloc(a,b) ((void) 0)
124
125 /* stop unused var warnings by assigning mp to itself */
126
127 #define xfs_corruption_error(e,l,mp,b,sz,fi,ln,fa) do { \
128 (mp) = (mp); \
129 cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e)); \
130 } while (0)
131
132 #define XFS_CORRUPTION_ERROR(e, lvl, mp, buf, bufsize) do { \
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
142 #define XFS_ERRLEVEL_LOW 1
143 #define XFS_FORCED_SHUTDOWN(mp) 0
144 #define XFS_ILOCK_EXCL 0
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)
148 #define XFS_TEST_ERROR(expr,a,b) ( expr )
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 }
168
169 #ifdef __GNUC__
170 #define __return_address __builtin_return_address(0)
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()
187 #endif
188
189 /* miscellaneous kernel routines not in user space */
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)
195 #define rcu_read_lock() ((void) 0)
196 #define rcu_read_unlock() ((void) 0)
197 /* Need to be able to handle this bare or in control flow */
198 static inline bool WARN_ON(bool expr) {
199 return (expr);
200 }
201
202 #define WARN_ON_ONCE(e) WARN_ON(e)
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)
206
207 #define READ_ONCE(x) (x)
208 #define WRITE_ONCE(x, val) ((x) = (val))
209
210 /*
211 * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs
212 * or all sorts of badness can occur!
213 */
214 #define prandom_u32() 0
215
216 #define PAGE_SIZE getpagesize()
217
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
223 static 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))))
234
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 */
246 static inline uint64_t
247 div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
248 {
249 *remainder = dividend % divisor;
250 return dividend / divisor;
251 }
252
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; })
257
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)
265
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 */
284 static 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 */
313 static inline unsigned long
314 find_next_bit(const unsigned long *addr, unsigned long size,
315 unsigned long offset)
316 {
317 return _find_next_bit(addr, size, offset, 0UL);
318 }
319 static inline unsigned long
320 find_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)
326
327 static inline __attribute__((const))
328 int is_power_of_2(unsigned long n)
329 {
330 return (n != 0 && ((n & (n - 1)) == 0));
331 }
332
333 /*
334 * xfs_iroundup: round up argument to next power of two
335 */
336 static inline uint
337 roundup_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 }
357
358 static inline uint64_t
359 roundup_64(uint64_t x, uint32_t y)
360 {
361 x += y - 1;
362 do_div(x, y);
363 return x * y;
364 }
365
366 /* buffer management */
367 #define XBF_TRYLOCK 0
368 #define XBF_UNMAPPED 0
369 #define XBF_DONE 0
370 #define xfs_buf_stale(bp) ((bp)->b_flags |= LIBXFS_B_STALE)
371 #define XFS_BUF_UNDELAYWRITE(bp) ((bp)->b_flags &= ~LIBXFS_B_DIRTY)
372 #define XFS_BUF_SET_BDSTRAT_FUNC(a,b) ((void) 0)
373
374 /* avoid gcc warning */
375 #define xfs_buf_incore(bt,blkno,len,lockit) ({ \
376 typeof(blkno) __foo = (blkno); \
377 typeof(len) __bar = (len); \
378 (blkno) = __foo; \
379 (len) = __bar; /* no set-but-unused warning */ \
380 NULL; \
381 })
382 #define xfs_buf_relse(bp) libxfs_putbuf(bp)
383 #define xfs_buf_get(devp,blkno,len) (libxfs_getbuf((devp), (blkno), (len)))
384 #define xfs_bwrite(bp) libxfs_writebuf((bp), 0)
385 #define xfs_buf_oneshot(bp) ((void) 0)
386
387 #define XBRW_READ LIBXFS_BREAD
388 #define XBRW_WRITE LIBXFS_BWRITE
389 #define xfs_buf_zero(bp,off,len) libxfs_iomove(bp,off,len,NULL,LIBXFS_BZERO)
390
391 /* mount stuff */
392 #define XFS_MOUNT_32BITINODES LIBXFS_MOUNT_32BITINODES
393 #define XFS_MOUNT_ATTR2 LIBXFS_MOUNT_ATTR2
394 #define XFS_MOUNT_SMALL_INUMS 0 /* ignored in userspace */
395 #define XFS_MOUNT_WSYNC 0 /* ignored in userspace */
396 #define XFS_MOUNT_NOALIGN 0 /* ignored in userspace */
397 #define XFS_MOUNT_IKEEP 0 /* ignored in userspace */
398 #define XFS_MOUNT_SWALLOC 0 /* ignored in userspace */
399 #define XFS_MOUNT_RDONLY 0 /* ignored in userspace */
400 #define XFS_MOUNT_BAD_SUMMARY 0 /* ignored in userspace */
401
402 #define xfs_trans_set_sync(tp) ((void) 0)
403 #define xfs_trans_agblocks_delta(tp, d)
404 #define xfs_trans_agflist_delta(tp, d)
405 #define xfs_trans_agbtree_delta(tp, d)
406 #define xfs_trans_buf_set_type(tp, bp, t) ({ \
407 int __t = (t); \
408 __t = __t; /* no set-but-unused warning */ \
409 tp = tp; /* no set-but-unused warning */ \
410 })
411
412 #define xfs_trans_buf_copy_type(dbp, sbp)
413
414 /* no readahead, need to avoid set-but-unused var warnings. */
415 #define xfs_buf_readahead(a,d,c,ops) ({ \
416 xfs_daddr_t __d = d; \
417 __d = __d; /* no set-but-unused warning */ \
418 })
419 #define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */
420
421 #define xfs_sort qsort
422
423 #define xfs_ilock(ip,mode) ((void) 0)
424 #define xfs_ilock_data_map_shared(ip) (0)
425 #define xfs_ilock_attr_map_shared(ip) (0)
426 #define xfs_iunlock(ip,mode) ({ \
427 typeof(mode) __mode = mode; \
428 __mode = __mode; /* no set-but-unused warning */ \
429 })
430
431 /* space allocation */
432 #define XFS_EXTENT_BUSY_DISCARDED 0x01 /* undergoing a discard op. */
433 #define XFS_EXTENT_BUSY_SKIP_DISCARD 0x02 /* do not discard */
434
435 #define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0)
436 /* avoid unused variable warning */
437 #define xfs_extent_busy_insert(tp,ag,bno,len,flags)({ \
438 xfs_agnumber_t __foo = ag; \
439 __foo = __foo; /* no set-but-unused warning */ \
440 })
441 #define xfs_extent_busy_trim(args,bno,len,busy_gen) ({ \
442 unsigned __foo = *(busy_gen); \
443 *(busy_gen) = __foo; \
444 false; \
445 })
446 #define xfs_extent_busy_flush(mp,pag,busy_gen) ((void)(0))
447
448 #define xfs_rotorstep 1
449 #define xfs_bmap_rtalloc(a) (-ENOSYS)
450 #define xfs_get_extsz_hint(ip) (0)
451 #define xfs_get_cowextsz_hint(ip) (0)
452 #define xfs_inode_is_filestream(ip) (0)
453 #define xfs_filestream_lookup_ag(ip) (0)
454 #define xfs_filestream_new_ag(ip,ag) (0)
455
456 /* quota bits */
457 #define xfs_trans_mod_dquot_byino(t,i,f,d) ((void) 0)
458 #define xfs_trans_reserve_quota_nblks(t,i,b,n,f) (0)
459 #define xfs_trans_unreserve_quota_nblks(t,i,b,n,f) ((void) 0)
460 #define xfs_qm_dqattach(i) (0)
461
462 #define uuid_copy(s,d) platform_uuid_copy((s),(d))
463 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
464
465 #define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0)
466 #define xfs_sb_validate_fsb_count(sbp, nblks) (0)
467
468 /*
469 * Prototypes for kernel static functions that are aren't in their
470 * associated header files.
471 */
472 struct xfs_da_args;
473 struct xfs_bmap_free;
474 struct xfs_bmap_free_item;
475 struct xfs_mount;
476 struct xfs_sb;
477 struct xfs_trans;
478 struct xfs_inode;
479 struct xfs_log_item;
480 struct xfs_buf;
481 struct xfs_buf_map;
482 struct xfs_buf_log_item;
483 struct xfs_buftarg;
484
485 /* xfs_attr.c */
486 int xfs_attr_rmtval_get(struct xfs_da_args *);
487
488 /* xfs_bmap.c */
489 void xfs_bmap_del_free(struct xfs_bmap_free *, struct xfs_bmap_free_item *);
490
491 /* xfs_mount.c */
492 int xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
493 void xfs_mount_common(struct xfs_mount *, struct xfs_sb *);
494
495 /*
496 * logitem.c and trans.c prototypes
497 */
498 void xfs_trans_init(struct xfs_mount *);
499 int xfs_trans_roll(struct xfs_trans **);
500
501 /* xfs_trans_item.c */
502 void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
503 void xfs_trans_del_item(struct xfs_log_item *);
504
505 /* xfs_inode_item.c */
506 void xfs_inode_item_init(struct xfs_inode *, struct xfs_mount *);
507
508 /* xfs_buf_item.c */
509 void xfs_buf_item_init(struct xfs_buf *, struct xfs_mount *);
510 void xfs_buf_item_log(struct xfs_buf_log_item *, uint, uint);
511
512 /* xfs_trans_buf.c */
513 struct xfs_buf *xfs_trans_buf_item_match(struct xfs_trans *,
514 struct xfs_buftarg *, struct xfs_buf_map *, int);
515
516 /* local source files */
517 #define xfs_mod_fdblocks(mp, delta, rsvd) \
518 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, rsvd)
519 #define xfs_mod_frextents(mp, delta) \
520 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, delta, 0)
521 int libxfs_mod_incore_sb(struct xfs_mount *, int, int64_t, int);
522 /* percpu counters in mp are #defined to the superblock sb_ counters */
523 #define xfs_reinit_percpu_counters(mp)
524
525 void xfs_trans_mod_sb(struct xfs_trans *, uint, long);
526
527 void xfs_verifier_error(struct xfs_buf *bp, int error,
528 xfs_failaddr_t failaddr);
529 void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
530 const char *name, void *buf, size_t bufsz,
531 xfs_failaddr_t failaddr);
532
533 #define xfs_buf_verifier_error(bp,e,n,bu,bus,fa) \
534 xfs_verifier_error(bp, e, fa)
535
536 /* XXX: this is clearly a bug - a shared header needs to export this */
537 /* xfs_rtalloc.c */
538 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
539 bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
540
541 struct xfs_rtalloc_rec {
542 xfs_rtblock_t ar_startext;
543 xfs_rtblock_t ar_extcount;
544 };
545
546 typedef int (*xfs_rtalloc_query_range_fn)(
547 struct xfs_trans *tp,
548 struct xfs_rtalloc_rec *rec,
549 void *priv);
550
551 int libxfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
552 xfs_off_t count_fsb);
553
554
555 bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
556 void xfs_log_item_init(struct xfs_mount *, struct xfs_log_item *, int);
557 #define xfs_log_in_recovery(mp) (false)
558
559 /* xfs_icache.c */
560 #define xfs_inode_set_cowblocks_tag(ip) do { } while (0)
561 #define xfs_inode_set_eofblocks_tag(ip) do { } while (0)
562
563 /* xfs_stats.h */
564 #define XFS_STATS_CALC_INDEX(member) 0
565 #define XFS_STATS_INC_OFF(mp, off)
566 #define XFS_STATS_ADD_OFF(mp, off, val)
567
568 typedef unsigned char u8;
569 unsigned int hweight8(unsigned int w);
570 unsigned int hweight32(unsigned int w);
571 unsigned int hweight64(__u64 w);
572
573 #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
574 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
575
576 static inline void set_bit(int nr, volatile unsigned long *addr)
577 {
578 unsigned long mask = BIT_MASK(nr);
579 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
580
581 *p |= mask;
582 }
583
584 static inline void clear_bit(int nr, volatile unsigned long *addr)
585 {
586 unsigned long mask = BIT_MASK(nr);
587 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
588
589 *p &= ~mask;
590 }
591
592 static inline int test_bit(int nr, const volatile unsigned long *addr)
593 {
594 unsigned long mask = BIT_MASK(nr);
595 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
596
597 return *p & mask;
598 }
599
600 /* Sets and returns original value of the bit */
601 static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
602 {
603 if (test_bit(nr, addr))
604 return 1;
605 set_bit(nr, addr);
606 return 0;
607 }
608
609 /* Keep static checkers quiet about nonstatic functions by exporting */
610 int xfs_inode_hasattr(struct xfs_inode *ip);
611 int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
612 int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
613 unsigned char **value, int *valuelenp, int flags);
614 int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
615 unsigned char *value, int valuelen, int flags);
616 int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
617
618 int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
619 xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
620 int xfs_rtcheck_range(struct xfs_mount *mp, struct xfs_trans *tp,
621 xfs_rtblock_t start, xfs_extlen_t len, int val,
622 xfs_rtblock_t *new, int *stat);
623 int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp,
624 xfs_rtblock_t start, xfs_rtblock_t limit,
625 xfs_rtblock_t *rtblock);
626 int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,
627 xfs_rtblock_t start, xfs_rtblock_t limit,
628 xfs_rtblock_t *rtblock);
629 int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
630 xfs_rtblock_t start, xfs_extlen_t len, int val);
631 int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp,
632 int log, xfs_rtblock_t bbno, int delta,
633 xfs_buf_t **rbpp, xfs_fsblock_t *rsb,
634 xfs_suminfo_t *sum);
635 int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log,
636 xfs_rtblock_t bbno, int delta, xfs_buf_t **rbpp,
637 xfs_fsblock_t *rsb);
638 int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
639 xfs_rtblock_t start, xfs_extlen_t len,
640 struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
641 int xfs_rtalloc_query_range(struct xfs_trans *tp,
642 struct xfs_rtalloc_rec *low_rec,
643 struct xfs_rtalloc_rec *high_rec,
644 xfs_rtalloc_query_range_fn fn,
645 void *priv);
646 int xfs_rtalloc_query_all(struct xfs_trans *tp,
647 xfs_rtalloc_query_range_fn fn,
648 void *priv);
649 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
650 int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,
651 xfs_rtblock_t start, xfs_extlen_t len,
652 bool *is_free);
653 /* xfs_bmap_util.h */
654 struct xfs_bmalloca;
655 int xfs_bmap_extsize_align(struct xfs_mount *mp, struct xfs_bmbt_irec *gotp,
656 struct xfs_bmbt_irec *prevp, xfs_extlen_t extsz,
657 int rt, int eof, int delay, int convert,
658 xfs_fileoff_t *offp, xfs_extlen_t *lenp);
659 void xfs_bmap_adjacent(struct xfs_bmalloca *ap);
660 int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
661 int whichfork, struct xfs_bmbt_irec *rec,
662 int *is_empty);
663
664 #endif /* __LIBXFS_INTERNAL_XFS_H__ */