forked from dlorch/hammer-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfly_wrap.h
345 lines (274 loc) · 10.5 KB
/
dfly_wrap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#ifndef _DFLY_WRAP_H
#define _DFLY_WRAP_H
/*
* Header file providing compability "glue" between
* DragonFly BSD and Linux: Contains mostly dummy
* definitions and no-op functions.
*
* Use as follows: First include linux headers, then
* dfly_wrap.h, then dfly headers.
*/
#include <linux/types.h> // for u_ont32_t, uint64_t
#include <asm/bug.h> // for BUG_ON
#include <linux/time.h> // for struct timespec
#include <linux/bio.h> // for struct bio
#include <linux/kernel.h> // for printk, simple_strtoul
#include <linux/ctype.h> // for isascii, isdigit, isalpha, isupper, isspace
#include <linux/slab.h> // for kmalloc
#include <linux/string.h> // for memcmp, memcpy, memset
#include <linux/buffer_head.h> // for brelse
/*
* required DragonFly BSD definitions
*/
// indicate we are in kernel
#define _KERNEL 1
// from sys/cdefs.h
#define __unused
// from sys/dirent.h
#define DT_DBF 15 /* database record file*/
// from sys/stat.h
#define S_IFDB 0110000 /* record access file */
#define UF_NOHISTORY 0x00000040 /* do not retain history/snapshots */
#define SF_NOHISTORY 0x00400000 /* do not retain history/snapshots */
// from cpu/i386/include/param.h
#define SMP_MAXCPU 16
// from sys/malloc.h
struct malloc_type {
struct malloc_type *ks_next; /* next in list */
long ks_memuse[SMP_MAXCPU]; /* total memory held in bytes */
long ks_loosememuse; /* (inaccurate) aggregate memuse */
long ks_limit; /* most that are allowed to exist */
long ks_size; /* sizes of this thing that are allocated */
long ks_inuse[SMP_MAXCPU]; /* # of allocs currently in use */
int64_t ks_calls; /* total packets of this type ever allocated */
long ks_maxused; /* maximum number ever used */
uint32_t ks_magic; /* if it's not magic, don't touch it */
const char *ks_shortdesc; /* short description */
uint16_t ks_limblocks; /* number of times blocked for hitting limit */
uint16_t ks_mapblocks; /* number of times blocked for kernel map */
long ks_reserved[4]; /* future use (module compatibility) */
};
#define M_MAGIC 877983977 /* time when first defined :-) */
#define MALLOC_DECLARE(type) \
extern struct malloc_type type[1]
#define MALLOC_DEFINE(type, shortdesc, longdesc) \
struct malloc_type type[1] = { \
{ NULL, { 0 }, 0, 0, 0, { 0 }, 0, 0, M_MAGIC, shortdesc, 0, 0 } \
};
#define M_WAITOK 0x0002 /* wait for resources / alloc from cache */
#define M_ZERO 0x0100 /* bzero() the allocation */
#define M_USE_RESERVE 0x0200 /* can eat into free list reserve */
#define kfree(addr, type) dfly_kfree(addr, type)
#define kmalloc(size, type, flags) dfly_kmalloc(size, type, flags)
MALLOC_DECLARE(M_TEMP);
void dfly_kfree (void *addr, struct malloc_type *type);
void *dfly_kmalloc (unsigned long size, struct malloc_type *type, int flags);
// from sys/ktr.h
#define KTR_INFO_MASTER_EXTERN(master)
// from sys/proc.h
#define PRISON_ROOT 0x1
struct lwp {};
// from sys/thread.h
#define crit_enter()
#define crit_exit()
struct thread {
struct lwp *td_lwp; /* (optional) associated lwp */
};
typedef struct thread *thread_t;
extern int lwkt_create (void (*func)(void *), void *, struct thread **,
struct thread *, int, int, const char *, ...);
extern void lwkt_exit (void);
// from platform/pc32/include/thread.h
#define curthread ((thread_t)NULL)
// from sys/types.h
typedef u_int32_t udev_t; /* device number */
typedef uint64_t u_quad_t; /* quads */
// from sys/param.h
#define MAXBSIZE 65536 /* must be power of 2 */
#define PCATCH 0x00000100 /* tsleep checks signals */
// from sys/time.h
extern time_t time_second;
struct krate {
int freq;
int ticks;
int count;
};
void getmicrotime (struct timeval *tv);
// from sys/statvfs.h
struct statvfs {
long f_blocks; /* total data blocks in file system */
};
// from sys/buf.h
struct buf {
caddr_t b_data; /* Memory, superblocks, indirect etc. */
};
struct vnode;
int bread (struct super_block*, off_t, int, struct buf **);
#ifndef _LINUX_BUFFER_HEAD_H
void brelse (struct buf *);
#endif
void dfly_brelse (struct buf *);
struct buf_rb_tree {
void *rbh_root;
};
int bd_heatup (void);
// from sys/mount.h
#define MNT_RDONLY 0x00000001 /* read only Filesystem */
#define MNT_WAIT 1 /* synchronously wait for I/O to complete */
#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
struct statfs {
long f_blocks; /* total data blocks in file system */
};
struct netexport {};
struct export_args {};
struct mount {
int mnt_flag; /* flags shared with user */
struct statfs mnt_stat; /* cache of Filesystem stats */
struct statvfs mnt_vstat; /* extended stats */
};
int vfs_mountedon (struct vnode *); /* is a vfs mounted on vp */
// from sys/uio.h
enum uio_seg {
UIO_USERSPACE, /* from user data space */
UIO_SYSSPACE, /* from system space */
UIO_NOCOPY /* don't copy, already in object */
};
// from sys/vfscache.h
struct vattr {};
enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD, VDATABASE };
// from sys/vfsops.h
#define VOP_OPEN(vp, mode, cred, fp) \
vop_open(*(vp)->v_ops, vp, mode, cred, fp)
#define VOP_CLOSE(vp, fflag) \
vop_close(*(vp)->v_ops, vp, fflag)
#define VOP_FSYNC(vp, waitfor) \
vop_fsync(*(vp)->v_ops, vp, waitfor)
struct vop_inactive_args {};
struct vop_reclaim_args {};
struct vop_ops {};
struct ucred;
int vop_open(struct vop_ops *ops, struct vnode *vp, int mode,
struct ucred *cred, struct file *file);
int vop_close(struct vop_ops *ops, struct vnode *vp, int fflag);
int vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor);
// sys/conf.h
#define si_mountpoint __si_u.__si_disk.__sid_mountpoint
struct cdev {
union {
struct {
struct mount *__sid_mountpoint;
} __si_disk;
} __si_u;
};
int count_udev (int x, int y);
// from sys/vnode.h
#define VMSC_GETVP 0x01
#define VMSC_NOWAIT 0x10
#define VMSC_ONEPASS 0x20
#define V_SAVE 0x0001 /* vinvalbuf: sync file first */
#define v_umajor v_un.vu_cdev.vu_umajor
#define v_uminor v_un.vu_cdev.vu_uminor
#define v_rdev v_un.vu_cdev.vu_cdevinfo
#define VINACTIVE 0x04000 /* The vnode is inactive (did VOP_INACTIVE) */
struct vnode {
int v_flag; /* vnode flags (see below) */
void *v_data; /* private data for fs */
struct buf_rb_tree v_rbdirty_tree; /* RB tree of dirty bufs */
enum vtype v_type; /* vnode type */
struct vop_ops **v_ops; /* vnode operations vector */
union {
struct {
int vu_umajor; /* device number for attach */
int vu_uminor;
struct cdev *vu_cdevinfo; /* device (VCHR, VBLK) */
} vu_cdev;
} v_un;
struct super_block *sb; // defined by us, we use this for sb_bread()
};
int vinvalbuf (struct vnode *vp, int save, int slpflag, int slptimeo);
int vn_isdisk (struct vnode *vp, int *errp);
int vn_lock (struct vnode *vp, int flags);
void vn_unlock (struct vnode *vp);
void vrele (struct vnode *vp);
int vmntvnodescan(struct mount *mp, int flags,
int (*fastfunc)(struct mount *mp, struct vnode *vp, void *data),
int (*slowfunc)(struct mount *mp, struct vnode *vp, void *data),
void *data);
// from sys/ucred.h
struct ucred {};
#define FSCRED ((struct ucred *)-1) /* Filesystem credential */
// from sys/namecache.h
struct nchandle {};
int cache_vref(struct nchandle *, struct ucred *, struct vnode **);
// from sys/nlookup.h
#define NLC_FOLLOW 0x00000001 /* follow leaf symlink */
struct nlookupdata {
struct nchandle nl_nch; /* start-point and result */
struct ucred *nl_cred; /* credentials for nlookup */
};
int nlookup_init(struct nlookupdata *, const char *, enum uio_seg, int);
int nlookup(struct nlookupdata *);
void nlookup_done(struct nlookupdata *);
// from cpu/*/*/stdarg.h
typedef __builtin_va_list __va_list; /* internally known to gcc */
#define __va_start(ap, last) \
__builtin_va_start(ap, last)
#define __va_end(ap) \
__builtin_va_end(ap)
// from sys/systm.h
#define KKASSERT(exp) BUG_ON(!(exp))
#define KASSERT(exp,msg) BUG_ON(!(exp))
#define kprintf printk
#define ksnprintf snprintf
#define strtoul simple_strtoul
#define bcopy memcpy
#define bzero(buf, len) memset(buf, 0, len)
void Debugger (const char *msg);
uint32_t crc32(const void *buf, size_t size);
uint32_t crc32_ext(const void *buf, size_t size, uint32_t ocrc);
int tsleep (void *, int, const char *, int);
void wakeup (void *chan);
int copyin (const void *udaddr, void *kaddr, size_t len);
int copyout (const void *kaddr, void *udaddr, size_t len);
u_quad_t strtouq (const char *, char **, int);
int kvprintf (const char *, __va_list);
// from kern/vfs_subr.c
#define KERN_MAXVNODES 5 /* int: max vnodes */
// from sys/sysctl.h
extern int desiredvnodes;
// from sys/errno.h
#define EFTYPE 79 /* Inappropriate file type or format */
// from sys/fcntl.h
#define FREAD 0x0001
#define FWRITE 0x0002
// from sys/lock.h
#define LK_EXCLUSIVE 0x00000002 /* exclusive lock */
#define LK_RETRY 0x00020000 /* vn_lock: retry until locked */
// from sys/libkern.h
#define bcmp(cs, ct, count) memcmp(cs, ct, count)
// from cpu/i386/include/param.h
#define MAXPHYS (128 * 1024) /* max raw I/O transfer size */
// from sys/signal2.h
#define CURSIG(lp) __cursig(lp, 1, 0)
int __cursig(struct lwp *, int, int);
// from sys/buf.h
extern int hidirtybufspace;
// from sys/kernel.h
extern int hz; /* system clock's frequency */
// from sys/iosched.h
void bwillwrite(int bytes);
// from sys/priv.h
#define PRIV_ROOT 1 /* Catch-all during development. */
int priv_check_cred(struct ucred *cred, int priv, int flags);
// from cpu/i386/include/limits.h
#define UQUAD_MAX ULLONG_MAX /* max value for a uquad_t */
/*
* conflicting Linux definitions
*/
// in linux/module.h
#undef LIST_HEAD
// in linux/rbtree.h
#undef RB_BLACK
#undef RB_RED
#undef RB_ROOT
#endif /* _DFLY_WRAP_H */