2 |
#include "perl.h" |
#include "perl.h" |
3 |
#include "XSUB.h" |
#include "XSUB.h" |
4 |
|
|
5 |
#include <fuse/fuse.h> |
#ifdef USE_ITHREADS |
6 |
|
# ifdef I_PTHREAD |
7 |
|
/* perl implements threads with pthread. So, we use the pthread API for |
8 |
|
* handling thread-local storage. */ |
9 |
|
# include <pthread.h> |
10 |
|
PerlInterpreter *master_interp = NULL; |
11 |
|
static inline void create_perl_context() { |
12 |
|
if(master_interp) { |
13 |
|
PerlInterpreter *me = PERL_GET_CONTEXT; |
14 |
|
if(!me) { |
15 |
|
PERL_SET_CONTEXT(master_interp); |
16 |
|
me = perl_clone(master_interp, CLONEf_CLONE_HOST); |
17 |
|
} |
18 |
|
} |
19 |
|
} |
20 |
|
# define FUSE_CONTEXT_PRE create_perl_context(); { dSP |
21 |
|
# define FUSE_CONTEXT_POST } |
22 |
|
# define FUSE_USE_ITHREADS |
23 |
|
# else |
24 |
|
# error "Sorry, I don't know how to handle ithreads on this architecture." |
25 |
|
# endif |
26 |
|
#else |
27 |
|
# define FUSE_CONTEXT_PRE dSP |
28 |
|
# define FUSE_CONTEXT_POST |
29 |
|
#endif |
30 |
|
#include <fuse.h> |
31 |
|
|
32 |
#undef DEBUGf |
#undef DEBUGf |
33 |
#if 0 |
#if 0 |
34 |
#define DEBUGf(f, a...) fprintf(stderr, "%s:%d (%i): " f,__BASE_FILE__,__LINE__,PL_stack_sp-PL_stack_base ,##a ) |
#define DEBUGf(f, a...) fprintf(stderr, "%s:%d (%i): " f,__BASE_FILE__,__LINE__,sp-PL_stack_base ,##a ) |
35 |
#else |
#else |
36 |
#define DEBUGf(a...) |
#define DEBUGf(a...) |
37 |
#endif |
#endif |
40 |
SV *_PLfuse_callbacks[N_CALLBACKS]; |
SV *_PLfuse_callbacks[N_CALLBACKS]; |
41 |
|
|
42 |
int _PLfuse_getattr(const char *file, struct stat *result) { |
int _PLfuse_getattr(const char *file, struct stat *result) { |
43 |
dSP; |
int rv; |
44 |
int rv, statcount; |
FUSE_CONTEXT_PRE; |
45 |
|
DEBUGf("getattr begin: %s\n",file); |
46 |
ENTER; |
ENTER; |
47 |
SAVETMPS; |
SAVETMPS; |
48 |
PUSHMARK(SP); |
PUSHMARK(SP); |
70 |
result->st_uid = POPi; |
result->st_uid = POPi; |
71 |
result->st_nlink = POPi; |
result->st_nlink = POPi; |
72 |
result->st_mode = POPi; |
result->st_mode = POPi; |
73 |
/*result->st_ino =*/ POPi; |
result->st_ino = POPi; |
74 |
result->st_dev = POPi; |
result->st_dev = POPi; |
75 |
rv = 0; |
rv = 0; |
76 |
} |
} |
77 |
FREETMPS; |
FREETMPS; |
78 |
LEAVE; |
LEAVE; |
79 |
PUTBACK; |
PUTBACK; |
80 |
|
DEBUGf("getattr end: %i\n",rv); |
81 |
|
FUSE_CONTEXT_POST; |
82 |
return rv; |
return rv; |
83 |
} |
} |
84 |
|
|
85 |
int _PLfuse_readlink(const char *file,char *buf,size_t buflen) { |
int _PLfuse_readlink(const char *file,char *buf,size_t buflen) { |
86 |
int rv; |
int rv; |
87 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
|
dSP; |
|
|
I32 ax; |
|
88 |
if(buflen < 1) |
if(buflen < 1) |
89 |
return EINVAL; |
return EINVAL; |
90 |
|
DEBUGf("readlink begin\n"); |
91 |
ENTER; |
ENTER; |
92 |
SAVETMPS; |
SAVETMPS; |
93 |
PUSHMARK(SP); |
PUSHMARK(SP); |
110 |
LEAVE; |
LEAVE; |
111 |
buf[buflen-1] = 0; |
buf[buflen-1] = 0; |
112 |
PUTBACK; |
PUTBACK; |
113 |
|
DEBUGf("readlink end: %i\n",rv); |
114 |
|
FUSE_CONTEXT_POST; |
115 |
return rv; |
return rv; |
116 |
} |
} |
117 |
|
|
118 |
|
#if 0 |
119 |
|
/* |
120 |
|
* This doesn't yet work... we alwas get ENOSYS when trying to use readdir(). |
121 |
|
* Well, of course, getdir() is fine as well. |
122 |
|
*/ |
123 |
|
int _PLfuse_readdir(const char *file, void *dirh, fuse_fill_dir_t dirfil, off_t off, struct fuse_file_info *fi) { |
124 |
|
#endif |
125 |
int _PLfuse_getdir(const char *file, fuse_dirh_t dirh, fuse_dirfil_t dirfil) { |
int _PLfuse_getdir(const char *file, fuse_dirh_t dirh, fuse_dirfil_t dirfil) { |
126 |
int prv, rv; |
int prv, rv; |
127 |
dSP; |
FUSE_CONTEXT_PRE; |
128 |
|
DEBUGf("getdir begin\n"); |
129 |
ENTER; |
ENTER; |
130 |
SAVETMPS; |
SAVETMPS; |
131 |
PUSHMARK(SP); |
PUSHMARK(SP); |
136 |
if(prv) { |
if(prv) { |
137 |
rv = POPi; |
rv = POPi; |
138 |
while(--prv) |
while(--prv) |
139 |
dirfil(dirh,POPp,0); |
dirfil(dirh,POPp,0,0); |
140 |
} else { |
} else { |
141 |
fprintf(stderr,"getdir() handler returned nothing!\n"); |
fprintf(stderr,"getdir() handler returned nothing!\n"); |
142 |
rv = -ENOSYS; |
rv = -ENOSYS; |
144 |
FREETMPS; |
FREETMPS; |
145 |
LEAVE; |
LEAVE; |
146 |
PUTBACK; |
PUTBACK; |
147 |
|
DEBUGf("getdir end: %i\n",rv); |
148 |
|
FUSE_CONTEXT_POST; |
149 |
return rv; |
return rv; |
150 |
} |
} |
151 |
|
|
152 |
int _PLfuse_mknod (const char *file, mode_t mode, dev_t dev) { |
int _PLfuse_mknod (const char *file, mode_t mode, dev_t dev) { |
153 |
int rv; |
int rv; |
154 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
155 |
char *rvstr; |
DEBUGf("mknod begin\n"); |
|
dSP; |
|
156 |
ENTER; |
ENTER; |
157 |
SAVETMPS; |
SAVETMPS; |
158 |
PUSHMARK(SP); |
PUSHMARK(SP); |
169 |
FREETMPS; |
FREETMPS; |
170 |
LEAVE; |
LEAVE; |
171 |
PUTBACK; |
PUTBACK; |
172 |
|
DEBUGf("mknod end: %i\n",rv); |
173 |
|
FUSE_CONTEXT_POST; |
174 |
return rv; |
return rv; |
175 |
} |
} |
176 |
|
|
177 |
int _PLfuse_mkdir (const char *file, mode_t mode) { |
int _PLfuse_mkdir (const char *file, mode_t mode) { |
178 |
int rv; |
int rv; |
179 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
180 |
char *rvstr; |
DEBUGf("mkdir begin\n"); |
|
dSP; |
|
|
DEBUGf("mkdir begin: %i\n",sp-PL_stack_base); |
|
181 |
ENTER; |
ENTER; |
182 |
SAVETMPS; |
SAVETMPS; |
183 |
PUSHMARK(SP); |
PUSHMARK(SP); |
193 |
FREETMPS; |
FREETMPS; |
194 |
LEAVE; |
LEAVE; |
195 |
PUTBACK; |
PUTBACK; |
196 |
DEBUGf("mkdir end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("mkdir end: %i\n",rv); |
197 |
|
FUSE_CONTEXT_POST; |
198 |
return rv; |
return rv; |
199 |
} |
} |
200 |
|
|
201 |
|
|
202 |
int _PLfuse_unlink (const char *file) { |
int _PLfuse_unlink (const char *file) { |
203 |
int rv; |
int rv; |
204 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
205 |
char *rvstr; |
DEBUGf("unlink begin\n"); |
|
dSP; |
|
|
DEBUGf("unlink begin: %i\n",sp-PL_stack_base); |
|
206 |
ENTER; |
ENTER; |
207 |
SAVETMPS; |
SAVETMPS; |
208 |
PUSHMARK(SP); |
PUSHMARK(SP); |
217 |
FREETMPS; |
FREETMPS; |
218 |
LEAVE; |
LEAVE; |
219 |
PUTBACK; |
PUTBACK; |
220 |
DEBUGf("unlink end: %i\n",sp-PL_stack_base); |
DEBUGf("unlink end: %i\n",rv); |
221 |
|
FUSE_CONTEXT_POST; |
222 |
return rv; |
return rv; |
223 |
} |
} |
224 |
|
|
225 |
int _PLfuse_rmdir (const char *file) { |
int _PLfuse_rmdir (const char *file) { |
226 |
int rv; |
int rv; |
227 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
228 |
char *rvstr; |
DEBUGf("rmdir begin\n"); |
|
dSP; |
|
|
DEBUGf("rmdir begin: %i\n",sp-PL_stack_base); |
|
229 |
ENTER; |
ENTER; |
230 |
SAVETMPS; |
SAVETMPS; |
231 |
PUSHMARK(SP); |
PUSHMARK(SP); |
240 |
FREETMPS; |
FREETMPS; |
241 |
LEAVE; |
LEAVE; |
242 |
PUTBACK; |
PUTBACK; |
243 |
DEBUGf("rmdir end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("rmdir end: %i\n",rv); |
244 |
|
FUSE_CONTEXT_POST; |
245 |
return rv; |
return rv; |
246 |
} |
} |
247 |
|
|
248 |
int _PLfuse_symlink (const char *file, const char *new) { |
int _PLfuse_symlink (const char *file, const char *new) { |
249 |
int rv; |
int rv; |
250 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
251 |
char *rvstr; |
DEBUGf("symlink begin\n"); |
|
dSP; |
|
|
DEBUGf("symlink begin: %i\n",sp-PL_stack_base); |
|
252 |
ENTER; |
ENTER; |
253 |
SAVETMPS; |
SAVETMPS; |
254 |
PUSHMARK(SP); |
PUSHMARK(SP); |
264 |
FREETMPS; |
FREETMPS; |
265 |
LEAVE; |
LEAVE; |
266 |
PUTBACK; |
PUTBACK; |
267 |
DEBUGf("symlink end: %i\n",sp-PL_stack_base); |
DEBUGf("symlink end: %i\n",rv); |
268 |
|
FUSE_CONTEXT_POST; |
269 |
return rv; |
return rv; |
270 |
} |
} |
271 |
|
|
272 |
int _PLfuse_rename (const char *file, const char *new) { |
int _PLfuse_rename (const char *file, const char *new) { |
273 |
int rv; |
int rv; |
274 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
275 |
char *rvstr; |
DEBUGf("rename begin\n"); |
|
dSP; |
|
|
DEBUGf("rename begin: %i\n",sp-PL_stack_base); |
|
276 |
ENTER; |
ENTER; |
277 |
SAVETMPS; |
SAVETMPS; |
278 |
PUSHMARK(SP); |
PUSHMARK(SP); |
288 |
FREETMPS; |
FREETMPS; |
289 |
LEAVE; |
LEAVE; |
290 |
PUTBACK; |
PUTBACK; |
291 |
DEBUGf("rename end: %i\n",sp-PL_stack_base); |
DEBUGf("rename end: %i\n",rv); |
292 |
|
FUSE_CONTEXT_POST; |
293 |
return rv; |
return rv; |
294 |
} |
} |
295 |
|
|
296 |
int _PLfuse_link (const char *file, const char *new) { |
int _PLfuse_link (const char *file, const char *new) { |
297 |
int rv; |
int rv; |
298 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
299 |
char *rvstr; |
DEBUGf("link begin\n"); |
|
dSP; |
|
|
DEBUGf("link begin: %i\n",sp-PL_stack_base); |
|
300 |
ENTER; |
ENTER; |
301 |
SAVETMPS; |
SAVETMPS; |
302 |
PUSHMARK(SP); |
PUSHMARK(SP); |
312 |
FREETMPS; |
FREETMPS; |
313 |
LEAVE; |
LEAVE; |
314 |
PUTBACK; |
PUTBACK; |
315 |
DEBUGf("link end: %i\n",sp-PL_stack_base); |
DEBUGf("link end: %i\n",rv); |
316 |
|
FUSE_CONTEXT_POST; |
317 |
return rv; |
return rv; |
318 |
} |
} |
319 |
|
|
320 |
int _PLfuse_chmod (const char *file, mode_t mode) { |
int _PLfuse_chmod (const char *file, mode_t mode) { |
321 |
int rv; |
int rv; |
322 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
323 |
char *rvstr; |
DEBUGf("chmod begin\n"); |
|
dSP; |
|
|
DEBUGf("chmod begin: %i\n",sp-PL_stack_base); |
|
324 |
ENTER; |
ENTER; |
325 |
SAVETMPS; |
SAVETMPS; |
326 |
PUSHMARK(SP); |
PUSHMARK(SP); |
336 |
FREETMPS; |
FREETMPS; |
337 |
LEAVE; |
LEAVE; |
338 |
PUTBACK; |
PUTBACK; |
339 |
DEBUGf("chmod end: %i\n",sp-PL_stack_base); |
DEBUGf("chmod end: %i\n",rv); |
340 |
|
FUSE_CONTEXT_POST; |
341 |
return rv; |
return rv; |
342 |
} |
} |
343 |
|
|
344 |
int _PLfuse_chown (const char *file, uid_t uid, gid_t gid) { |
int _PLfuse_chown (const char *file, uid_t uid, gid_t gid) { |
345 |
int rv; |
int rv; |
346 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
347 |
char *rvstr; |
DEBUGf("chown begin\n"); |
|
dSP; |
|
|
DEBUGf("chown begin: %i\n",sp-PL_stack_base); |
|
348 |
ENTER; |
ENTER; |
349 |
SAVETMPS; |
SAVETMPS; |
350 |
PUSHMARK(SP); |
PUSHMARK(SP); |
361 |
FREETMPS; |
FREETMPS; |
362 |
LEAVE; |
LEAVE; |
363 |
PUTBACK; |
PUTBACK; |
364 |
DEBUGf("chown end: %i\n",sp-PL_stack_base); |
DEBUGf("chown end: %i\n",rv); |
365 |
|
FUSE_CONTEXT_POST; |
366 |
return rv; |
return rv; |
367 |
} |
} |
368 |
|
|
369 |
int _PLfuse_truncate (const char *file, off_t off) { |
int _PLfuse_truncate (const char *file, off_t off) { |
370 |
int rv; |
int rv; |
371 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
372 |
char *rvstr; |
DEBUGf("truncate begin\n"); |
|
dSP; |
|
|
DEBUGf("truncate begin: %i\n",sp-PL_stack_base); |
|
373 |
ENTER; |
ENTER; |
374 |
SAVETMPS; |
SAVETMPS; |
375 |
PUSHMARK(SP); |
PUSHMARK(SP); |
385 |
FREETMPS; |
FREETMPS; |
386 |
LEAVE; |
LEAVE; |
387 |
PUTBACK; |
PUTBACK; |
388 |
DEBUGf("truncate end: %i\n",sp-PL_stack_base); |
DEBUGf("truncate end: %i\n",rv); |
389 |
|
FUSE_CONTEXT_POST; |
390 |
return rv; |
return rv; |
391 |
} |
} |
392 |
|
|
393 |
int _PLfuse_utime (const char *file, struct utimbuf *uti) { |
int _PLfuse_utime (const char *file, struct utimbuf *uti) { |
394 |
int rv; |
int rv; |
395 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
396 |
char *rvstr; |
DEBUGf("utime begin\n"); |
|
dSP; |
|
|
DEBUGf("utime begin: %i\n",sp-PL_stack_base); |
|
397 |
ENTER; |
ENTER; |
398 |
SAVETMPS; |
SAVETMPS; |
399 |
PUSHMARK(SP); |
PUSHMARK(SP); |
410 |
FREETMPS; |
FREETMPS; |
411 |
LEAVE; |
LEAVE; |
412 |
PUTBACK; |
PUTBACK; |
413 |
DEBUGf("utime end: %i\n",sp-PL_stack_base); |
DEBUGf("utime end: %i\n",rv); |
414 |
|
FUSE_CONTEXT_POST; |
415 |
return rv; |
return rv; |
416 |
} |
} |
417 |
|
|
418 |
int _PLfuse_open (const char *file, int flags) { |
int _PLfuse_open (const char *file, struct fuse_file_info *fi) { |
419 |
int rv; |
int rv; |
420 |
SV *rvsv; |
int flags = fi->flags; |
421 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
422 |
dSP; |
DEBUGf("open begin\n"); |
|
DEBUGf("open begin: %i\n",sp-PL_stack_base); |
|
423 |
ENTER; |
ENTER; |
424 |
SAVETMPS; |
SAVETMPS; |
425 |
PUSHMARK(SP); |
PUSHMARK(SP); |
435 |
FREETMPS; |
FREETMPS; |
436 |
LEAVE; |
LEAVE; |
437 |
PUTBACK; |
PUTBACK; |
438 |
DEBUGf("open end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("open end: %i\n",rv); |
439 |
|
FUSE_CONTEXT_POST; |
440 |
return rv; |
return rv; |
441 |
} |
} |
442 |
|
|
443 |
int _PLfuse_read (const char *file, char *buf, size_t buflen, off_t off) { |
int _PLfuse_read (const char *file, char *buf, size_t buflen, off_t off, struct fuse_file_info *fi) { |
444 |
int rv; |
int rv; |
445 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
446 |
dSP; |
DEBUGf("read begin\n"); |
|
DEBUGf("read begin: %i\n",sp-PL_stack_base); |
|
447 |
ENTER; |
ENTER; |
448 |
SAVETMPS; |
SAVETMPS; |
449 |
PUSHMARK(SP); |
PUSHMARK(SP); |
474 |
FREETMPS; |
FREETMPS; |
475 |
LEAVE; |
LEAVE; |
476 |
PUTBACK; |
PUTBACK; |
477 |
DEBUGf("read end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("read end: %i\n",rv); |
478 |
|
FUSE_CONTEXT_POST; |
479 |
return rv; |
return rv; |
480 |
} |
} |
481 |
|
|
482 |
int _PLfuse_write (const char *file, const char *buf, size_t buflen, off_t off) { |
int _PLfuse_write (const char *file, const char *buf, size_t buflen, off_t off, struct fuse_file_info *fi) { |
483 |
int rv; |
int rv; |
484 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
485 |
dSP; |
DEBUGf("write begin\n"); |
|
DEBUGf("write begin: %i\n",sp-PL_stack_base); |
|
486 |
ENTER; |
ENTER; |
487 |
SAVETMPS; |
SAVETMPS; |
488 |
PUSHMARK(SP); |
PUSHMARK(SP); |
499 |
FREETMPS; |
FREETMPS; |
500 |
LEAVE; |
LEAVE; |
501 |
PUTBACK; |
PUTBACK; |
502 |
DEBUGf("write end: %i\n",sp-PL_stack_base); |
DEBUGf("write end: %i\n",rv); |
503 |
|
FUSE_CONTEXT_POST; |
504 |
return rv; |
return rv; |
505 |
} |
} |
506 |
|
|
507 |
int _PLfuse_statfs (const char *file, struct statfs *st) { |
int _PLfuse_statfs (const char *file, struct statvfs *st) { |
508 |
int rv; |
int rv; |
509 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
510 |
dSP; |
DEBUGf("statfs begin\n"); |
|
DEBUGf("statfs begin: %i\n",sp-PL_stack_base); |
|
511 |
ENTER; |
ENTER; |
512 |
SAVETMPS; |
SAVETMPS; |
513 |
PUSHMARK(SP); |
PUSHMARK(SP); |
514 |
PUTBACK; |
PUTBACK; |
515 |
rv = call_sv(_PLfuse_callbacks[17],G_ARRAY); |
rv = call_sv(_PLfuse_callbacks[17],G_ARRAY); |
516 |
SPAGAIN; |
SPAGAIN; |
517 |
if(rv > 5) { |
DEBUGf("statfs got %i params\n",rv); |
518 |
st->f_bsize = POPi; |
if(rv == 6 || rv == 7) { |
519 |
st->f_bfree = POPi; |
st->f_bsize = POPi; |
520 |
st->f_blocks = POPi; |
st->f_bfree = POPi; |
521 |
st->f_ffree = POPi; |
st->f_blocks = POPi; |
522 |
st->f_files = POPi; |
st->f_ffree = POPi; |
523 |
st->f_namelen = POPi; |
st->f_files = POPi; |
524 |
if(rv > 6) |
st->f_namemax = POPi; |
525 |
|
/* zero and fill-in other */ |
526 |
|
st->f_fsid = 0; |
527 |
|
st->f_frsize = 4096; |
528 |
|
st->f_flag = 0; |
529 |
|
st->f_bavail = st->f_bfree; |
530 |
|
st->f_favail = st->f_ffree; |
531 |
|
|
532 |
|
if(rv == 7) |
533 |
rv = POPi; |
rv = POPi; |
534 |
else |
else |
535 |
rv = 0; |
rv = 0; |
544 |
FREETMPS; |
FREETMPS; |
545 |
LEAVE; |
LEAVE; |
546 |
PUTBACK; |
PUTBACK; |
547 |
DEBUGf("statfs end: %i\n",sp-PL_stack_base); |
DEBUGf("statfs end: %i\n",rv); |
548 |
|
FUSE_CONTEXT_POST; |
549 |
return rv; |
return rv; |
550 |
} |
} |
551 |
|
|
552 |
int _PLfuse_flush (const char *file) { |
int _PLfuse_flush (const char *file, struct fuse_file_info *fi) { |
553 |
int rv; |
int rv; |
554 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
555 |
dSP; |
DEBUGf("flush begin\n"); |
|
DEBUGf("flush begin: %i\n",sp-PL_stack_base); |
|
556 |
ENTER; |
ENTER; |
557 |
SAVETMPS; |
SAVETMPS; |
558 |
PUSHMARK(SP); |
PUSHMARK(SP); |
567 |
FREETMPS; |
FREETMPS; |
568 |
LEAVE; |
LEAVE; |
569 |
PUTBACK; |
PUTBACK; |
570 |
DEBUGf("flush end: %i\n",sp-PL_stack_base); |
DEBUGf("flush end: %i\n",rv); |
571 |
|
FUSE_CONTEXT_POST; |
572 |
return rv; |
return rv; |
573 |
} |
} |
574 |
|
|
575 |
int _PLfuse_release (const char *file, int flags) { |
int _PLfuse_release (const char *file, struct fuse_file_info *fi) { |
576 |
int rv; |
int rv; |
577 |
char *rvstr; |
int flags = fi->flags; |
578 |
dSP; |
FUSE_CONTEXT_PRE; |
579 |
DEBUGf("release begin: %i\n",sp-PL_stack_base); |
DEBUGf("release begin\n"); |
580 |
ENTER; |
ENTER; |
581 |
SAVETMPS; |
SAVETMPS; |
582 |
PUSHMARK(SP); |
PUSHMARK(SP); |
592 |
FREETMPS; |
FREETMPS; |
593 |
LEAVE; |
LEAVE; |
594 |
PUTBACK; |
PUTBACK; |
595 |
DEBUGf("release end: %i\n",sp-PL_stack_base); |
DEBUGf("release end: %i\n",rv); |
596 |
|
FUSE_CONTEXT_POST; |
597 |
return rv; |
return rv; |
598 |
} |
} |
599 |
|
|
600 |
int _PLfuse_fsync (const char *file, int flags) { |
int _PLfuse_fsync (const char *file, int datasync, struct fuse_file_info *fi) { |
601 |
int rv; |
int rv; |
602 |
char *rvstr; |
int flags = fi->flags; |
603 |
dSP; |
FUSE_CONTEXT_PRE; |
604 |
DEBUGf("fsync begin: %i\n",sp-PL_stack_base); |
DEBUGf("fsync begin\n"); |
605 |
ENTER; |
ENTER; |
606 |
SAVETMPS; |
SAVETMPS; |
607 |
PUSHMARK(SP); |
PUSHMARK(SP); |
617 |
FREETMPS; |
FREETMPS; |
618 |
LEAVE; |
LEAVE; |
619 |
PUTBACK; |
PUTBACK; |
620 |
DEBUGf("fsync end: %i\n",sp-PL_stack_base); |
DEBUGf("fsync end: %i\n",rv); |
621 |
|
FUSE_CONTEXT_POST; |
622 |
return rv; |
return rv; |
623 |
} |
} |
624 |
|
|
625 |
int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) { |
int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) { |
626 |
int rv; |
int rv; |
627 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
628 |
dSP; |
DEBUGf("setxattr begin\n"); |
|
DEBUGf("setxattr begin: %i\n",sp-PL_stack_base); |
|
629 |
ENTER; |
ENTER; |
630 |
SAVETMPS; |
SAVETMPS; |
631 |
PUSHMARK(SP); |
PUSHMARK(SP); |
643 |
FREETMPS; |
FREETMPS; |
644 |
LEAVE; |
LEAVE; |
645 |
PUTBACK; |
PUTBACK; |
646 |
DEBUGf("setxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("setxattr end: %i\n",rv); |
647 |
|
FUSE_CONTEXT_POST; |
648 |
return rv; |
return rv; |
649 |
} |
} |
650 |
|
|
651 |
int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) { |
int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) { |
652 |
int rv; |
int rv; |
653 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
654 |
dSP; |
DEBUGf("getxattr begin\n"); |
|
DEBUGf("getxattr begin: %i\n",sp-PL_stack_base); |
|
655 |
ENTER; |
ENTER; |
656 |
SAVETMPS; |
SAVETMPS; |
657 |
PUSHMARK(SP); |
PUSHMARK(SP); |
686 |
FREETMPS; |
FREETMPS; |
687 |
LEAVE; |
LEAVE; |
688 |
PUTBACK; |
PUTBACK; |
689 |
DEBUGf("getxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("getxattr end: %i\n",rv); |
690 |
|
FUSE_CONTEXT_POST; |
691 |
return rv; |
return rv; |
692 |
} |
} |
693 |
|
|
694 |
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
695 |
int prv, rv; |
int prv, rv; |
696 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
697 |
dSP; |
DEBUGf("listxattr begin\n"); |
|
DEBUGf("listxattr begin: %i\n",sp-PL_stack_base); |
|
698 |
ENTER; |
ENTER; |
699 |
SAVETMPS; |
SAVETMPS; |
700 |
PUSHMARK(SP); |
PUSHMARK(SP); |
709 |
char *p = list; |
char *p = list; |
710 |
int spc = size; |
int spc = size; |
711 |
int total_len = 0; |
int total_len = 0; |
|
int i; |
|
712 |
|
|
713 |
rv = POPi; |
rv = POPi; |
714 |
prv--; |
prv--; |
750 |
FREETMPS; |
FREETMPS; |
751 |
LEAVE; |
LEAVE; |
752 |
PUTBACK; |
PUTBACK; |
753 |
DEBUGf("listxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("listxattr end: %i\n",rv); |
754 |
|
FUSE_CONTEXT_POST; |
755 |
return rv; |
return rv; |
756 |
} |
} |
757 |
|
|
758 |
int _PLfuse_removexattr (const char *file, const char *name) { |
int _PLfuse_removexattr (const char *file, const char *name) { |
759 |
int rv; |
int rv; |
760 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
761 |
dSP; |
DEBUGf("removexattr begin\n"); |
|
DEBUGf("removexattr begin: %i\n",sp-PL_stack_base); |
|
762 |
ENTER; |
ENTER; |
763 |
SAVETMPS; |
SAVETMPS; |
764 |
PUSHMARK(SP); |
PUSHMARK(SP); |
774 |
FREETMPS; |
FREETMPS; |
775 |
LEAVE; |
LEAVE; |
776 |
PUTBACK; |
PUTBACK; |
777 |
DEBUGf("removexattr end: %i\n",sp-PL_stack_base); |
DEBUGf("removexattr end: %i\n",rv); |
778 |
|
FUSE_CONTEXT_POST; |
779 |
return rv; |
return rv; |
780 |
} |
} |
781 |
|
|
783 |
getattr: _PLfuse_getattr, |
getattr: _PLfuse_getattr, |
784 |
readlink: _PLfuse_readlink, |
readlink: _PLfuse_readlink, |
785 |
getdir: _PLfuse_getdir, |
getdir: _PLfuse_getdir, |
786 |
|
#if 0 |
787 |
|
readdir: _PLfuse_readdir, |
788 |
|
#endif |
789 |
mknod: _PLfuse_mknod, |
mknod: _PLfuse_mknod, |
790 |
mkdir: _PLfuse_mkdir, |
mkdir: _PLfuse_mkdir, |
791 |
unlink: _PLfuse_unlink, |
unlink: _PLfuse_unlink, |
816 |
void |
void |
817 |
perl_fuse_main(...) |
perl_fuse_main(...) |
818 |
PREINIT: |
PREINIT: |
819 |
struct fuse_operations fops = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
struct fuse_operations fops = |
820 |
int i, fd, varnum = 0, debug, have_mnt; |
{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, |
821 |
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
822 |
|
int i, fd, debug, threaded; |
823 |
char *mountpoint; |
char *mountpoint; |
824 |
char *mountopts; |
char *mountopts; |
825 |
STRLEN n_a; |
struct fuse_args margs = FUSE_ARGS_INIT(0, NULL); |
826 |
STRLEN l; |
struct fuse_args fargs = FUSE_ARGS_INIT(0, NULL); |
827 |
INIT: |
INIT: |
828 |
if(items != 28) { |
if(items != 29) { |
829 |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
830 |
XSRETURN_UNDEF; |
XSRETURN_UNDEF; |
831 |
} |
} |
832 |
CODE: |
CODE: |
833 |
debug = SvIV(ST(0)); |
debug = SvIV(ST(0)); |
834 |
mountpoint = SvPV_nolen(ST(1)); |
threaded = SvIV(ST(1)); |
835 |
mountopts = SvPV_nolen(ST(2)); |
if(threaded) { |
836 |
/* FIXME: reevaluate multithreading support when perl6 arrives */ |
#ifdef FUSE_USE_ITHREADS |
837 |
|
master_interp = PERL_GET_CONTEXT; |
838 |
|
#else |
839 |
|
fprintf(stderr,"FUSE warning: Your script has requested multithreaded " |
840 |
|
"mode, but your perl was not built with -Dusethreads. " |
841 |
|
"Threads are disabled.\n"); |
842 |
|
threaded = 0; |
843 |
|
#endif |
844 |
|
} |
845 |
|
mountpoint = SvPV_nolen(ST(2)); |
846 |
|
mountopts = SvPV_nolen(ST(3)); |
847 |
for(i=0;i<N_CALLBACKS;i++) { |
for(i=0;i<N_CALLBACKS;i++) { |
848 |
SV *var = ST(i+3); |
SV *var = ST(i+4); |
849 |
if((var != &PL_sv_undef) && SvROK(var)) { |
/* allow symbolic references, or real code references. */ |
850 |
if(SvTYPE(SvRV(var)) == SVt_PVCV) { |
if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) { |
851 |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
852 |
tmp2[i] = tmp1[i]; |
tmp2[i] = tmp1[i]; |
853 |
_PLfuse_callbacks[i] = var; |
#ifdef FUSE_USE_ITHREADS |
854 |
} else |
if(threaded) |
855 |
croak("arg is not a code reference!"); |
/* note: under 5.8.7, this croaks for code references. */ |
856 |
|
SvSHARE(var); |
857 |
|
#endif |
858 |
|
_PLfuse_callbacks[i] = var; |
859 |
|
} else |
860 |
|
if(SvOK(var)) { |
861 |
|
croak("invalid callback passed to perl_fuse_main " |
862 |
|
"(%s is not a string, code ref, or undef).\n", |
863 |
|
i+4,SvPVbyte_nolen(var)); |
864 |
} |
} |
865 |
} |
} |
866 |
/* FIXME: need to pass fusermount arguments */ |
/* |
867 |
fd = fuse_mount(mountpoint,mountopts); |
* XXX: What comes here is just a ridiculous use of the option parsing API |
868 |
|
* to hack on compatibility with other parts of the new API. First and |
869 |
|
* foremost, real C argc/argv would be good to get at... |
870 |
|
*/ |
871 |
|
if (mountopts && |
872 |
|
(fuse_opt_add_arg(&margs, "") == -1 || |
873 |
|
fuse_opt_add_arg(&margs, "-o") == -1 || |
874 |
|
fuse_opt_add_arg(&margs, mountopts) == -1)) { |
875 |
|
fuse_opt_free_args(&margs); |
876 |
|
croak("out of memory\n"); |
877 |
|
} |
878 |
|
fd = fuse_mount(mountpoint,&margs); |
879 |
|
fuse_opt_free_args(&margs); |
880 |
if(fd < 0) |
if(fd < 0) |
881 |
croak("could not mount fuse filesystem!"); |
croak("could not mount fuse filesystem!\n"); |
882 |
fuse_loop(fuse_new(fd,debug ? "debug" : NULL,&fops)); |
if (debug) { |
883 |
|
if ( fuse_opt_add_arg(&fargs, "") == -1 || |
884 |
|
fuse_opt_add_arg(&fargs, "-d") == -1) { |
885 |
|
fuse_opt_free_args(&fargs); |
886 |
|
croak("out of memory\n"); |
887 |
|
} |
888 |
|
} else { |
889 |
|
if (fuse_opt_add_arg(&fargs, "") == -1) |
890 |
|
croak("out of memory\n"); |
891 |
|
} |
892 |
|
|
893 |
|
if(threaded) { |
894 |
|
fuse_loop_mt(fuse_new(fd,&fargs,&fops,sizeof(fops))); |
895 |
|
} else |
896 |
|
fuse_loop(fuse_new(fd,&fargs,&fops,sizeof(fops))); |
897 |
|
fuse_opt_free_args(&fargs); |