]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/libxfs_priv.h
c14faca002cba36e3660aaa55567d3427751b440
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__
53 * Repair doesn't have a inode when it calls libxfs_dir2_data_freescan,
54 * so we to work around this internally for now.
56 #define xfs_dir2_data_freescan(ip, hdr, loghead) \
57 __xfs_dir2_data_freescan((ip)->i_mount->m_dir_geo, \
58 (ip)->d_ops, hdr, loghead)
60 #include "libxfs_api_defs.h"
61 #include "platform_defs.h"
69 #include "radix-tree.h"
72 #include "xfs_types.h"
77 /* CRC stuff, buffer API dependent on it */
78 extern uint32_t crc32_le(uint32_t crc
, unsigned char const *p
, size_t len
);
79 extern uint32_t crc32c_le(uint32_t crc
, unsigned char const *p
, size_t len
);
81 #define crc32(c,p,l) crc32_le((c),(unsigned char const *)(p),(l))
82 #define crc32c(c,p,l) crc32c_le((c),(unsigned char const *)(p),(l))
84 #include "xfs_cksum.h"
87 * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
88 * every files via a similar include in the kernel xfs_linux.h.
90 #include "libxfs_io.h"
92 /* for all the support code that uses progname in error messages */
93 extern char *progname
;
96 #define ASSERT(ex) assert(ex)
99 #define EWRONGFS EINVAL
102 #define xfs_error_level 0
104 #define STATIC static
106 /* XXX: need to push these out to make LIBXFS_ATTR defines */
107 #define ATTR_ROOT 0x0002
108 #define ATTR_SECURE 0x0008
109 #define ATTR_CREATE 0x0010
110 #define ATTR_REPLACE 0x0020
111 #define ATTR_KERNOTIME 0
112 #define ATTR_KERNOVAL 0
114 #define IHOLD(ip) ((void) 0)
116 #define XFS_IGET_CREATE 0x1
117 #define XFS_IGET_UNTRUSTED 0x2
119 extern void cmn_err(int, char *, ...);
120 enum ce
{ CE_DEBUG
, CE_CONT
, CE_NOTE
, CE_WARN
, CE_ALERT
, CE_PANIC
};
122 #define xfs_notice(mp,fmt,args...) cmn_err(CE_NOTE,fmt, ## args)
123 #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
124 #define xfs_hex_dump(d,n) ((void) 0)
126 #define xfs_force_shutdown(d,n) ((void) 0)
128 /* stop unused var warnings by assigning mp to itself */
129 #define XFS_CORRUPTION_ERROR(e,l,mp,m) do { \
131 cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e)); \
134 #define XFS_ERROR_REPORT(e,l,mp) do { \
136 cmn_err(CE_ALERT, "%s: XFS_ERROR_REPORT", (e)); \
139 #define XFS_QM_DQATTACH(mp,ip,flags) 0
140 #define XFS_ERRLEVEL_LOW 1
141 #define XFS_FORCED_SHUTDOWN(mp) 0
142 #define XFS_ILOCK_EXCL 0
143 #define XFS_STATS_INC(mp, count) do { } while (0)
144 #define XFS_STATS_DEC(mp, count, x) do { } while (0)
145 #define XFS_STATS_ADD(mp, count, x) do { } while (0)
146 #define XFS_TRANS_MOD_DQUOT_BYINO(mp,tp,ip,field,delta) do { } while (0)
147 #define XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0
148 #define XFS_TRANS_UNRESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0
149 #define XFS_TEST_ERROR(expr,a,b,c) ( expr )
150 #define XFS_WANT_CORRUPTED_GOTO(mp, expr, l) \
153 if ((mp)->m_flags & LIBXFS_MOUNT_WANT_CORRUPTED) \
154 printf("WANT_CORRUPTED_GOTO at %s:%d\n", \
155 __func__, __LINE__); \
156 error = -EFSCORRUPTED; \
160 #define XFS_WANT_CORRUPTED_RETURN(mp, expr) \
163 if ((mp)->m_flags & LIBXFS_MOUNT_WANT_CORRUPTED) \
164 printf("WANT_CORRUPTED_RETURN at %s:%d\n", \
165 __func__, __LINE__); \
166 return -EFSCORRUPTED; \
171 #define __return_address __builtin_return_address(0)
174 #define XFS_DQUOT_CLUSTER_SIZE_FSB (xfs_filblks_t)1
176 /* miscellaneous kernel routines not in user space */
177 #define down_read(a) ((void) 0)
178 #define up_read(a) ((void) 0)
179 #define spin_lock_init(a) ((void) 0)
180 #define spin_lock(a) ((void) 0)
181 #define spin_unlock(a) ((void) 0)
182 #define likely(x) (x)
183 #define unlikely(x) (x)
184 #define rcu_read_lock() ((void) 0)
185 #define rcu_read_unlock() ((void) 0)
186 #define WARN_ON_ONCE(expr) ((void) 0)
188 #define percpu_counter_read(x) (*x)
189 #define percpu_counter_read_positive(x) ((*x) > 0 ? (*x) : 0)
190 #define percpu_counter_sum(x) (*x)
193 * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs
194 * or all sorts of badness can occur!
196 #define prandom_u32() 0
198 #define PAGE_SIZE getpagesize()
200 static inline int __do_div(unsigned long long *n
, unsigned base
)
203 __res
= (int)(((unsigned long) *n
) % (unsigned) base
);
204 *n
= ((unsigned long) *n
) / (unsigned) base
;
208 #define do_div(n,base) (__do_div((unsigned long long *)&(n), (base)))
209 #define do_mod(a, b) ((a) % (b))
210 #define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
212 #define min_t(type,x,y) \
213 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
214 #define max_t(type,x,y) \
215 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
218 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
219 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
220 #define round_down(x, y) ((x) & ~__round_mask(x, y))
221 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
224 * Handling for kernel bitmap types.
226 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, NBBY * sizeof(long))
227 #define DECLARE_BITMAP(name,bits) \
228 unsigned long name[BITS_TO_LONGS(bits)]
229 #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
232 * This is a common helper function for find_next_bit and
233 * find_next_zero_bit. The difference is the "invert" argument, which
234 * is XORed with each fetched word before searching it for one bits.
236 static inline unsigned long
237 _find_next_bit(const unsigned long *addr
, unsigned long nbits
,
238 unsigned long start
, unsigned long invert
)
242 if (!nbits
|| start
>= nbits
)
245 tmp
= addr
[start
/ BITS_PER_LONG
] ^ invert
;
247 /* Handle 1st word. */
248 tmp
&= BITMAP_FIRST_WORD_MASK(start
);
249 start
= round_down(start
, BITS_PER_LONG
);
252 start
+= BITS_PER_LONG
;
256 tmp
= addr
[start
/ BITS_PER_LONG
] ^ invert
;
259 return min(start
+ ffs(tmp
), nbits
);
263 * Find the next set bit in a memory region.
265 static inline unsigned long
266 find_next_bit(const unsigned long *addr
, unsigned long size
,
267 unsigned long offset
)
269 return _find_next_bit(addr
, size
, offset
, 0UL);
271 static inline unsigned long
272 find_next_zero_bit(const unsigned long *addr
, unsigned long size
,
273 unsigned long offset
)
275 return _find_next_bit(addr
, size
, offset
, ~0UL);
277 #define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
279 static inline __attribute__((const))
280 int is_power_of_2(unsigned long n
)
282 return (n
!= 0 && ((n
& (n
- 1)) == 0));
286 * xfs_iroundup: round up argument to next power of two
289 roundup_pow_of_two(uint v
)
294 if ((v
& (v
- 1)) == 0)
296 ASSERT((v
& 0x80000000) == 0);
297 if ((v
& (v
+ 1)) == 0)
299 for (i
= 0, m
= 1; i
< 31; i
++, m
<<= 1) {
303 if ((v
& (v
+ 1)) == 0)
310 static inline __uint64_t
311 roundup_64(__uint64_t x
, __uint32_t y
)
318 /* buffer management */
319 #define XFS_BUF_LOCK 0
320 #define XFS_BUF_TRYLOCK 0
321 #define XBF_LOCK XFS_BUF_LOCK
322 #define XBF_TRYLOCK XFS_BUF_TRYLOCK
323 #define XBF_DONT_BLOCK 0
324 #define XBF_UNMAPPED 0
326 #define XFS_BUF_GETERROR(bp) 0
327 #define XFS_BUF_DONE(bp) ((bp)->b_flags |= LIBXFS_B_UPTODATE)
328 #define XFS_BUF_ISDONE(bp) ((bp)->b_flags & LIBXFS_B_UPTODATE)
329 #define xfs_buf_stale(bp) ((bp)->b_flags |= LIBXFS_B_STALE)
330 #define XFS_BUF_UNDELAYWRITE(bp) ((bp)->b_flags &= ~LIBXFS_B_DIRTY)
331 #define XFS_BUF_SET_VTYPE(a,b) ((void) 0)
332 #define XFS_BUF_SET_VTYPE_REF(a,b,c) ((void) 0)
333 #define XFS_BUF_SET_BDSTRAT_FUNC(a,b) ((void) 0)
335 /* avoid gcc warning */
336 #define xfs_incore(bt,blkno,len,lockit) ({ \
337 typeof(blkno) __foo = (blkno); \
338 typeof(len) __bar = (len); \
340 (len) = __bar; /* no set-but-unused warning */ \
343 #define xfs_buf_relse(bp) libxfs_putbuf(bp)
344 #define xfs_buf_get(devp,blkno,len,f) (libxfs_getbuf((devp), (blkno), (len)))
345 #define xfs_bwrite(bp) libxfs_writebuf((bp), 0)
346 #define xfs_buf_delwri_queue(bp, bl) libxfs_writebuf((bp), 0)
348 #define XBRW_READ LIBXFS_BREAD
349 #define XBRW_WRITE LIBXFS_BWRITE
350 #define xfs_buf_iomove(bp,off,len,data,f) libxfs_iomove(bp,off,len,data,f)
351 #define xfs_buf_zero(bp,off,len) libxfs_iomove(bp,off,len,0,LIBXFS_BZERO)
354 #define XFS_MOUNT_32BITINODES LIBXFS_MOUNT_32BITINODES
355 #define XFS_MOUNT_ATTR2 LIBXFS_MOUNT_ATTR2
356 #define XFS_MOUNT_SMALL_INUMS 0 /* ignored in userspace */
357 #define XFS_MOUNT_WSYNC 0 /* ignored in userspace */
358 #define XFS_MOUNT_NOALIGN 0 /* ignored in userspace */
359 #define XFS_MOUNT_IKEEP 0 /* ignored in userspace */
360 #define XFS_MOUNT_SWALLOC 0 /* ignored in userspace */
361 #define XFS_MOUNT_RDONLY 0 /* ignored in userspace */
364 #define _xfs_trans_alloc(mp, type, f) libxfs_trans_alloc(mp, type)
365 #define xfs_trans_get_block_res(tp) 1
366 #define xfs_trans_set_sync(tp) ((void) 0)
367 #define xfs_trans_ordered_buf(tp, bp) ((void) 0)
368 #define xfs_trans_agblocks_delta(tp, d)
369 #define xfs_trans_agflist_delta(tp, d)
370 #define xfs_trans_agbtree_delta(tp, d)
371 #define xfs_trans_buf_set_type(tp, bp, t) ({ \
373 __t = __t; /* no set-but-unused warning */ \
376 #define xfs_trans_buf_copy_type(dbp, sbp)
378 /* no readahead, need to avoid set-but-unused var warnings. */
379 #define xfs_buf_readahead(a,d,c,ops) ({ \
380 xfs_daddr_t __d = d; \
381 __d = __d; /* no set-but-unused warning */ \
383 #define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */
384 #define xfs_buftrace(x,y) ((void) 0) /* debug only */
386 #define xfs_cmn_err(tag,level,mp,fmt,args...) cmn_err(level,fmt, ## args)
387 #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
388 #define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
389 #define xfs_alert_tag(mp,tag,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
391 #define xfs_dir2_trace_args(where, args) ((void) 0)
392 #define xfs_dir2_trace_args_b(where, args, bp) ((void) 0)
393 #define xfs_dir2_trace_args_bb(where, args, lbp, dbp) ((void) 0)
394 #define xfs_dir2_trace_args_bibii(where, args, bs, ss, bd, sd, c) ((void) 0)
395 #define xfs_dir2_trace_args_db(where, args, db, bp) ((void) 0)
396 #define xfs_dir2_trace_args_i(where, args, i) ((void) 0)
397 #define xfs_dir2_trace_args_s(where, args, s) ((void) 0)
398 #define xfs_dir2_trace_args_sb(where, args, s, bp) ((void) 0)
399 #define xfs_sort qsort
401 #define xfs_icsb_reinit_counters(mp) do { } while (0)
402 #define xfs_initialize_perag_icache(pag) ((void) 0)
404 #define xfs_ilock(ip,mode) ((void) 0)
405 #define xfs_ilock_nowait(ip,mode) ((void) 0)
406 #define xfs_ilock_demote(ip,mode) ((void) 0)
407 #define xfs_ilock_data_map_shared(ip) (0)
408 #define xfs_ilock_attr_map_shared(ip) (0)
409 #define xfs_iunlock(ip,mode) ({ \
410 typeof(mode) __mode = mode; \
411 __mode = __mode; /* no set-but-unused warning */ \
413 #define __xfs_flock(ip) ((void) 0)
415 /* space allocation */
416 #define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0)
417 /* avoid unused variable warning */
418 #define xfs_extent_busy_insert(tp,ag,bno,len,flags)({ \
419 xfs_agnumber_t __foo = ag; \
420 __foo = __foo; /* no set-but-unused warning */ \
422 #define xfs_extent_busy_trim(args,fbno,flen,bno,len) \
428 /* avoid unused variable warning */
429 #define xfs_alloc_busy_insert(tp,ag,b,len) ({ \
430 xfs_agnumber_t __foo = ag; \
434 #define xfs_rotorstep 1
435 #define xfs_bmap_rtalloc(a) (-ENOSYS)
436 #define xfs_get_extsz_hint(ip) (0)
437 #define xfs_inode_is_filestream(ip) (0)
438 #define xfs_filestream_lookup_ag(ip) (0)
439 #define xfs_filestream_new_ag(ip,ag) (0)
441 #define xfs_log_force(mp,flags) ((void) 0)
442 #define XFS_LOG_SYNC 1
445 #define xfs_trans_mod_dquot_byino(t,i,f,d) ((void) 0)
446 #define xfs_trans_reserve_quota_nblks(t,i,b,n,f) (0)
447 #define xfs_trans_unreserve_quota_nblks(t,i,b,n,f) ((void) 0)
448 #define xfs_qm_dqattach(i,f) (0)
450 #define uuid_copy(s,d) platform_uuid_copy((s),(d))
451 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
453 #define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0)
454 #define xfs_sb_validate_fsb_count(sbp, nblks) (0)
457 * Prototypes for kernel static functions that are aren't in their
458 * associated header files.
461 struct xfs_bmap_free
;
462 struct xfs_bmap_free_item
;
470 struct xfs_buf_log_item
;
474 int xfs_attr_rmtval_get(struct xfs_da_args
*);
477 void xfs_bmap_del_free(struct xfs_bmap_free
*, struct xfs_bmap_free_item
*,
478 struct xfs_bmap_free_item
*);
481 int xfs_initialize_perag_data(struct xfs_mount
*, xfs_agnumber_t
);
482 void xfs_mount_common(struct xfs_mount
*, struct xfs_sb
*);
485 * logitem.c and trans.c prototypes
487 void xfs_trans_init(struct xfs_mount
*);
488 int xfs_trans_roll(struct xfs_trans
**, struct xfs_inode
*);
490 /* xfs_trans_item.c */
491 void xfs_trans_add_item(struct xfs_trans
*, struct xfs_log_item
*);
492 void xfs_trans_del_item(struct xfs_log_item
*);
494 /* xfs_inode_item.c */
495 void xfs_inode_item_init(struct xfs_inode
*, struct xfs_mount
*);
498 void xfs_buf_item_init(struct xfs_buf
*, struct xfs_mount
*);
499 void xfs_buf_item_log(struct xfs_buf_log_item
*, uint
, uint
);
501 /* xfs_trans_buf.c */
502 struct xfs_buf
*xfs_trans_buf_item_match(struct xfs_trans
*,
503 struct xfs_buftarg
*, struct xfs_buf_map
*, int);
505 /* local source files */
506 #define xfs_mod_fdblocks(mp, delta, rsvd) \
507 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, rsvd)
508 #define xfs_mod_frextents(mp, delta) \
509 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, delta, 0)
510 int libxfs_mod_incore_sb(struct xfs_mount
*, int, int64_t, int);
511 /* percpu counters in mp are #defined to the superblock sb_ counters */
512 #define xfs_reinit_percpu_counters(mp)
514 void xfs_trans_mod_sb(struct xfs_trans
*, uint
, long);
515 void xfs_trans_init(struct xfs_mount
*);
516 int xfs_trans_roll(struct xfs_trans
**, struct xfs_inode
*);
517 void xfs_verifier_error(struct xfs_buf
*bp
);
519 /* XXX: this is clearly a bug - a shared header needs to export this */
521 int libxfs_rtfree_extent(struct xfs_trans
*, xfs_rtblock_t
, xfs_extlen_t
);
523 int libxfs_zero_extent(struct xfs_inode
*ip
, xfs_fsblock_t start_fsb
,
524 xfs_off_t count_fsb
);
526 bool xfs_log_check_lsn(struct xfs_mount
*, xfs_lsn_t
);
528 #endif /* __LIBXFS_INTERNAL_XFS_H__ */