]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
2bd0ea18 | 4 | * |
da23017d NS |
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 | |
2bd0ea18 NS |
7 | * published by the Free Software Foundation. |
8 | * | |
da23017d NS |
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. | |
2bd0ea18 | 13 | * |
da23017d NS |
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 | |
2bd0ea18 NS |
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. | |
dfc130f3 | 29 | * |
2bd0ea18 NS |
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 | ||
1d7e80ee | 45 | #include <xfs/libxfs.h> |
a2ceac1f | 46 | #include "xfs_dir2_priv.h" |
2bd0ea18 | 47 | |
a2ceac1f DC |
48 | #undef ASSERT |
49 | #define ASSERT(ex) assert(ex) | |
5e656dbb | 50 | |
a2ceac1f | 51 | typedef __uint32_t uint_t; |
5e656dbb BN |
52 | typedef __uint32_t inst_t; /* an instruction */ |
53 | ||
a2ceac1f DC |
54 | #ifndef EWRONGFS |
55 | #define EWRONGFS EINVAL | |
56 | #endif | |
5e656dbb | 57 | |
a2ceac1f DC |
58 | #define m_ddev_targp m_dev |
59 | #define m_logdev_targp m_logdev | |
60 | #define m_rtdev_targp m_rtdev | |
56b2de80 | 61 | #define xfs_error_level 0 |
5e656dbb BN |
62 | |
63 | #define STATIC static | |
5e656dbb BN |
64 | |
65 | #define ATTR_ROOT LIBXFS_ATTR_ROOT | |
66 | #define ATTR_SECURE LIBXFS_ATTR_SECURE | |
67 | #define ATTR_CREATE LIBXFS_ATTR_CREATE | |
68 | #define ATTR_REPLACE LIBXFS_ATTR_REPLACE | |
69 | #define ATTR_KERNOTIME 0 | |
70 | #define ATTR_KERNOVAL 0 | |
71 | ||
72 | #define IHOLD(ip) ((void) 0) | |
73 | ||
a2ceac1f DC |
74 | /* stop unused var warnings by assigning mp to itself */ |
75 | #define XFS_CORRUPTION_ERROR(e,l,mp,m) do { (mp) = (mp); } while (0) | |
76 | #define XFS_ERROR_REPORT(e,l,mp) do { (mp) = (mp); } while (0) | |
5e656dbb BN |
77 | #define XFS_QM_DQATTACH(mp,ip,flags) 0 |
78 | #define XFS_ERROR(e) (e) | |
5e656dbb BN |
79 | #define XFS_ERRLEVEL_LOW 1 |
80 | #define XFS_FORCED_SHUTDOWN(mp) 0 | |
81 | #define XFS_ILOCK_EXCL 0 | |
82 | #define XFS_STATS_INC(count) do { } while (0) | |
83 | #define XFS_STATS_DEC(count, x) do { } while (0) | |
84 | #define XFS_STATS_ADD(count, x) do { } while (0) | |
85 | #define XFS_TRANS_MOD_DQUOT_BYINO(mp,tp,ip,field,delta) do { } while (0) | |
86 | #define XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0 | |
87 | #define XFS_TRANS_UNRESERVE_QUOTA_NBLKS(mp,tp,ip,nblks,ninos,fl) 0 | |
88 | #define XFS_TEST_ERROR(expr,a,b,c) ( expr ) | |
89 | #define XFS_WANT_CORRUPTED_GOTO(expr,l) \ | |
90 | { if (!(expr)) { error = EFSCORRUPTED; goto l; } } | |
91 | #define XFS_WANT_CORRUPTED_RETURN(expr) \ | |
92 | { if (!(expr)) { return EFSCORRUPTED; } } | |
93 | ||
5e656dbb BN |
94 | #ifdef __GNUC__ |
95 | #define __return_address __builtin_return_address(0) | |
96 | #endif | |
97 | ||
98 | /* miscellaneous kernel routines not in user space */ | |
99 | #define down_read(a) ((void) 0) | |
100 | #define up_read(a) ((void) 0) | |
101 | #define spin_lock_init(a) ((void) 0) | |
102 | #define spin_lock(a) ((void) 0) | |
103 | #define spin_unlock(a) ((void) 0) | |
104 | #define likely(x) (x) | |
105 | #define unlikely(x) (x) | |
56b2de80 DC |
106 | #define rcu_read_lock() ((void) 0) |
107 | #define rcu_read_unlock() ((void) 0) | |
5e656dbb | 108 | |
2bd0ea18 | 109 | /* |
49f693fa | 110 | * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs |
5e656dbb | 111 | * or all sorts of badness can occur! |
2bd0ea18 | 112 | */ |
49f693fa | 113 | #define prandom_u32() 0 |
2bd0ea18 | 114 | |
5e656dbb | 115 | #define PAGE_CACHE_SIZE getpagesize() |
2bd0ea18 | 116 | |
5e656dbb BN |
117 | static inline int __do_div(unsigned long long *n, unsigned base) |
118 | { | |
119 | int __res; | |
120 | __res = (int)(((unsigned long) *n) % (unsigned) base); | |
121 | *n = ((unsigned long) *n) / (unsigned) base; | |
122 | return __res; | |
123 | } | |
124 | ||
125 | #define do_div(n,base) (__do_div((unsigned long long *)&(n), (base))) | |
126 | #define do_mod(a, b) ((a) % (b)) | |
127 | #define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) | |
2bd0ea18 | 128 | |
5e656dbb BN |
129 | #define min_t(type,x,y) \ |
130 | ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) | |
131 | #define max_t(type,x,y) \ | |
132 | ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) | |
57c9fccb | 133 | |
91eba724 | 134 | |
91eba724 | 135 | |
5e656dbb BN |
136 | static inline __attribute__((const)) |
137 | int is_power_of_2(unsigned long n) | |
138 | { | |
139 | return (n != 0 && ((n & (n - 1)) == 0)); | |
140 | } | |
2bd0ea18 NS |
141 | |
142 | /* | |
5e656dbb | 143 | * xfs_iroundup: round up argument to next power of two |
2bd0ea18 | 144 | */ |
5e656dbb BN |
145 | static inline uint |
146 | roundup_pow_of_two(uint v) | |
147 | { | |
148 | int i; | |
149 | uint m; | |
150 | ||
151 | if ((v & (v - 1)) == 0) | |
152 | return v; | |
153 | ASSERT((v & 0x80000000) == 0); | |
154 | if ((v & (v + 1)) == 0) | |
155 | return v + 1; | |
156 | for (i = 0, m = 1; i < 31; i++, m <<= 1) { | |
157 | if (v & m) | |
158 | continue; | |
159 | v |= m; | |
160 | if ((v & (v + 1)) == 0) | |
161 | return v + 1; | |
162 | } | |
163 | ASSERT(0); | |
164 | return 0; | |
165 | } | |
2bd0ea18 NS |
166 | |
167 | /* buffer management */ | |
168 | #define XFS_BUF_LOCK 0 | |
2bd0ea18 | 169 | #define XFS_BUF_TRYLOCK 0 |
56b2de80 DC |
170 | #define XBF_LOCK XFS_BUF_LOCK |
171 | #define XBF_TRYLOCK XFS_BUF_TRYLOCK | |
172 | #define XBF_DONT_BLOCK 0 | |
a2ceac1f | 173 | #define XBF_UNMAPPED 0 |
2bd0ea18 | 174 | #define XFS_BUF_GETERROR(bp) 0 |
f1b058f9 NS |
175 | #define XFS_BUF_DONE(bp) ((bp)->b_flags |= LIBXFS_B_UPTODATE) |
176 | #define XFS_BUF_ISDONE(bp) ((bp)->b_flags & LIBXFS_B_UPTODATE) | |
a2ceac1f | 177 | #define xfs_buf_stale(bp) ((bp)->b_flags |= LIBXFS_B_STALE) |
f1b058f9 | 178 | #define XFS_BUF_UNDELAYWRITE(bp) ((bp)->b_flags &= ~LIBXFS_B_DIRTY) |
2bd0ea18 NS |
179 | #define XFS_BUF_SET_VTYPE(a,b) ((void) 0) |
180 | #define XFS_BUF_SET_VTYPE_REF(a,b,c) ((void) 0) | |
181 | #define XFS_BUF_SET_BDSTRAT_FUNC(a,b) ((void) 0) | |
5e656dbb | 182 | |
57c9fccb | 183 | #define xfs_incore(bt,blkno,len,lockit) 0 |
2bd0ea18 | 184 | #define xfs_buf_relse(bp) libxfs_putbuf(bp) |
6d1d29a7 | 185 | #define xfs_read_buf(mp,devp,blkno,len,f,bpp) \ |
5e656dbb BN |
186 | (*(bpp) = libxfs_readbuf((devp), \ |
187 | (blkno), (len), 1), 0) | |
56b2de80 | 188 | #define xfs_buf_get(devp,blkno,len,f) \ |
5e656dbb | 189 | (libxfs_getbuf((devp), (blkno), (len))) |
57c9fccb NS |
190 | #define xfs_bwrite(mp,bp) libxfs_writebuf((bp), 0) |
191 | ||
56b2de80 DC |
192 | #define XBRW_READ LIBXFS_BREAD |
193 | #define XBRW_WRITE LIBXFS_BWRITE | |
194 | #define xfs_buf_iomove(bp,off,len,data,f) libxfs_iomove(bp,off,len,data,f) | |
195 | #define xfs_buf_zero(bp,off,len) libxfs_iomove(bp,off,len,0,LIBXFS_BZERO) | |
2bd0ea18 | 196 | |
5e656dbb BN |
197 | /* mount stuff */ |
198 | #define XFS_MOUNT_32BITINODES LIBXFS_MOUNT_32BITINODES | |
199 | #define XFS_MOUNT_ATTR2 LIBXFS_MOUNT_ATTR2 | |
200 | #define XFS_MOUNT_SMALL_INUMS 0 /* ignored in userspace */ | |
201 | #define XFS_MOUNT_WSYNC 0 /* ignored in userspace */ | |
202 | #define XFS_MOUNT_NOALIGN 0 /* ignored in userspace */ | |
203 | ||
56b2de80 DC |
204 | #define xfs_icsb_modify_counters(mp, field, delta, rsvd) \ |
205 | xfs_mod_incore_sb(mp, field, delta, rsvd) | |
206 | ||
5e656dbb BN |
207 | /* |
208 | * Map XFS kernel routine names to libxfs versions | |
209 | */ | |
210 | ||
211 | #define xfs_alloc_fix_freelist libxfs_alloc_fix_freelist | |
212 | #define xfs_attr_get libxfs_attr_get | |
213 | #define xfs_attr_set libxfs_attr_set | |
214 | #define xfs_attr_remove libxfs_attr_remove | |
215 | #define xfs_rtfree_extent libxfs_rtfree_extent | |
216 | ||
217 | #define xfs_fs_repair_cmn_err libxfs_fs_repair_cmn_err | |
218 | #define xfs_fs_cmn_err libxfs_fs_cmn_err | |
219 | ||
220 | #define xfs_bmap_finish libxfs_bmap_finish | |
56b2de80 | 221 | #define xfs_trans_ichgtime libxfs_trans_ichgtime |
5e656dbb BN |
222 | #define xfs_mod_incore_sb libxfs_mod_incore_sb |
223 | ||
224 | #define xfs_trans_alloc libxfs_trans_alloc | |
225 | #define xfs_trans_bhold libxfs_trans_bhold | |
226 | #define xfs_trans_binval libxfs_trans_binval | |
227 | #define xfs_trans_bjoin libxfs_trans_bjoin | |
228 | #define xfs_trans_brelse libxfs_trans_brelse | |
229 | #define xfs_trans_commit libxfs_trans_commit | |
230 | #define xfs_trans_cancel libxfs_trans_cancel | |
231 | #define xfs_trans_dup libxfs_trans_dup | |
232 | #define xfs_trans_get_buf libxfs_trans_get_buf | |
233 | #define xfs_trans_getsb libxfs_trans_getsb | |
234 | #define xfs_trans_iget libxfs_trans_iget | |
235 | #define xfs_trans_ihold libxfs_trans_ihold | |
236 | #define xfs_trans_ijoin libxfs_trans_ijoin | |
56b2de80 | 237 | #define xfs_trans_ijoin_ref libxfs_trans_ijoin_ref |
5e656dbb BN |
238 | #define xfs_trans_inode_alloc_buf libxfs_trans_inode_alloc_buf |
239 | #define xfs_trans_log_buf libxfs_trans_log_buf | |
240 | #define xfs_trans_log_inode libxfs_trans_log_inode | |
241 | #define xfs_trans_mod_sb libxfs_trans_mod_sb | |
242 | #define xfs_trans_read_buf libxfs_trans_read_buf | |
a2ceac1f DC |
243 | #define xfs_trans_read_buf_map libxfs_trans_read_buf_map |
244 | #define xfs_trans_get_buf_map libxfs_trans_get_buf_map | |
5e656dbb BN |
245 | #define xfs_trans_reserve libxfs_trans_reserve |
246 | ||
247 | #define xfs_trans_get_block_res(tp) 1 | |
248 | #define xfs_trans_set_sync(tp) ((void) 0) | |
249 | #define xfs_trans_agblocks_delta(tp, d) | |
250 | #define xfs_trans_agflist_delta(tp, d) | |
251 | #define xfs_trans_agbtree_delta(tp, d) | |
5dfa5cd2 | 252 | #define xfs_trans_buf_set_type(tp, bp, t) |
5e656dbb | 253 | |
a2ceac1f DC |
254 | #define xfs_buf_readahead(a,b,c,ops) ((void) 0) /* no readahead */ |
255 | #define xfs_buf_readahead_map(a,b,c,ops) ((void) 0) /* no readahead */ | |
256 | #define xfs_btree_reada_bufl(m,fsb,c,ops) ((void) 0) | |
257 | #define xfs_btree_reada_bufs(m,fsb,c,x,ops) ((void) 0) | |
258 | #define xfs_buftrace(x,y) ((void) 0) /* debug only */ | |
5e656dbb BN |
259 | |
260 | #define xfs_cmn_err(tag,level,mp,fmt,args...) cmn_err(level,fmt, ## args) | |
a2ceac1f DC |
261 | #define xfs_warn(mp,fmt,args...) cmn_err(CE_WARN,fmt, ## args) |
262 | #define xfs_alert(mp,fmt,args...) cmn_err(CE_ALERT,fmt, ## args) | |
263 | #define xfs_alert_tag(mp,tag,fmt,args...) cmn_err(CE_ALERT,fmt, ## args) | |
5e656dbb | 264 | |
2bd0ea18 NS |
265 | #define xfs_dir2_trace_args(where, args) ((void) 0) |
266 | #define xfs_dir2_trace_args_b(where, args, bp) ((void) 0) | |
267 | #define xfs_dir2_trace_args_bb(where, args, lbp, dbp) ((void) 0) | |
268 | #define xfs_dir2_trace_args_bibii(where, args, bs, ss, bd, sd, c) ((void) 0) | |
269 | #define xfs_dir2_trace_args_db(where, args, db, bp) ((void) 0) | |
270 | #define xfs_dir2_trace_args_i(where, args, i) ((void) 0) | |
271 | #define xfs_dir2_trace_args_s(where, args, s) ((void) 0) | |
272 | #define xfs_dir2_trace_args_sb(where, args, s, bp) ((void) 0) | |
5e656dbb | 273 | #define xfs_sort qsort |
2bd0ea18 | 274 | |
5e656dbb BN |
275 | #define xfs_icsb_reinit_counters(mp) do { } while (0) |
276 | #define xfs_initialize_perag_icache(pag) ((void) 0) | |
27c21191 | 277 | |
5e656dbb | 278 | #define xfs_ilock(ip,mode) ((void) 0) |
a2ceac1f DC |
279 | #define xfs_ilock_nowait(ip,mode) ((void) 0) |
280 | #define xfs_ilock_demote(ip,mode) ((void) 0) | |
5e656dbb | 281 | #define xfs_iunlock(ip,mode) ((void) 0) |
a2ceac1f DC |
282 | #define xfs_ilock_map_shared(ip,mode) ((void) 0) |
283 | #define xfs_iunlock_map_shared(ip,mode) ((void) 0) | |
284 | #define __xfs_flock(ip) ((void) 0) | |
2bd0ea18 | 285 | |
5e656dbb | 286 | /* space allocation */ |
a2ceac1f DC |
287 | #define xfs_extent_busy_reuse(mp,ag,bno,len,user) ((void) 0) |
288 | #define xfs_extent_busy_insert(tp,ag,bno,len,flags) ((void) 0) | |
289 | #define xfs_extent_busy_trim(args,fbno,flen,bno,len) \ | |
290 | do { \ | |
291 | *(bno) = (fbno); \ | |
292 | *(len) = (flen); \ | |
293 | } while (0) | |
294 | ||
56b2de80 DC |
295 | /* avoid unused variable warning */ |
296 | #define xfs_alloc_busy_insert(tp,ag,b,len) ({ \ | |
297 | xfs_agnumber_t __foo = ag; \ | |
298 | __foo = 0; \ | |
299 | }) | |
a2ceac1f | 300 | |
5e656dbb BN |
301 | #define xfs_rotorstep 1 |
302 | #define xfs_bmap_rtalloc(a) (ENOSYS) | |
303 | #define xfs_rtpick_extent(mp,tp,len,p) (ENOSYS) | |
304 | #define xfs_get_extsz_hint(ip) (0) | |
305 | #define xfs_inode_is_filestream(ip) (0) | |
306 | #define xfs_filestream_lookup_ag(ip) (0) | |
307 | #define xfs_filestream_new_ag(ip,ag) (0) | |
2bd0ea18 | 308 | |
a2ceac1f DC |
309 | #define xfs_log_force(mp,flags) ((void) 0) |
310 | #define XFS_LOG_SYNC 1 | |
311 | ||
312 | /* quota bits */ | |
313 | #define xfs_trans_mod_dquot_byino(t,i,f,d) ((void) 0) | |
314 | #define xfs_trans_reserve_quota_nblks(t,i,b,n,f) (0) | |
315 | #define xfs_trans_unreserve_quota_nblks(t,i,b,n,f) ((void) 0) | |
316 | #define xfs_qm_dqattach(i,f) (0) | |
317 | ||
5dfa5cd2 DC |
318 | #define uuid_copy(s,d) platform_uuid_copy((s),(d)) |
319 | #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0) | |
320 | ||
2bd0ea18 | 321 | /* |
5e656dbb BN |
322 | * Prototypes for kernel static functions that are aren't in their |
323 | * associated header files | |
2bd0ea18 NS |
324 | */ |
325 | ||
5e656dbb BN |
326 | /* xfs_attr.c */ |
327 | int xfs_attr_rmtval_get(struct xfs_da_args *); | |
2bd0ea18 NS |
328 | |
329 | /* xfs_bmap.c */ | |
5e656dbb BN |
330 | void xfs_bmap_del_free(xfs_bmap_free_t *, xfs_bmap_free_item_t *, |
331 | xfs_bmap_free_item_t *); | |
2bd0ea18 | 332 | |
5e656dbb BN |
333 | /* xfs_inode.c */ |
334 | void xfs_iflush_fork(xfs_inode_t *, xfs_dinode_t *, xfs_inode_log_item_t *, | |
335 | int, xfs_buf_t *); | |
a2ceac1f DC |
336 | /* |
337 | * For regular files we only update the on-disk filesize when actually | |
338 | * writing data back to disk. Until then only the copy in the VFS inode | |
339 | * is uptodate. | |
340 | */ | |
341 | static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip) | |
342 | { | |
343 | if (S_ISREG(ip->i_d.di_mode)) | |
344 | return ip->i_size; | |
345 | return ip->i_d.di_size; | |
346 | } | |
5e656dbb BN |
347 | |
348 | /* xfs_mount.c */ | |
349 | int xfs_initialize_perag_data(xfs_mount_t *, xfs_agnumber_t); | |
350 | void xfs_mount_common(xfs_mount_t *, xfs_sb_t *); | |
351 | ||
352 | /* | |
353 | * logitem.c and trans.c prototypes | |
354 | */ | |
2bd0ea18 NS |
355 | |
356 | /* xfs_trans_item.c */ | |
c40bdaa2 DC |
357 | void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *); |
358 | void xfs_trans_del_item(struct xfs_log_item *); | |
359 | void xfs_trans_free_items(struct xfs_trans *, int); | |
2bd0ea18 | 360 | |
2bd0ea18 NS |
361 | /* xfs_inode_item.c */ |
362 | void xfs_inode_item_init (xfs_inode_t *, xfs_mount_t *); | |
363 | ||
364 | /* xfs_buf_item.c */ | |
365 | void xfs_buf_item_init (xfs_buf_t *, xfs_mount_t *); | |
366 | void xfs_buf_item_log (xfs_buf_log_item_t *, uint, uint); | |
367 | ||
5e656dbb | 368 | /* xfs_trans_buf.c */ |
a2ceac1f DC |
369 | xfs_buf_t *xfs_trans_buf_item_match(xfs_trans_t *, dev_t, |
370 | struct xfs_buf_map *, int); | |
5e656dbb | 371 | |
2bd0ea18 | 372 | /* local source files */ |
5e656dbb BN |
373 | int xfs_mod_incore_sb(xfs_mount_t *, xfs_sb_field_t, int64_t, int); |
374 | void xfs_trans_mod_sb(xfs_trans_t *, uint, long); |