]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/libxfs_priv.h
xfsprogs: remove the unused inst_t typedef
[thirdparty/xfsprogs-dev.git] / libxfs / libxfs_priv.h
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19 /*
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.
26 *
27 * It should only ever be #include'd by XFS "kernel" code being
28 * compiled in user space.
29 *
30 * Our goals here are to...
31 * o "share" large amounts of complex code between user and
32 * kernel space;
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.
43 */
44
45 /*
46 * define a guard and something we can check to determine what include context
47 * we are running from.
48 */
49 #ifndef __LIBXFS_INTERNAL_XFS_H__
50 #define __LIBXFS_INTERNAL_XFS_H__
51
52 /*
53 * Repair doesn't have a inode when it calls libxfs_dir2_data_freescan,
54 * so we to work around this internally for now.
55 */
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)
59
60 #include "libxfs_api_defs.h"
61 #include "xfs/platform_defs.h"
62
63 #include "xfs/list.h"
64 #include "xfs/hlist.h"
65 #include "xfs/cache.h"
66 #include "xfs/bitops.h"
67 #include "xfs/kmem.h"
68 #include "xfs/radix-tree.h"
69 #include "xfs/swab.h"
70 #include "xfs/atomic.h"
71
72 #include "xfs/xfs_types.h"
73 #include "xfs/xfs_arch.h"
74
75 #include "xfs/xfs_fs.h"
76
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);
80
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))
83
84 #include "xfs/xfs_cksum.h"
85
86 /*
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.
89 */
90 #include "libxfs_io.h"
91
92 /* for all the support code that uses progname in error messages */
93 extern char *progname;
94
95 #undef ASSERT
96 #define ASSERT(ex) assert(ex)
97
98 typedef __uint32_t uint_t;
99
100 #ifndef EWRONGFS
101 #define EWRONGFS EINVAL
102 #endif
103
104 #define xfs_error_level 0
105
106 #define STATIC static
107
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
115
116 #define IHOLD(ip) ((void) 0)
117
118 #define XFS_IGET_CREATE 0x1
119 #define XFS_IGET_UNTRUSTED 0x2
120
121 extern void cmn_err(int, char *, ...);
122 enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
123
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)
127
128
129 /* stop unused var warnings by assigning mp to itself */
130 #define XFS_CORRUPTION_ERROR(e,l,mp,m) do { \
131 (mp) = (mp); \
132 cmn_err(CE_ALERT, "%s: XFS_CORRUPTION_ERROR", (e)); \
133 } while (0)
134
135 #define XFS_ERROR_REPORT(e,l,mp) do { \
136 (mp) = (mp); \
137 cmn_err(CE_ALERT, "%s: XFS_ERROR_REPORT", (e)); \
138 } while (0)
139
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; } }
155
156 #ifdef __GNUC__
157 #define __return_address __builtin_return_address(0)
158 #endif
159
160 #define XFS_DQUOT_CLUSTER_SIZE_FSB (xfs_filblks_t)1
161
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)
173
174 #define percpu_counter_read(x) (*x)
175 #define percpu_counter_sum(x) (*x)
176
177 /*
178 * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs
179 * or all sorts of badness can occur!
180 */
181 #define prandom_u32() 0
182
183 #define PAGE_CACHE_SIZE getpagesize()
184
185 static inline int __do_div(unsigned long long *n, unsigned base)
186 {
187 int __res;
188 __res = (int)(((unsigned long) *n) % (unsigned) base);
189 *n = ((unsigned long) *n) / (unsigned) base;
190 return __res;
191 }
192
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))))
196
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; })
201
202
203
204 static inline __attribute__((const))
205 int is_power_of_2(unsigned long n)
206 {
207 return (n != 0 && ((n & (n - 1)) == 0));
208 }
209
210 /*
211 * xfs_iroundup: round up argument to next power of two
212 */
213 static inline uint
214 roundup_pow_of_two(uint v)
215 {
216 int i;
217 uint m;
218
219 if ((v & (v - 1)) == 0)
220 return v;
221 ASSERT((v & 0x80000000) == 0);
222 if ((v & (v + 1)) == 0)
223 return v + 1;
224 for (i = 0, m = 1; i < 31; i++, m <<= 1) {
225 if (v & m)
226 continue;
227 v |= m;
228 if ((v & (v + 1)) == 0)
229 return v + 1;
230 }
231 ASSERT(0);
232 return 0;
233 }
234
235 static inline __uint64_t
236 roundup_64(__uint64_t x, __uint32_t y)
237 {
238 x += y - 1;
239 do_div(x, y);
240 return x * y;
241 }
242
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))
246
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
254 #define XBF_DONE 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)
263
264 /* avoid gcc warning */
265 #define xfs_incore(bt,blkno,len,lockit) ({ \
266 typeof(blkno) __foo = (blkno); \
267 typeof(len) __bar = (len); \
268 (blkno) = __foo; \
269 (len) = __bar; /* no set-but-unused warning */ \
270 NULL; \
271 })
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)
276
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)
281
282 /* mount stuff */
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 */
291
292
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) ({ \
301 int __t = (t); \
302 __t = __t; /* no set-but-unused warning */ \
303 })
304
305 #define xfs_trans_buf_copy_type(dbp, sbp)
306
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 */ \
311 })
312 #define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */
313 #define xfs_buftrace(x,y) ((void) 0) /* debug only */
314
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)
319
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
329
330 #define xfs_icsb_reinit_counters(mp) do { } while (0)
331 #define xfs_initialize_perag_icache(pag) ((void) 0)
332
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 */ \
341 })
342 #define __xfs_flock(ip) ((void) 0)
343
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 */ \
350 })
351 #define xfs_extent_busy_trim(args,fbno,flen,bno,len) \
352 do { \
353 *(bno) = (fbno); \
354 *(len) = (flen); \
355 } while (0)
356
357 /* avoid unused variable warning */
358 #define xfs_alloc_busy_insert(tp,ag,b,len) ({ \
359 xfs_agnumber_t __foo = ag; \
360 __foo = 0; \
361 })
362
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)
370
371 #define xfs_log_force(mp,flags) ((void) 0)
372 #define XFS_LOG_SYNC 1
373
374 /* quota bits */
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)
379
380 #define uuid_copy(s,d) platform_uuid_copy((s),(d))
381 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
382
383 #define xfs_icreate_log(tp, agno, agbno, cnt, isize, len, gen) ((void) 0)
384 #define xfs_sb_validate_fsb_count(sbp, nblks) (0)
385
386 /*
387 * Prototypes for kernel static functions that are aren't in their
388 * associated header files.
389 */
390 struct xfs_da_args;
391 struct xfs_bmap_free;
392 struct xfs_bmap_free_item;
393 struct xfs_mount;
394 struct xfs_sb;
395 struct xfs_trans;
396 struct xfs_inode;
397 struct xfs_log_item;
398 struct xfs_buf;
399 struct xfs_buf_map;
400 struct xfs_buf_log_item;
401 struct xfs_buftarg;
402
403 /* xfs_attr.c */
404 int xfs_attr_rmtval_get(struct xfs_da_args *);
405
406 /* xfs_bmap.c */
407 void xfs_bmap_del_free(struct xfs_bmap_free *, struct xfs_bmap_free_item *,
408 struct xfs_bmap_free_item *);
409
410 /* xfs_mount.c */
411 int xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
412 void xfs_mount_common(struct xfs_mount *, struct xfs_sb *);
413
414 /*
415 * logitem.c and trans.c prototypes
416 */
417 void xfs_trans_init(struct xfs_mount *);
418 int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *);
419
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 *);
423
424 /* xfs_inode_item.c */
425 void xfs_inode_item_init(struct xfs_inode *, struct xfs_mount *);
426
427 /* xfs_buf_item.c */
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);
430
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);
434
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);
442
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);
447
448 /* XXX: this is clearly a bug - a shared header needs to export this */
449 /* xfs_rtalloc.c */
450 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
451
452 #endif /* __LIBXFS_INTERNAL_XFS_H__ */