]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/libxfs_priv.h
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 "xfs/platform_defs.h"
64 #include "xfs/hlist.h"
65 #include "xfs/cache.h"
66 #include "xfs/bitops.h"
68 #include "xfs/radix-tree.h"
70 #include "xfs/atomic.h"
72 #include "xfs/xfs_types.h"
73 #include "xfs/xfs_arch.h"
75 #include "xfs/xfs_fs.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/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)
98 typedef __uint32_t uint_t
;
101 #define EWRONGFS EINVAL
104 #define xfs_error_level 0
106 #define STATIC static
108 /* XXX: need to push these out to make LIBXFS_ATTR defines */
109 #define ATTR_ROOT 0x0002
110 #define ATTR_SECURE 0x0008
111 #define ATTR_CREATE 0x0010
112 #define ATTR_REPLACE 0x0020
113 #define ATTR_KERNOTIME 0
114 #define ATTR_KERNOVAL 0
116 #define IHOLD(ip) ((void) 0)
118 #define XFS_IGET_CREATE 0x1
119 #define XFS_IGET_UNTRUSTED 0x2
121 extern void cmn_err(int, char *, ...);
122 enum ce
{ CE_DEBUG
, CE_CONT
, CE_NOTE
, CE_WARN
, CE_ALERT
, CE_PANIC
};
124 #define xfs_notice(mp,fmt,args...) cmn_err(CE_NOTE,fmt, ## args)
125 #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
126 #define xfs_hex_dump(d,n) ((void) 0)
129 /* stop unused var warnings by assigning mp to itself */
130 #define XFS_CORRUPTION_ERROR(e,l,mp,m) do { \
132 cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e)); \
135 #define XFS_ERROR_REPORT(e,l,mp) do { \
137 cmn_err(CE_ALERT, "%s: XFS_ERROR_REPORT", (e)); \
140 #define XFS_QM_DQATTACH(mp,ip,flags) 0
141 #define XFS_ERRLEVEL_LOW 1
142 #define XFS_FORCED_SHUTDOWN(mp) 0
143 #define XFS_ILOCK_EXCL 0
144 #define XFS_STATS_INC(count) do { } while (0)
145 #define XFS_STATS_DEC(count, x) do { } while (0)
146 #define XFS_STATS_ADD(count, x) do { } while (0)
147 #define XFS_TRANS_MOD_DQUOT_BYINO(mp,tp,ip,field,delta) do { } while (0)
148 #define XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0
149 #define XFS_TRANS_UNRESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0
150 #define XFS_TEST_ERROR(expr,a,b,c) ( expr )
151 #define XFS_WANT_CORRUPTED_GOTO(mp, expr, l) \
152 { (mp) = (mp); if (!(expr)) { error = EFSCORRUPTED; goto l; } }
153 #define XFS_WANT_CORRUPTED_RETURN(mp, expr) \
154 { (mp) = (mp); if (!(expr)) { return EFSCORRUPTED; } }
157 #define __return_address __builtin_return_address(0)
160 #define XFS_DQUOT_CLUSTER_SIZE_FSB (xfs_filblks_t)1
162 /* miscellaneous kernel routines not in user space */
163 #define down_read(a) ((void) 0)
164 #define up_read(a) ((void) 0)
165 #define spin_lock_init(a) ((void) 0)
166 #define spin_lock(a) ((void) 0)
167 #define spin_unlock(a) ((void) 0)
168 #define likely(x) (x)
169 #define unlikely(x) (x)
170 #define rcu_read_lock() ((void) 0)
171 #define rcu_read_unlock() ((void) 0)
172 #define WARN_ON_ONCE(expr) ((void) 0)
174 #define percpu_counter_read(x) (*x)
175 #define percpu_counter_sum(x) (*x)
178 * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs
179 * or all sorts of badness can occur!
181 #define prandom_u32() 0
183 #define PAGE_CACHE_SIZE getpagesize()
185 static inline int __do_div(unsigned long long *n
, unsigned base
)
188 __res
= (int)(((unsigned long) *n
) % (unsigned) base
);
189 *n
= ((unsigned long) *n
) / (unsigned) base
;
193 #define do_div(n,base) (__do_div((unsigned long long *)&(n), (base)))
194 #define do_mod(a, b) ((a) % (b))
195 #define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
197 #define min_t(type,x,y) \
198 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
199 #define max_t(type,x,y) \
200 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
204 static inline __attribute__((const))
205 int is_power_of_2(unsigned long n
)
207 return (n
!= 0 && ((n
& (n
- 1)) == 0));
211 * xfs_iroundup: round up argument to next power of two
214 roundup_pow_of_two(uint v
)
219 if ((v
& (v
- 1)) == 0)
221 ASSERT((v
& 0x80000000) == 0);
222 if ((v
& (v
+ 1)) == 0)
224 for (i
= 0, m
= 1; i
< 31; i
++, m
<<= 1) {
228 if ((v
& (v
+ 1)) == 0)
235 static inline __uint64_t
236 roundup_64(__uint64_t x
, __uint32_t y
)
243 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
244 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
245 #define round_down(x, y) ((x) & ~__round_mask(x, y))
247 /* buffer management */
248 #define XFS_BUF_LOCK 0
249 #define XFS_BUF_TRYLOCK 0
250 #define XBF_LOCK XFS_BUF_LOCK
251 #define XBF_TRYLOCK XFS_BUF_TRYLOCK
252 #define XBF_DONT_BLOCK 0
253 #define XBF_UNMAPPED 0
255 #define XFS_BUF_GETERROR(bp) 0
256 #define XFS_BUF_DONE(bp) ((bp)->b_flags |= LIBXFS_B_UPTODATE)
257 #define XFS_BUF_ISDONE(bp) ((bp)->b_flags & LIBXFS_B_UPTODATE)
258 #define xfs_buf_stale(bp) ((bp)->b_flags |= LIBXFS_B_STALE)
259 #define XFS_BUF_UNDELAYWRITE(bp) ((bp)->b_flags &= ~LIBXFS_B_DIRTY)
260 #define XFS_BUF_SET_VTYPE(a,b) ((void) 0)
261 #define XFS_BUF_SET_VTYPE_REF(a,b,c) ((void) 0)
262 #define XFS_BUF_SET_BDSTRAT_FUNC(a,b) ((void) 0)
264 /* avoid gcc warning */
265 #define xfs_incore(bt,blkno,len,lockit) ({ \
266 typeof(blkno) __foo = (blkno); \
267 typeof(len) __bar = (len); \
269 (len) = __bar; /* no set-but-unused warning */ \
272 #define xfs_buf_relse(bp) libxfs_putbuf(bp)
273 #define xfs_buf_get(devp,blkno,len,f) (libxfs_getbuf((devp), (blkno), (len)))
274 #define xfs_bwrite(bp) libxfs_writebuf((bp), 0)
275 #define xfs_buf_delwri_queue(bp, bl) libxfs_writebuf((bp), 0)
277 #define XBRW_READ LIBXFS_BREAD
278 #define XBRW_WRITE LIBXFS_BWRITE
279 #define xfs_buf_iomove(bp,off,len,data,f) libxfs_iomove(bp,off,len,data,f)
280 #define xfs_buf_zero(bp,off,len) libxfs_iomove(bp,off,len,0,LIBXFS_BZERO)
283 #define XFS_MOUNT_32BITINODES LIBXFS_MOUNT_32BITINODES
284 #define XFS_MOUNT_ATTR2 LIBXFS_MOUNT_ATTR2
285 #define XFS_MOUNT_SMALL_INUMS 0 /* ignored in userspace */
286 #define XFS_MOUNT_WSYNC 0 /* ignored in userspace */
287 #define XFS_MOUNT_NOALIGN 0 /* ignored in userspace */
288 #define XFS_MOUNT_IKEEP 0 /* ignored in userspace */
289 #define XFS_MOUNT_SWALLOC 0 /* ignored in userspace */
290 #define XFS_MOUNT_RDONLY 0 /* ignored in userspace */
293 #define _xfs_trans_alloc(mp, type, f) libxfs_trans_alloc(mp, type)
294 #define xfs_trans_get_block_res(tp) 1
295 #define xfs_trans_set_sync(tp) ((void) 0)
296 #define xfs_trans_ordered_buf(tp, bp) ((void) 0)
297 #define xfs_trans_agblocks_delta(tp, d)
298 #define xfs_trans_agflist_delta(tp, d)
299 #define xfs_trans_agbtree_delta(tp, d)
300 #define xfs_trans_buf_set_type(tp, bp, t) ({ \
302 __t = __t; /* no set-but-unused warning */ \
305 #define xfs_trans_buf_copy_type(dbp, sbp)
307 /* no readahead, need to avoid set-but-unused var warnings. */
308 #define xfs_buf_readahead(a,d,c,ops) ({ \
309 xfs_daddr_t __d = d; \
310 __d = __d; /* no set-but-unused warning */ \
312 #define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */
313 #define xfs_buftrace(x,y) ((void) 0) /* debug only */
315 #define xfs_cmn_err(tag,level,mp,fmt,args...) cmn_err(level,fmt, ## args)
316 #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args)
317 #define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
318 #define xfs_alert_tag(mp,tag,fmt,args...) cmn_err(CE_ALERT,fmt, ## args)
320 #define xfs_dir2_trace_args(where, args) ((void) 0)
321 #define xfs_dir2_trace_args_b(where, args, bp) ((void) 0)
322 #define xfs_dir2_trace_args_bb(where, args, lbp, dbp) ((void) 0)
323 #define xfs_dir2_trace_args_bibii(where, args, bs, ss, bd, sd, c) ((void) 0)
324 #define xfs_dir2_trace_args_db(where, args, db, bp) ((void) 0)
325 #define xfs_dir2_trace_args_i(where, args, i) ((void) 0)
326 #define xfs_dir2_trace_args_s(where, args, s) ((void) 0)
327 #define xfs_dir2_trace_args_sb(where, args, s, bp) ((void) 0)
328 #define xfs_sort qsort
330 #define xfs_icsb_reinit_counters(mp) do { } while (0)
331 #define xfs_initialize_perag_icache(pag) ((void) 0)
333 #define xfs_ilock(ip,mode) ((void) 0)
334 #define xfs_ilock_nowait(ip,mode) ((void) 0)
335 #define xfs_ilock_demote(ip,mode) ((void) 0)
336 #define xfs_ilock_data_map_shared(ip) (0)
337 #define xfs_ilock_attr_map_shared(ip) (0)
338 #define xfs_iunlock(ip,mode) ({ \
339 typeof(mode) __mode = mode; \
340 __mode = __mode; /* no set-but-unused warning */ \
342 #define __xfs_flock(ip) ((void) 0)
344 /* space allocation */
345 #define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0)
346 /* avoid unused variable warning */
347 #define xfs_extent_busy_insert(tp,ag,bno,len,flags)({ \
348 xfs_agnumber_t __foo = ag; \
349 __foo = __foo; /* no set-but-unused warning */ \
351 #define xfs_extent_busy_trim(args,fbno,flen,bno,len) \
357 /* avoid unused variable warning */
358 #define xfs_alloc_busy_insert(tp,ag,b,len) ({ \
359 xfs_agnumber_t __foo = ag; \
363 #define xfs_rotorstep 1
364 #define xfs_bmap_rtalloc(a) (ENOSYS)
365 #define xfs_rtpick_extent(mp,tp,len,p) (ENOSYS)
366 #define xfs_get_extsz_hint(ip) (0)
367 #define xfs_inode_is_filestream(ip) (0)
368 #define xfs_filestream_lookup_ag(ip) (0)
369 #define xfs_filestream_new_ag(ip,ag) (0)
371 #define xfs_log_force(mp,flags) ((void) 0)
372 #define XFS_LOG_SYNC 1
375 #define xfs_trans_mod_dquot_byino(t,i,f,d) ((void) 0)
376 #define xfs_trans_reserve_quota_nblks(t,i,b,n,f) (0)
377 #define xfs_trans_unreserve_quota_nblks(t,i,b,n,f) ((void) 0)
378 #define xfs_qm_dqattach(i,f) (0)
380 #define uuid_copy(s,d) platform_uuid_copy((s),(d))
381 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
383 #define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0)
384 #define xfs_sb_validate_fsb_count(sbp, nblks) (0)
387 * Prototypes for kernel static functions that are aren't in their
388 * associated header files.
391 struct xfs_bmap_free
;
392 struct xfs_bmap_free_item
;
400 struct xfs_buf_log_item
;
404 int xfs_attr_rmtval_get(struct xfs_da_args
*);
407 void xfs_bmap_del_free(struct xfs_bmap_free
*, struct xfs_bmap_free_item
*,
408 struct xfs_bmap_free_item
*);
411 int xfs_initialize_perag_data(struct xfs_mount
*, xfs_agnumber_t
);
412 void xfs_mount_common(struct xfs_mount
*, struct xfs_sb
*);
415 * logitem.c and trans.c prototypes
417 void xfs_trans_init(struct xfs_mount
*);
418 int xfs_trans_roll(struct xfs_trans
**, struct xfs_inode
*);
420 /* xfs_trans_item.c */
421 void xfs_trans_add_item(struct xfs_trans
*, struct xfs_log_item
*);
422 void xfs_trans_del_item(struct xfs_log_item
*);
424 /* xfs_inode_item.c */
425 void xfs_inode_item_init(struct xfs_inode
*, struct xfs_mount
*);
428 void xfs_buf_item_init(struct xfs_buf
*, struct xfs_mount
*);
429 void xfs_buf_item_log(struct xfs_buf_log_item
*, uint
, uint
);
431 /* xfs_trans_buf.c */
432 struct xfs_buf
*xfs_trans_buf_item_match(struct xfs_trans
*,
433 struct xfs_buftarg
*, struct xfs_buf_map
*, int);
435 /* local source files */
436 #define xfs_mod_fdblocks(mp, delta, rsvd) \
437 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FDBLOCKS, delta, rsvd)
438 #define xfs_mod_frextents(mp, delta) \
439 libxfs_mod_incore_sb(mp, XFS_TRANS_SB_FREXTENTS, delta, 0)
440 int libxfs_mod_incore_sb(struct xfs_mount
*, int, int64_t, int);
441 void xfs_reinit_percpu_counters(struct xfs_mount
*mp
);
443 void xfs_trans_mod_sb(struct xfs_trans
*, uint
, long);
444 void xfs_trans_init(struct xfs_mount
*);
445 int xfs_trans_roll(struct xfs_trans
**, struct xfs_inode
*);
446 void xfs_verifier_error(struct xfs_buf
*bp
);
448 /* XXX: this is clearly a bug - a shared header needs to export this */
450 int libxfs_rtfree_extent(struct xfs_trans
*, xfs_rtblock_t
, xfs_extlen_t
);
452 #endif /* __LIBXFS_INTERNAL_XFS_H__ */