This repository has been archived by the owner on Nov 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdfly_wrap.c
225 lines (181 loc) · 4.46 KB
/
dfly_wrap.c
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
#include "dfly_wrap.h"
#include <linux/errno.h>
// from sys/sysctl.h
int desiredvnodes = KERN_MAXVNODES; // Maximum number of vnodes
// from kern/vfs_nlookup.c
int nlookup_init(struct nlookupdata *nd, const char *path, enum uio_seg seg, int flags) {
return 0;
}
int nlookup(struct nlookupdata *nd) {
return 0;
}
void nlookup_done(struct nlookupdata *nd) {
// no-op
}
// from kern/vfs_subr.c
int count_udev (int x, int y) {
return 0;
}
int vfs_mountedon(struct vnode *vp) {
return 0;
}
int vinvalbuf(struct vnode *vp, int flags, int slpflag, int slptimeo) {
return 0;
}
int vn_isdisk(struct vnode *vp, int *errp) {
return 1;
}
int vn_lock(struct vnode *vp, int flags) {
return 0;
}
void vn_unlock(struct vnode *vp) {
panic("vn_unlock");
}
// from kern/vopops.c
int vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
struct file *fp) {
panic("vop_open");
return 0;
}
int vop_close(struct vop_ops *ops, struct vnode *vp, int fflag) {
panic("vop_close");
return 0;
}
int vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor) {
panic("vop_fsync");
return 0;
}
// from kern/vfs_lock.c
void vrele(struct vnode *vp) {
panic("vrele");
}
// from kern/vfs_cache.c
int cache_vref(struct nchandle *nch, struct ucred *cred, struct vnode **vpp) {
return 0;
}
// from platform/*/*/db_interface.c
void Debugger (const char *msg) {
panic("Debugger");
}
// from platform/*/platform/copyio.c
int copyout(const void *kaddr, void *udaddr, size_t len) {
panic("copyout");
return 0;
}
int copyin(const void *udaddr, void *kaddr, size_t len) {
panic("copyin");
return 0;
}
// from kern/vfs_bio.c
int hidirtybufspace;
int bread(struct super_block *sb, off_t loffset, int size, struct buf **bpp) {
struct buffer_head *bh;
unsigned i, num;
sector_t block;
int error;
BUG_ON(size % BLOCK_SIZE); // size must be multiple of BLOCK_SIZE
BUG_ON(loffset % BLOCK_SIZE); // loffset must be multiple of BLOCK_SIZE
*bpp = kzalloc(sizeof(**bpp), GFP_KERNEL);
if(!(*bpp)) {
error = -ENOMEM;
goto failed;
}
(*bpp)->b_data = kzalloc(size, GFP_KERNEL);
if(!(*bpp)->b_data) {
error = -ENOMEM;
goto failed;
}
num = size / BLOCK_SIZE;
block = loffset / BLOCK_SIZE;
for(i=0; i<num; ++i) {
bh = sb_bread(sb, block + i);
if(!bh) {
error = -ENOMEM;
goto failed;
}
memcpy(((*bpp)->b_data + i*BLOCK_SIZE), bh->b_data, BLOCK_SIZE);
brelse(bh);
}
return 0;
failed:
return(error);
}
#ifndef _LINUX_BUFFER_HEAD_H
void brelse(struct buf *bp) {
panic("brelse");
}
#endif
int bd_heatup (void) {
panic("bd_heatup");
return 0;
}
// from kern/vfs_mount.c
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
) {
panic("vmntvnodescan");
return 0;
}
// from kern/kern_slaballoc.c
#undef kfree
void dfly_kfree(void *ptr, struct malloc_type *type) {
kfree(ptr);
}
void dfly_brelse(struct buf *bp) {
kfree(bp->b_data);
kfree(bp);
}
#undef kmalloc
void *dfly_kmalloc(unsigned long size, struct malloc_type *type, int flags) {
return kzalloc(size, GFP_KERNEL);
}
MALLOC_DEFINE(M_TEMP, "temp", "misc temporary data buffers");
// from kern/kern_synch.c
int tsleep(void *ident, int flags, const char *wmesg, int timo) {
panic("tsleep");
return 0;
}
void wakeup(void *ident) {
panic("wakeup");
}
// from kern/clock.c
time_t time_second; /* read-only 'passive' uptime in seconds */
void getmicrotime(struct timeval *tvp) {
do_gettimeofday(tvp);
}
// from sys/signal2.h
int __cursig(struct lwp *lp, int mayblock, int maytrace) {
panic("__cursig");
return 0;
}
// from kern/lwkt_thread.c
int lwkt_create(void (*func)(void *), void *arg,
struct thread **tdp, thread_t template, int tdflags, int cpu,
const char *fmt, ...)
{
panic("lwkt_create");
return 0;
}
void lwkt_exit(void) {
panic("lwkt_exit");
}
// from kern/subr_param.c
int hz;
// from kern/kern_iosched.c
void bwillwrite(int bytes) {
panic("bwillwrite");
}
// from kern/kern_prot.c
int priv_check_cred(struct ucred *cred, int priv, int flags) {
panic("priv_check_cred");
return 0;
}
// from kern/subr_prf.c
int kvprintf(const char *fmt, __va_list ap) {
panic("kvprintf");
return 0;
}