]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/libxfs_priv.h
libfrog: move crc32c.h to libfrog/
[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_get_uncached(t,n,f) \
383 libxfs_getbufr((t), XFS_BUF_DADDR_NULL, (n));
384 #define xfs_buf_relse(bp) libxfs_putbuf(bp)
385 #define xfs_buf_get(devp,blkno,len) (libxfs_getbuf((devp), (blkno), (len)))
386 #define xfs_bwrite(bp) libxfs_writebuf((bp), 0)
387 #define xfs_buf_delwri_queue(bp, bl) libxfs_writebuf((bp), 0)
388 #define xfs_buf_delwri_submit(bl) (0)
389 #define xfs_buf_oneshot(bp) ((void) 0)
390
391 #define XBRW_READ LIBXFS_BREAD
392 #define XBRW_WRITE LIBXFS_BWRITE
393 #define xfs_buf_zero(bp,off,len) libxfs_iomove(bp,off,len,NULL,LIBXFS_BZERO)
394
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 */
401 #define XFS_MOUNT_IKEEP 0 /* ignored in userspace */
402 #define XFS_MOUNT_SWALLOC 0 /* ignored in userspace */
403 #define XFS_MOUNT_RDONLY 0 /* ignored in userspace */
404 #define XFS_MOUNT_BAD_SUMMARY 0 /* ignored in userspace */
405
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)
410 #define xfs_trans_buf_set_type(tp, bp, t) ({ \
411 int __t = (t); \
412 __t = __t; /* no set-but-unused warning */ \
413 tp = tp; /* no set-but-unused warning */ \
414 })
415
416 #define xfs_trans_buf_copy_type(dbp, sbp)
417
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 })
423 #define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */
424
425 #define xfs_sort qsort
426
427 #define xfs_ilock(ip,mode) ((void) 0)
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 })
434
435 /* space allocation */
436 #define XFS_EXTENT_BUSY_DISCARDED 0x01 /* undergoing a discard op. */
437 #define XFS_EXTENT_BUSY_SKIP_DISCARD 0x02 /* do not discard */
438
439 #define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0)
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 })
445 #define xfs_extent_busy_trim(args,bno,len,busy_gen) ({ \
446 unsigned __foo = *(busy_gen); \
447 *(busy_gen) = __foo; \
448 false; \
449 })
450 #define xfs_extent_busy_flush(mp,pag,busy_gen) ((void)(0))
451
452 #define xfs_rotorstep 1
453 #define xfs_bmap_rtalloc(a) (-ENOSYS)
454 #define xfs_get_extsz_hint(ip) (0)
455 #define xfs_get_cowextsz_hint(ip) (0)
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)
459
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)
464 #define xfs_qm_dqattach(i) (0)
465
466 #define uuid_copy(s,d) platform_uuid_copy((s),(d))
467 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
468
469 #define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0)
470 #define xfs_sb_validate_fsb_count(sbp, nblks) (0)
471
472 /*
473 * Prototypes for kernel static functions that are aren't in their
474 * associated header files.
475 */
476 struct xfs_da_args;
477 struct xfs_bmap_free;
478 struct xfs_bmap_free_item;
479 struct xfs_mount;
480 struct xfs_sb;
481 struct xfs_trans;
482 struct xfs_inode;
483 struct xfs_log_item;
484 struct xfs_buf;
485 struct xfs_buf_map;
486 struct xfs_buf_log_item;
487 struct xfs_buftarg;
488
489 /* xfs_attr.c */
490 int xfs_attr_rmtval_get(struct xfs_da_args *);
491
492 /* xfs_bmap.c */
493 void xfs_bmap_del_free(struct xfs_bmap_free *, struct xfs_bmap_free_item *);
494
495 /* xfs_mount.c */
496 int xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
497 void xfs_mount_common(struct xfs_mount *, struct xfs_sb *);
498
499 /*
500 * logitem.c and trans.c prototypes
501 */
502 void xfs_trans_init(struct xfs_mount *);
503 int xfs_trans_roll(struct xfs_trans **);
504
505 /* xfs_trans_item.c */
506 void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
507 void xfs_trans_del_item(struct xfs_log_item *);
508
509 /* xfs_inode_item.c */
510 void xfs_inode_item_init(struct xfs_inode *, struct xfs_mount *);
511
512 /* xfs_buf_item.c */
513 void xfs_buf_item_init(struct xfs_buf *, struct xfs_mount *);
514 void xfs_buf_item_log(struct xfs_buf_log_item *, uint, uint);
515
516 /* xfs_trans_buf.c */
517 struct xfs_buf *xfs_trans_buf_item_match(struct xfs_trans *,
518 struct xfs_buftarg *, struct xfs_buf_map *, int);
519
520 /* local source files */
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)
525 int libxfs_mod_incore_sb(struct xfs_mount *, int, int64_t, int);
526 /* percpu counters in mp are #defined to the superblock sb_ counters */
527 #define xfs_reinit_percpu_counters(mp)
528
529 void xfs_trans_mod_sb(struct xfs_trans *, uint, long);
530
531 void xfs_verifier_error(struct xfs_buf *bp, int error,
532 xfs_failaddr_t failaddr);
533 void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
534 const char *name, void *buf, size_t bufsz,
535 xfs_failaddr_t failaddr);
536
537 #define xfs_buf_verifier_error(bp,e,n,bu,bus,fa) \
538 xfs_verifier_error(bp, e, fa)
539
540 /* XXX: this is clearly a bug - a shared header needs to export this */
541 /* xfs_rtalloc.c */
542 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
543 bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
544
545 struct xfs_rtalloc_rec {
546 xfs_rtblock_t ar_startext;
547 xfs_rtblock_t ar_extcount;
548 };
549
550 typedef int (*xfs_rtalloc_query_range_fn)(
551 struct xfs_trans *tp,
552 struct xfs_rtalloc_rec *rec,
553 void *priv);
554
555 int libxfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
556 xfs_off_t count_fsb);
557
558
559 bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
560 void xfs_log_item_init(struct xfs_mount *, struct xfs_log_item *, int);
561 #define xfs_log_in_recovery(mp) (false)
562
563 /* xfs_icache.c */
564 #define xfs_inode_set_cowblocks_tag(ip) do { } while (0)
565 #define xfs_inode_set_eofblocks_tag(ip) do { } while (0)
566
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
572 typedef unsigned char u8;
573 unsigned int hweight8(unsigned int w);
574 unsigned int hweight32(unsigned int w);
575 unsigned int hweight64(__u64 w);
576
577 #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
578 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
579
580 static 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
588 static 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
596 static 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
604 /* Sets and returns original value of the bit */
605 static 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
613 /* Keep static checkers quiet about nonstatic functions by exporting */
614 int xfs_inode_hasattr(struct xfs_inode *ip);
615 int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
616 int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
617 unsigned char *value, int *valuelenp, int flags);
618 int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
619 unsigned char *value, int valuelen, int flags);
620 int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);
621
622 int xfs_rtbuf_get(struct xfs_mount *mp, struct xfs_trans *tp,
623 xfs_rtblock_t block, int issum, struct xfs_buf **bpp);
624 int 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);
627 int 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);
630 int 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);
633 int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp,
634 xfs_rtblock_t start, xfs_extlen_t len, int val);
635 int 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);
639 int 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);
642 int 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);
645 int 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);
650 int xfs_rtalloc_query_all(struct xfs_trans *tp,
651 xfs_rtalloc_query_range_fn fn,
652 void *priv);
653 bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
654 int 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 */
658 struct xfs_bmalloca;
659 int 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);
663 void xfs_bmap_adjacent(struct xfs_bmalloca *ap);
664 int xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
665 int whichfork, struct xfs_bmbt_irec *rec,
666 int *is_empty);
667
668 #endif /* __LIBXFS_INTERNAL_XFS_H__ */