2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * This header is effectively a "namespace multiplexor" for the
21 * user level XFS code. It provides all of the necessary stuff
22 * such that we can build some parts of the XFS kernel code in
23 * user space in a controlled fashion, and translates the names
24 * used in the kernel into the names which libxfs is going to
25 * make available to user tools.
27 * It should only ever be #include'd by XFS "kernel" code being
28 * compiled in user space.
30 * Our goals here are to...
31 * o "share" large amounts of complex code between user and
33 * o shield the user tools from changes in the bleeding
34 * edge kernel code, merging source changes when
35 * convenient and not immediately (no symlinks);
36 * o i.e. be able to merge changes to the kernel source back
37 * into the affected user tools in a controlled fashion;
38 * o provide a _minimalist_ life-support system for kernel
39 * code in user land, not the "everything + the kitchen
40 * sink" model which libsim had mutated into;
41 * o allow the kernel code to be completely free of code
42 * specifically there to support the user level build.
46 * define a guard and something we can check to determine what include context
47 * we are running from.
49 #ifndef __LIBXFS_INTERNAL_XFS_H__
50 #define __LIBXFS_INTERNAL_XFS_H__
52 #include "libxfs_api_defs.h"
53 #include "platform_defs.h"
61 #include "radix-tree.h"
64 #include "xfs_types.h"
69 /* CRC stuff, buffer API dependent on it */
70 extern uint32_t crc32_le(uint32_t crc
, unsigned char const *p
, size_t len
);
71 extern uint32_t crc32c_le(uint32_t crc
, unsigned char const *p
, size_t len
);
73 #define crc32(c,p,l) crc32_le((c),(unsigned char const *)(p),(l))
74 #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
76 #include "xfs_cksum.h"
79 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
80 * every files via a similar include in the kernel xfs_linux.h.
82 #include "libxfs_io.h"
84 /* for all the support code that uses progname in error messages */
85 extern char *progname
;
88 #define ASSERT(ex) assert(ex)
91 #define EWRONGFS EINVAL
94 #define xfs_error_level 0
98 /* XXX: need to push these out to make LIBXFS_ATTR defines */
99 #define ATTR_ROOT 0x0002
100 #define ATTR_SECURE 0x0008
101 #define ATTR_CREATE 0x0010
102 #define ATTR_REPLACE 0x0020
103 #define ATTR_KERNOTIME 0
104 #define ATTR_KERNOVAL 0
106 #define XFS_IGET_CREATE 0x1
107 #define XFS_IGET_UNTRUSTED 0x2
109 extern void cmn_err(int, char *, ...);
110 enum ce
{ CE_DEBUG
, CE_CONT
, CE_NOTE
, CE_WARN
, CE_ALERT
, CE_PANIC
};
112 #define xfs_notice(mp,fmt,args...) cmn_err(CE_NOTE,fmt, ## args)
113 #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
114 #define xfs_hex_dump(d,n) ((void) 0)
116 #define xfs_force_shutdown(d,n) ((void) 0)
118 /* stop unused var warnings by assigning mp to itself */
119 #define XFS_CORRUPTION_ERROR(e,l,mp,m) do { \
121 cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e)); \
124 #define XFS_ERROR_REPORT(e,l,mp) do { \
126 cmn_err(CE_ALERT, "%s: XFS_ERROR_REPORT", (e)); \
129 #define XFS_ERRLEVEL_LOW 1
130 #define XFS_FORCED_SHUTDOWN(mp) 0
131 #define XFS_ILOCK_EXCL 0
132 #define XFS_STATS_INC(mp, count) do { (mp) = (mp); } while (0)
133 #define XFS_STATS_DEC(mp, count, x) do { (mp) = (mp); } while (0)
134 #define XFS_STATS_ADD(mp, count, x) do { (mp) = (mp); } while (0)
135 #define XFS_TEST_ERROR(expr,a,b) ( expr )
136 #define XFS_WANT_CORRUPTED_GOTO(mp, expr, l) \
139 if ((mp)->m_flags & LIBXFS_MOUNT_WANT_CORRUPTED) \
140 printf("WANT_CORRUPTED_GOTO at %s:%d\n", \
141 __func__, __LINE__); \
142 error = -EFSCORRUPTED; \
146 #define XFS_WANT_CORRUPTED_RETURN(mp, expr) \
149 if ((mp)->m_flags & LIBXFS_MOUNT_WANT_CORRUPTED) \
150 printf("WANT_CORRUPTED_RETURN at %s:%d\n", \
151 __func__, __LINE__); \
152 return -EFSCORRUPTED; \
157 #define __return_address __builtin_return_address(0)
160 * Return the address of a label. Use barrier() so that the optimizer
161 * won't reorder code to refactor the error jumpouts into a single
162 * return, which throws off the reported address.
164 #define __this_address ({ __label__ __here; __here: barrier(); &&__here; })
165 /* Optimization barrier */
167 /* The "volatile" is due to gcc bugs */
168 #define barrier() __asm__ __volatile__("": : :"memory")
171 /* Optimization barrier */
173 # define barrier() __memory_barrier()
176 #define XFS_DQUOT_CLUSTER_SIZE_FSB (xfs_filblks_t)1
178 /* miscellaneous kernel routines not in user space */
179 #define down_read(a) ((void) 0)
180 #define up_read(a) ((void) 0)
181 #define spin_lock_init(a) ((void) 0)
182 #define spin_lock(a) ((void) 0)
183 #define spin_unlock(a) ((void) 0)
184 #define likely(x) (x)
185 #define unlikely(x) (x)
186 #define rcu_read_lock() ((void) 0)
187 #define rcu_read_unlock() ((void) 0)
188 /* Need to be able to handle this bare or in control flow */
189 static inline bool WARN_ON_ONCE(bool expr
) {
193 #define percpu_counter_read(x) (*x)
194 #define percpu_counter_read_positive(x) ((*x) > 0 ? (*x) : 0)
195 #define percpu_counter_sum(x) (*x)
198 * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs
199 * or all sorts of badness can occur!
201 #define prandom_u32() 0
203 #define PAGE_SIZE getpagesize()
205 static inline int __do_div(unsigned long long *n
, unsigned base
)
208 __res
= (int)(((unsigned long) *n
) % (unsigned) base
);
209 *n
= ((unsigned long) *n
) / (unsigned) base
;
213 #define do_div(n,base) (__do_div((unsigned long long *)&(n), (base)))
214 #define do_mod(a, b) ((a) % (b))
215 #define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
217 #define min_t(type,x,y) \
218 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
219 #define max_t(type,x,y) \
220 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
223 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
224 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
225 #define round_down(x, y) ((x) & ~__round_mask(x, y))
226 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
229 * Handling for kernel bitmap types.
231 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, NBBY * sizeof(long))
232 #define DECLARE_BITMAP(name,bits) \
233 unsigned long name[BITS_TO_LONGS(bits)]
234 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
237 * This is a common helper function for find_next_bit and
238 * find_next_zero_bit. The difference is the "invert" argument, which
239 * is XORed with each fetched word before searching it for one bits.
241 static inline unsigned long
242 _find_next_bit(const unsigned long *addr
, unsigned long nbits
,
243 unsigned long start
, unsigned long invert
)
247 if (!nbits
|| start
>= nbits
)
250 tmp
= addr
[start
/ BITS_PER_LONG
] ^ invert
;
252 /* Handle 1st word. */
253 tmp
&= BITMAP_FIRST_WORD_MASK(start
);
254 start
= round_down(start
, BITS_PER_LONG
);
257 start
+= BITS_PER_LONG
;
261 tmp
= addr
[start
/ BITS_PER_LONG
] ^ invert
;
264 return min(start
+ ffs(tmp
), nbits
);
268 * Find the next set bit in a memory region.
270 static inline unsigned long
271 find_next_bit(const unsigned long *addr
, unsigned long size
,
272 unsigned long offset
)
274 return _find_next_bit(addr
, size
, offset
, 0UL);
276 static inline unsigned long
277 find_next_zero_bit(const unsigned long *addr
, unsigned long size
,
278 unsigned long offset
)
280 return _find_next_bit(addr
, size
, offset
, ~0UL);
282 #define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
284 static inline __attribute__((const))
285 int is_power_of_2(unsigned long n
)
287 return (n
!= 0 && ((n
& (n
- 1)) == 0));
291 * xfs_iroundup: round up argument to next power of two
294 roundup_pow_of_two(uint v
)
299 if ((v
& (v
- 1)) == 0)
301 ASSERT((v
& 0x80000000) == 0);
302 if ((v
& (v
+ 1)) == 0)
304 for (i
= 0, m
= 1; i
< 31; i
++, m
<<= 1) {
308 if ((v
& (v
+ 1)) == 0)
315 static inline uint64_t
316 roundup_64(uint64_t x
, uint32_t y
)
323 /* buffer management */
324 #define XBF_TRYLOCK 0
325 #define XBF_UNMAPPED 0
327 #define xfs_buf_stale(bp) ((bp)->b_flags |= LIBXFS_B_STALE)
328 #define XFS_BUF_UNDELAYWRITE(bp) ((bp)->b_flags &= ~LIBXFS_B_DIRTY)
329 #define XFS_BUF_SET_BDSTRAT_FUNC(a,b) ((void) 0)
331 /* avoid gcc warning */
332 #define xfs_incore(bt,blkno,len,lockit) ({ \
333 typeof(blkno) __foo = (blkno); \
334 typeof(len) __bar = (len); \
336 (len) = __bar; /* no set-but-unused warning */ \
339 #define xfs_buf_relse(bp) libxfs_putbuf(bp)
340 #define xfs_buf_get(devp,blkno,len,f) (libxfs_getbuf((devp), (blkno), (len)))
341 #define xfs_bwrite(bp) libxfs_writebuf((bp), 0)
342 #define xfs_buf_delwri_queue(bp, bl) libxfs_writebuf((bp), 0)
344 #define XBRW_READ LIBXFS_BREAD
345 #define XBRW_WRITE LIBXFS_BWRITE
346 #define xfs_buf_iomove(bp,off,len,data,f) libxfs_iomove(bp,off,len,data,f)
347 #define xfs_buf_zero(bp,off,len) libxfs_iomove(bp,off,len,0,LIBXFS_BZERO)
350 #define XFS_MOUNT_32BITINODES LIBXFS_MOUNT_32BITINODES
351 #define XFS_MOUNT_ATTR2 LIBXFS_MOUNT_ATTR2
352 #define XFS_MOUNT_SMALL_INUMS 0 /* ignored in userspace */
353 #define XFS_MOUNT_WSYNC 0 /* ignored in userspace */
354 #define XFS_MOUNT_NOALIGN 0 /* ignored in userspace */
355 #define XFS_MOUNT_IKEEP 0 /* ignored in userspace */
356 #define XFS_MOUNT_SWALLOC 0 /* ignored in userspace */
357 #define XFS_MOUNT_RDONLY 0 /* ignored in userspace */
360 #define xfs_trans_set_sync(tp) ((void) 0)
361 #define xfs_trans_agblocks_delta(tp, d)
362 #define xfs_trans_agflist_delta(tp, d)
363 #define xfs_trans_agbtree_delta(tp, d)
364 #define xfs_trans_buf_set_type(tp, bp, t) ({ \
366 __t = __t; /* no set-but-unused warning */ \
367 tp = tp; /* no set-but-unused warning */ \
370 #define xfs_trans_buf_copy_type(dbp, sbp)
372 /* no readahead, need to avoid set-but-unused var warnings. */
373 #define xfs_buf_readahead(a,d,c,ops) ({ \
374 xfs_daddr_t __d = d; \
375 __d = __d; /* no set-but-unused warning */ \
377 #define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */
379 #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
380 #define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
381 #define xfs_alert_tag(mp,tag,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
383 #define xfs_sort qsort
385 #define xfs_ilock(ip,mode) ((void) 0)
386 #define xfs_ilock_nowait(ip,mode) ((void) 0)
387 #define xfs_ilock_demote(ip,mode) ((void) 0)
388 #define xfs_ilock_data_map_shared(ip) (0)
389 #define xfs_ilock_attr_map_shared(ip) (0)
390 #define xfs_iunlock(ip,mode) ({ \
391 typeof(mode) __mode = mode; \
392 __mode = __mode; /* no set-but-unused warning */ \
395 /* space allocation */
396 #define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0)
397 /* avoid unused variable warning */
398 #define xfs_extent_busy_insert(tp,ag,bno,len,flags)({ \
399 xfs_agnumber_t __foo = ag; \
400 __foo = __foo; /* no set-but-unused warning */ \
402 #define xfs_extent_busy_trim(args,bno,len,busy_gen) ({ \
403 unsigned __foo = *(busy_gen); \
404 *(busy_gen) = __foo; \
407 #define xfs_extent_busy_flush(mp,pag,busy_gen) ((void)(0))
409 #define xfs_rotorstep 1
410 #define xfs_bmap_rtalloc(a) (-ENOSYS)
411 #define xfs_get_extsz_hint(ip) (0)
412 #define xfs_get_cowextsz_hint(ip) (0)
413 #define xfs_inode_is_filestream(ip) (0)
414 #define xfs_filestream_lookup_ag(ip) (0)
415 #define xfs_filestream_new_ag(ip,ag) (0)
417 #define xfs_log_force(mp,flags) ((void) 0)
418 #define XFS_LOG_SYNC 1
421 #define xfs_trans_mod_dquot_byino(t,i,f,d) ((void) 0)
422 #define xfs_trans_reserve_quota_nblks(t,i,b,n,f) (0)
423 #define xfs_trans_unreserve_quota_nblks(t,i,b,n,f) ((void) 0)
424 #define xfs_qm_dqattach(i,f) (0)
426 #define uuid_copy(s,d) platform_uuid_copy((s),(d))
427 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
429 #define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0)
430 #define xfs_sb_validate_fsb_count(sbp, nblks) (0)
433 * Prototypes for kernel static functions that are aren't in their
434 * associated header files.
437 struct xfs_bmap_free
;
438 struct xfs_bmap_free_item
;
446 struct xfs_buf_log_item
;
450 int xfs_attr_rmtval_get(struct xfs_da_args
*);
453 void xfs_bmap_del_free(struct xfs_bmap_free
*, struct xfs_bmap_free_item
*);
456 int xfs_initialize_perag_data(struct xfs_mount
*, xfs_agnumber_t
);
457 void xfs_mount_common(struct xfs_mount
*, struct xfs_sb
*);
460 * logitem.c and trans.c prototypes
462 void xfs_trans_init(struct xfs_mount
*);
463 int xfs_trans_roll(struct xfs_trans
**);
465 /* xfs_trans_item.c */
466 void xfs_trans_add_item(struct xfs_trans
*, struct xfs_log_item
*);
467 void xfs_trans_del_item(struct xfs_log_item
*);
469 /* xfs_inode_item.c */
470 void xfs_inode_item_init(struct xfs_inode
*, struct xfs_mount
*);
473 void xfs_buf_item_init(struct xfs_buf
*, struct xfs_mount
*);
474 void xfs_buf_item_log(struct xfs_buf_log_item
*, uint
, uint
);
476 /* xfs_trans_buf.c */
477 struct xfs_buf
*xfs_trans_buf_item_match(struct xfs_trans
*,
478 struct xfs_buftarg
*, struct xfs_buf_map
*, int);
480 /* local source files */
481 #define xfs_mod_fdblocks(mp, delta, rsvd) \
482 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, rsvd)
483 #define xfs_mod_frextents(mp, delta) \
484 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, delta, 0)
485 int libxfs_mod_incore_sb(struct xfs_mount
*, int, int64_t, int);
486 /* percpu counters in mp are #defined to the superblock sb_ counters */
487 #define xfs_reinit_percpu_counters(mp)
489 void xfs_trans_mod_sb(struct xfs_trans
*, uint
, long);
490 void xfs_verifier_error(struct xfs_buf
*bp
);
492 /* XXX: this is clearly a bug - a shared header needs to export this */
494 int libxfs_rtfree_extent(struct xfs_trans
*, xfs_rtblock_t
, xfs_extlen_t
);
496 struct xfs_rtalloc_rec
{
497 xfs_rtblock_t ar_startblock
;
498 xfs_rtblock_t ar_blockcount
;
501 typedef int (*xfs_rtalloc_query_range_fn
)(
502 struct xfs_trans
*tp
,
503 struct xfs_rtalloc_rec
*rec
,
506 int libxfs_zero_extent(struct xfs_inode
*ip
, xfs_fsblock_t start_fsb
,
507 xfs_off_t count_fsb
);
509 bool xfs_log_check_lsn(struct xfs_mount
*, xfs_lsn_t
);
512 #define xfs_inode_set_cowblocks_tag(ip) do { } while (0)
513 #define xfs_inode_set_eofblocks_tag(ip) do { } while (0)
516 #define XFS_STATS_CALC_INDEX(member) 0
517 #define XFS_STATS_INC_OFF(mp, off)
518 #define XFS_STATS_ADD_OFF(mp, off, val)
520 typedef unsigned char u8
;
522 #endif /* __LIBXFS_INTERNAL_XFS_H__ */