2 |
#include "perl.h" |
#include "perl.h" |
3 |
#include "XSUB.h" |
#include "XSUB.h" |
4 |
|
|
5 |
|
#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(); { |
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 |
28 |
|
# define FUSE_CONTEXT_POST |
29 |
|
#endif |
30 |
#include <fuse/fuse.h> |
#include <fuse/fuse.h> |
31 |
|
|
32 |
#undef DEBUGf |
#undef DEBUGf |
33 |
#if 0 |
#if 1 |
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 |
38 |
|
|
39 |
SV *_PLfuse_callbacks[18]; |
#define N_CALLBACKS 25 |
40 |
|
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) { |
|
dSP; |
|
43 |
int rv, statcount; |
int rv, statcount; |
44 |
|
FUSE_CONTEXT_PRE; |
45 |
|
dSP; |
46 |
|
DEBUGf("getattr begin: %s\n",file); |
47 |
ENTER; |
ENTER; |
48 |
SAVETMPS; |
SAVETMPS; |
49 |
PUSHMARK(SP); |
PUSHMARK(SP); |
78 |
FREETMPS; |
FREETMPS; |
79 |
LEAVE; |
LEAVE; |
80 |
PUTBACK; |
PUTBACK; |
81 |
|
DEBUGf("getattr end: %i\n",rv); |
82 |
|
FUSE_CONTEXT_POST; |
83 |
return rv; |
return rv; |
84 |
} |
} |
85 |
|
|
86 |
int _PLfuse_readlink(const char *file,char *buf,size_t buflen) { |
int _PLfuse_readlink(const char *file,char *buf,size_t buflen) { |
87 |
int rv; |
int rv; |
88 |
char *rvstr; |
char *rvstr; |
|
dSP; |
|
89 |
I32 ax; |
I32 ax; |
90 |
|
FUSE_CONTEXT_PRE; |
91 |
|
dSP; |
92 |
if(buflen < 1) |
if(buflen < 1) |
93 |
return EINVAL; |
return EINVAL; |
94 |
|
DEBUGf("readlink begin\n"); |
95 |
ENTER; |
ENTER; |
96 |
SAVETMPS; |
SAVETMPS; |
97 |
PUSHMARK(SP); |
PUSHMARK(SP); |
114 |
LEAVE; |
LEAVE; |
115 |
buf[buflen-1] = 0; |
buf[buflen-1] = 0; |
116 |
PUTBACK; |
PUTBACK; |
117 |
|
DEBUGf("readlink end: %i\n",rv); |
118 |
|
FUSE_CONTEXT_POST; |
119 |
return rv; |
return rv; |
120 |
} |
} |
121 |
|
|
122 |
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) { |
123 |
int prv, rv; |
int prv, rv; |
124 |
|
FUSE_CONTEXT_PRE; |
125 |
dSP; |
dSP; |
126 |
|
DEBUGf("getdir begin\n"); |
127 |
ENTER; |
ENTER; |
128 |
SAVETMPS; |
SAVETMPS; |
129 |
PUSHMARK(SP); |
PUSHMARK(SP); |
142 |
FREETMPS; |
FREETMPS; |
143 |
LEAVE; |
LEAVE; |
144 |
PUTBACK; |
PUTBACK; |
145 |
|
DEBUGf("getdir end: %i\n",rv); |
146 |
|
FUSE_CONTEXT_POST; |
147 |
return rv; |
return rv; |
148 |
} |
} |
149 |
|
|
151 |
int rv; |
int rv; |
152 |
SV *rvsv; |
SV *rvsv; |
153 |
char *rvstr; |
char *rvstr; |
154 |
|
FUSE_CONTEXT_PRE; |
155 |
dSP; |
dSP; |
156 |
|
DEBUGf("mknod begin\n"); |
157 |
ENTER; |
ENTER; |
158 |
SAVETMPS; |
SAVETMPS; |
159 |
PUSHMARK(SP); |
PUSHMARK(SP); |
170 |
FREETMPS; |
FREETMPS; |
171 |
LEAVE; |
LEAVE; |
172 |
PUTBACK; |
PUTBACK; |
173 |
|
DEBUGf("mknod end: %i\n",rv); |
174 |
|
FUSE_CONTEXT_POST; |
175 |
return rv; |
return rv; |
176 |
} |
} |
177 |
|
|
179 |
int rv; |
int rv; |
180 |
SV *rvsv; |
SV *rvsv; |
181 |
char *rvstr; |
char *rvstr; |
182 |
|
FUSE_CONTEXT_PRE; |
183 |
dSP; |
dSP; |
184 |
DEBUGf("mkdir begin: %i\n",sp-PL_stack_base); |
DEBUGf("mkdir begin\n"); |
185 |
ENTER; |
ENTER; |
186 |
SAVETMPS; |
SAVETMPS; |
187 |
PUSHMARK(SP); |
PUSHMARK(SP); |
197 |
FREETMPS; |
FREETMPS; |
198 |
LEAVE; |
LEAVE; |
199 |
PUTBACK; |
PUTBACK; |
200 |
DEBUGf("mkdir end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("mkdir end: %i\n",rv); |
201 |
|
FUSE_CONTEXT_POST; |
202 |
return rv; |
return rv; |
203 |
} |
} |
204 |
|
|
207 |
int rv; |
int rv; |
208 |
SV *rvsv; |
SV *rvsv; |
209 |
char *rvstr; |
char *rvstr; |
210 |
|
FUSE_CONTEXT_PRE; |
211 |
dSP; |
dSP; |
212 |
DEBUGf("unlink begin: %i\n",sp-PL_stack_base); |
DEBUGf("unlink begin\n"); |
213 |
ENTER; |
ENTER; |
214 |
SAVETMPS; |
SAVETMPS; |
215 |
PUSHMARK(SP); |
PUSHMARK(SP); |
224 |
FREETMPS; |
FREETMPS; |
225 |
LEAVE; |
LEAVE; |
226 |
PUTBACK; |
PUTBACK; |
227 |
DEBUGf("unlink end: %i\n",sp-PL_stack_base); |
DEBUGf("unlink end: %i\n",rv); |
228 |
|
FUSE_CONTEXT_POST; |
229 |
return rv; |
return rv; |
230 |
} |
} |
231 |
|
|
233 |
int rv; |
int rv; |
234 |
SV *rvsv; |
SV *rvsv; |
235 |
char *rvstr; |
char *rvstr; |
236 |
|
FUSE_CONTEXT_PRE; |
237 |
dSP; |
dSP; |
238 |
DEBUGf("rmdir begin: %i\n",sp-PL_stack_base); |
DEBUGf("rmdir begin\n"); |
239 |
ENTER; |
ENTER; |
240 |
SAVETMPS; |
SAVETMPS; |
241 |
PUSHMARK(SP); |
PUSHMARK(SP); |
250 |
FREETMPS; |
FREETMPS; |
251 |
LEAVE; |
LEAVE; |
252 |
PUTBACK; |
PUTBACK; |
253 |
DEBUGf("rmdir end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("rmdir end: %i\n",rv); |
254 |
|
FUSE_CONTEXT_POST; |
255 |
return rv; |
return rv; |
256 |
} |
} |
257 |
|
|
259 |
int rv; |
int rv; |
260 |
SV *rvsv; |
SV *rvsv; |
261 |
char *rvstr; |
char *rvstr; |
262 |
|
FUSE_CONTEXT_PRE; |
263 |
dSP; |
dSP; |
264 |
DEBUGf("symlink begin: %i\n",sp-PL_stack_base); |
DEBUGf("symlink begin\n"); |
265 |
ENTER; |
ENTER; |
266 |
SAVETMPS; |
SAVETMPS; |
267 |
PUSHMARK(SP); |
PUSHMARK(SP); |
277 |
FREETMPS; |
FREETMPS; |
278 |
LEAVE; |
LEAVE; |
279 |
PUTBACK; |
PUTBACK; |
280 |
DEBUGf("symlink end: %i\n",sp-PL_stack_base); |
DEBUGf("symlink end: %i\n",rv); |
281 |
|
FUSE_CONTEXT_POST; |
282 |
return rv; |
return rv; |
283 |
} |
} |
284 |
|
|
286 |
int rv; |
int rv; |
287 |
SV *rvsv; |
SV *rvsv; |
288 |
char *rvstr; |
char *rvstr; |
289 |
|
FUSE_CONTEXT_PRE; |
290 |
dSP; |
dSP; |
291 |
DEBUGf("rename begin: %i\n",sp-PL_stack_base); |
DEBUGf("rename begin\n"); |
292 |
ENTER; |
ENTER; |
293 |
SAVETMPS; |
SAVETMPS; |
294 |
PUSHMARK(SP); |
PUSHMARK(SP); |
304 |
FREETMPS; |
FREETMPS; |
305 |
LEAVE; |
LEAVE; |
306 |
PUTBACK; |
PUTBACK; |
307 |
DEBUGf("rename end: %i\n",sp-PL_stack_base); |
DEBUGf("rename end: %i\n",rv); |
308 |
|
FUSE_CONTEXT_POST; |
309 |
return rv; |
return rv; |
310 |
} |
} |
311 |
|
|
313 |
int rv; |
int rv; |
314 |
SV *rvsv; |
SV *rvsv; |
315 |
char *rvstr; |
char *rvstr; |
316 |
|
FUSE_CONTEXT_PRE; |
317 |
dSP; |
dSP; |
318 |
DEBUGf("link begin: %i\n",sp-PL_stack_base); |
DEBUGf("link begin\n"); |
319 |
ENTER; |
ENTER; |
320 |
SAVETMPS; |
SAVETMPS; |
321 |
PUSHMARK(SP); |
PUSHMARK(SP); |
331 |
FREETMPS; |
FREETMPS; |
332 |
LEAVE; |
LEAVE; |
333 |
PUTBACK; |
PUTBACK; |
334 |
DEBUGf("link end: %i\n",sp-PL_stack_base); |
DEBUGf("link end: %i\n",rv); |
335 |
|
FUSE_CONTEXT_POST; |
336 |
return rv; |
return rv; |
337 |
} |
} |
338 |
|
|
340 |
int rv; |
int rv; |
341 |
SV *rvsv; |
SV *rvsv; |
342 |
char *rvstr; |
char *rvstr; |
343 |
|
FUSE_CONTEXT_PRE; |
344 |
dSP; |
dSP; |
345 |
DEBUGf("chmod begin: %i\n",sp-PL_stack_base); |
DEBUGf("chmod begin\n"); |
346 |
ENTER; |
ENTER; |
347 |
SAVETMPS; |
SAVETMPS; |
348 |
PUSHMARK(SP); |
PUSHMARK(SP); |
358 |
FREETMPS; |
FREETMPS; |
359 |
LEAVE; |
LEAVE; |
360 |
PUTBACK; |
PUTBACK; |
361 |
DEBUGf("chmod end: %i\n",sp-PL_stack_base); |
DEBUGf("chmod end: %i\n",rv); |
362 |
|
FUSE_CONTEXT_POST; |
363 |
return rv; |
return rv; |
364 |
} |
} |
365 |
|
|
367 |
int rv; |
int rv; |
368 |
SV *rvsv; |
SV *rvsv; |
369 |
char *rvstr; |
char *rvstr; |
370 |
|
FUSE_CONTEXT_PRE; |
371 |
dSP; |
dSP; |
372 |
DEBUGf("chown begin: %i\n",sp-PL_stack_base); |
DEBUGf("chown begin\n"); |
373 |
ENTER; |
ENTER; |
374 |
SAVETMPS; |
SAVETMPS; |
375 |
PUSHMARK(SP); |
PUSHMARK(SP); |
386 |
FREETMPS; |
FREETMPS; |
387 |
LEAVE; |
LEAVE; |
388 |
PUTBACK; |
PUTBACK; |
389 |
DEBUGf("chown end: %i\n",sp-PL_stack_base); |
DEBUGf("chown end: %i\n",rv); |
390 |
|
FUSE_CONTEXT_POST; |
391 |
return rv; |
return rv; |
392 |
} |
} |
393 |
|
|
395 |
int rv; |
int rv; |
396 |
SV *rvsv; |
SV *rvsv; |
397 |
char *rvstr; |
char *rvstr; |
398 |
|
FUSE_CONTEXT_PRE; |
399 |
dSP; |
dSP; |
400 |
DEBUGf("truncate begin: %i\n",sp-PL_stack_base); |
DEBUGf("truncate begin\n"); |
401 |
ENTER; |
ENTER; |
402 |
SAVETMPS; |
SAVETMPS; |
403 |
PUSHMARK(SP); |
PUSHMARK(SP); |
413 |
FREETMPS; |
FREETMPS; |
414 |
LEAVE; |
LEAVE; |
415 |
PUTBACK; |
PUTBACK; |
416 |
DEBUGf("truncate end: %i\n",sp-PL_stack_base); |
DEBUGf("truncate end: %i\n",rv); |
417 |
|
FUSE_CONTEXT_POST; |
418 |
return rv; |
return rv; |
419 |
} |
} |
420 |
|
|
422 |
int rv; |
int rv; |
423 |
SV *rvsv; |
SV *rvsv; |
424 |
char *rvstr; |
char *rvstr; |
425 |
|
FUSE_CONTEXT_PRE; |
426 |
dSP; |
dSP; |
427 |
DEBUGf("utime begin: %i\n",sp-PL_stack_base); |
DEBUGf("utime begin\n"); |
428 |
ENTER; |
ENTER; |
429 |
SAVETMPS; |
SAVETMPS; |
430 |
PUSHMARK(SP); |
PUSHMARK(SP); |
441 |
FREETMPS; |
FREETMPS; |
442 |
LEAVE; |
LEAVE; |
443 |
PUTBACK; |
PUTBACK; |
444 |
DEBUGf("utime end: %i\n",sp-PL_stack_base); |
DEBUGf("utime end: %i\n",rv); |
445 |
|
FUSE_CONTEXT_POST; |
446 |
return rv; |
return rv; |
447 |
} |
} |
448 |
|
|
450 |
int rv; |
int rv; |
451 |
SV *rvsv; |
SV *rvsv; |
452 |
char *rvstr; |
char *rvstr; |
453 |
|
FUSE_CONTEXT_PRE; |
454 |
dSP; |
dSP; |
455 |
DEBUGf("open begin: %i\n",sp-PL_stack_base); |
DEBUGf("open begin\n"); |
456 |
ENTER; |
ENTER; |
457 |
SAVETMPS; |
SAVETMPS; |
458 |
PUSHMARK(SP); |
PUSHMARK(SP); |
468 |
FREETMPS; |
FREETMPS; |
469 |
LEAVE; |
LEAVE; |
470 |
PUTBACK; |
PUTBACK; |
471 |
DEBUGf("open end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("open end: %i\n",rv); |
472 |
|
FUSE_CONTEXT_POST; |
473 |
return rv; |
return rv; |
474 |
} |
} |
475 |
|
|
476 |
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) { |
477 |
int rv; |
int rv; |
478 |
char *rvstr; |
char *rvstr; |
479 |
|
FUSE_CONTEXT_PRE; |
480 |
dSP; |
dSP; |
481 |
DEBUGf("read begin: %i\n",sp-PL_stack_base); |
DEBUGf("read begin\n"); |
482 |
ENTER; |
ENTER; |
483 |
SAVETMPS; |
SAVETMPS; |
484 |
PUSHMARK(SP); |
PUSHMARK(SP); |
509 |
FREETMPS; |
FREETMPS; |
510 |
LEAVE; |
LEAVE; |
511 |
PUTBACK; |
PUTBACK; |
512 |
DEBUGf("read end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("read end: %i\n",rv); |
513 |
|
FUSE_CONTEXT_POST; |
514 |
return rv; |
return rv; |
515 |
} |
} |
516 |
|
|
517 |
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) { |
518 |
int rv; |
int rv; |
519 |
char *rvstr; |
char *rvstr; |
520 |
|
FUSE_CONTEXT_PRE; |
521 |
dSP; |
dSP; |
522 |
DEBUGf("write begin: %i\n",sp-PL_stack_base); |
DEBUGf("write begin\n"); |
523 |
ENTER; |
ENTER; |
524 |
SAVETMPS; |
SAVETMPS; |
525 |
PUSHMARK(SP); |
PUSHMARK(SP); |
536 |
FREETMPS; |
FREETMPS; |
537 |
LEAVE; |
LEAVE; |
538 |
PUTBACK; |
PUTBACK; |
539 |
DEBUGf("write end: %i\n",sp-PL_stack_base); |
DEBUGf("write end: %i\n",rv); |
540 |
|
FUSE_CONTEXT_POST; |
541 |
return rv; |
return rv; |
542 |
} |
} |
543 |
|
|
544 |
int _PLfuse_statfs (const char *file, struct statfs *st) { |
/* FIXME check for old fuse API (< 21?) and use statfs here */ |
545 |
|
int _PLfuse_statfs (const char *file, struct statvfs *st) { |
546 |
int rv; |
int rv; |
547 |
char *rvstr; |
char *rvstr; |
548 |
|
FUSE_CONTEXT_PRE; |
549 |
dSP; |
dSP; |
550 |
DEBUGf("statfs begin: %i\n",sp-PL_stack_base); |
DEBUGf("statfs begin\n"); |
551 |
ENTER; |
ENTER; |
552 |
SAVETMPS; |
SAVETMPS; |
553 |
PUSHMARK(SP); |
PUSHMARK(SP); |
554 |
PUTBACK; |
PUTBACK; |
555 |
rv = call_sv(_PLfuse_callbacks[17],G_ARRAY); |
rv = call_sv(_PLfuse_callbacks[17],G_ARRAY); |
556 |
SPAGAIN; |
SPAGAIN; |
557 |
if(rv > 5) { |
DEBUGf("statfs got %i params\n",rv); |
558 |
|
if(rv == 6 || rv == 7) { |
559 |
st->f_bsize = POPi; |
st->f_bsize = POPi; |
560 |
st->f_bfree = POPi; |
st->f_bfree = st->f_bavail = POPi; |
561 |
st->f_blocks = POPi; |
st->f_blocks = POPi; |
562 |
st->f_ffree = POPi; |
st->f_ffree = st->f_favail = POPi; |
563 |
st->f_files = POPi; |
st->f_files = POPi; |
564 |
st->f_namelen = POPi; |
st->f_namemax = POPi; |
565 |
if(rv > 6) |
/* zero all other */ |
566 |
|
st->f_frsize = 4096; |
567 |
|
st->f_fsid = 0; |
568 |
|
st->f_flag = 0; |
569 |
|
|
570 |
|
if(rv == 7) |
571 |
rv = POPi; |
rv = POPi; |
572 |
else |
else |
573 |
rv = 0; |
rv = 0; |
582 |
FREETMPS; |
FREETMPS; |
583 |
LEAVE; |
LEAVE; |
584 |
PUTBACK; |
PUTBACK; |
585 |
DEBUGf("statfs end: %i\n",sp-PL_stack_base); |
DEBUGf("statfs end: %i\n",rv); |
586 |
|
FUSE_CONTEXT_POST; |
587 |
|
return rv; |
588 |
|
} |
589 |
|
|
590 |
|
int _PLfuse_flush (const char *file) { |
591 |
|
int rv; |
592 |
|
char *rvstr; |
593 |
|
FUSE_CONTEXT_PRE; |
594 |
|
dSP; |
595 |
|
DEBUGf("flush begin\n"); |
596 |
|
ENTER; |
597 |
|
SAVETMPS; |
598 |
|
PUSHMARK(SP); |
599 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
600 |
|
PUTBACK; |
601 |
|
rv = call_sv(_PLfuse_callbacks[18],G_SCALAR); |
602 |
|
SPAGAIN; |
603 |
|
if(rv) |
604 |
|
rv = POPi; |
605 |
|
else |
606 |
|
rv = 0; |
607 |
|
FREETMPS; |
608 |
|
LEAVE; |
609 |
|
PUTBACK; |
610 |
|
DEBUGf("flush end: %i\n",rv); |
611 |
|
FUSE_CONTEXT_POST; |
612 |
|
return rv; |
613 |
|
} |
614 |
|
|
615 |
|
int _PLfuse_release (const char *file, int flags) { |
616 |
|
int rv; |
617 |
|
char *rvstr; |
618 |
|
FUSE_CONTEXT_PRE; |
619 |
|
dSP; |
620 |
|
DEBUGf("release begin\n"); |
621 |
|
ENTER; |
622 |
|
SAVETMPS; |
623 |
|
PUSHMARK(SP); |
624 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
625 |
|
XPUSHs(sv_2mortal(newSViv(flags))); |
626 |
|
PUTBACK; |
627 |
|
rv = call_sv(_PLfuse_callbacks[19],G_SCALAR); |
628 |
|
SPAGAIN; |
629 |
|
if(rv) |
630 |
|
rv = POPi; |
631 |
|
else |
632 |
|
rv = 0; |
633 |
|
FREETMPS; |
634 |
|
LEAVE; |
635 |
|
PUTBACK; |
636 |
|
DEBUGf("release end: %i\n",rv); |
637 |
|
FUSE_CONTEXT_POST; |
638 |
|
return rv; |
639 |
|
} |
640 |
|
|
641 |
|
int _PLfuse_fsync (const char *file, int flags) { |
642 |
|
int rv; |
643 |
|
char *rvstr; |
644 |
|
FUSE_CONTEXT_PRE; |
645 |
|
dSP; |
646 |
|
DEBUGf("fsync begin\n"); |
647 |
|
ENTER; |
648 |
|
SAVETMPS; |
649 |
|
PUSHMARK(SP); |
650 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
651 |
|
XPUSHs(sv_2mortal(newSViv(flags))); |
652 |
|
PUTBACK; |
653 |
|
rv = call_sv(_PLfuse_callbacks[20],G_SCALAR); |
654 |
|
SPAGAIN; |
655 |
|
if(rv) |
656 |
|
rv = POPi; |
657 |
|
else |
658 |
|
rv = 0; |
659 |
|
FREETMPS; |
660 |
|
LEAVE; |
661 |
|
PUTBACK; |
662 |
|
DEBUGf("fsync end: %i\n",rv); |
663 |
|
FUSE_CONTEXT_POST; |
664 |
|
return rv; |
665 |
|
} |
666 |
|
|
667 |
|
int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) { |
668 |
|
int rv; |
669 |
|
char *rvstr; |
670 |
|
FUSE_CONTEXT_PRE; |
671 |
|
dSP; |
672 |
|
DEBUGf("setxattr begin\n"); |
673 |
|
ENTER; |
674 |
|
SAVETMPS; |
675 |
|
PUSHMARK(SP); |
676 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
677 |
|
XPUSHs(sv_2mortal(newSVpv(name,0))); |
678 |
|
XPUSHs(sv_2mortal(newSVpvn(buf,buflen))); |
679 |
|
XPUSHs(sv_2mortal(newSViv(flags))); |
680 |
|
PUTBACK; |
681 |
|
rv = call_sv(_PLfuse_callbacks[21],G_SCALAR); |
682 |
|
SPAGAIN; |
683 |
|
if(rv) |
684 |
|
rv = POPi; |
685 |
|
else |
686 |
|
rv = 0; |
687 |
|
FREETMPS; |
688 |
|
LEAVE; |
689 |
|
PUTBACK; |
690 |
|
DEBUGf("setxattr end: %i\n",rv); |
691 |
|
FUSE_CONTEXT_POST; |
692 |
|
return rv; |
693 |
|
} |
694 |
|
|
695 |
|
int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) { |
696 |
|
int rv; |
697 |
|
char *rvstr; |
698 |
|
FUSE_CONTEXT_PRE; |
699 |
|
dSP; |
700 |
|
DEBUGf("getxattr begin\n"); |
701 |
|
ENTER; |
702 |
|
SAVETMPS; |
703 |
|
PUSHMARK(SP); |
704 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
705 |
|
XPUSHs(sv_2mortal(newSVpv(name,0))); |
706 |
|
PUTBACK; |
707 |
|
rv = call_sv(_PLfuse_callbacks[22],G_SCALAR); |
708 |
|
SPAGAIN; |
709 |
|
if(!rv) |
710 |
|
rv = -ENOENT; |
711 |
|
else { |
712 |
|
SV *mysv = POPs; |
713 |
|
|
714 |
|
rv = 0; |
715 |
|
if(SvTYPE(mysv) == SVt_NV || SvTYPE(mysv) == SVt_IV) |
716 |
|
rv = SvIV(mysv); |
717 |
|
else { |
718 |
|
if(SvPOK(mysv)) { |
719 |
|
rv = SvCUR(mysv); |
720 |
|
} else { |
721 |
|
rv = 0; |
722 |
|
} |
723 |
|
if ((rv > 0) && (buflen > 0)) |
724 |
|
{ |
725 |
|
if(rv > buflen) |
726 |
|
rv = -ERANGE; |
727 |
|
else |
728 |
|
memcpy(buf,SvPV_nolen(mysv),rv); |
729 |
|
} |
730 |
|
} |
731 |
|
} |
732 |
|
FREETMPS; |
733 |
|
LEAVE; |
734 |
|
PUTBACK; |
735 |
|
DEBUGf("getxattr end: %i\n",rv); |
736 |
|
FUSE_CONTEXT_POST; |
737 |
|
return rv; |
738 |
|
} |
739 |
|
|
740 |
|
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
741 |
|
int prv, rv; |
742 |
|
char *rvstr; |
743 |
|
FUSE_CONTEXT_PRE; |
744 |
|
dSP; |
745 |
|
DEBUGf("listxattr begin\n"); |
746 |
|
ENTER; |
747 |
|
SAVETMPS; |
748 |
|
PUSHMARK(SP); |
749 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
750 |
|
PUTBACK; |
751 |
|
prv = call_sv(_PLfuse_callbacks[23],G_ARRAY); |
752 |
|
SPAGAIN; |
753 |
|
if(!prv) |
754 |
|
rv = -ENOENT; |
755 |
|
else { |
756 |
|
|
757 |
|
char *p = list; |
758 |
|
int spc = size; |
759 |
|
int total_len = 0; |
760 |
|
int i; |
761 |
|
|
762 |
|
rv = POPi; |
763 |
|
prv--; |
764 |
|
|
765 |
|
/* Always nul terminate */ |
766 |
|
if (list && (size > 0)) |
767 |
|
list[0] = '\0'; |
768 |
|
|
769 |
|
while (prv > 0) |
770 |
|
{ |
771 |
|
SV *mysv = POPs; |
772 |
|
prv--; |
773 |
|
|
774 |
|
if (SvPOK(mysv)) { |
775 |
|
/* Copy nul too */ |
776 |
|
int s = SvCUR(mysv) + 1; |
777 |
|
total_len += s; |
778 |
|
|
779 |
|
if (p && (size > 0) && (spc >= s)) |
780 |
|
{ |
781 |
|
memcpy(p,SvPV_nolen(mysv),s); |
782 |
|
p += s; |
783 |
|
spc -= s; |
784 |
|
} |
785 |
|
} |
786 |
|
} |
787 |
|
|
788 |
|
/* |
789 |
|
* If the Perl returned an error, return that. |
790 |
|
* Otherwise check that the buffer was big enough. |
791 |
|
*/ |
792 |
|
if (rv == 0) |
793 |
|
{ |
794 |
|
rv = total_len; |
795 |
|
if ((size > 0) && (size < total_len)) |
796 |
|
rv = -ERANGE; |
797 |
|
} |
798 |
|
} |
799 |
|
FREETMPS; |
800 |
|
LEAVE; |
801 |
|
PUTBACK; |
802 |
|
DEBUGf("listxattr end: %i\n",rv); |
803 |
|
FUSE_CONTEXT_POST; |
804 |
|
return rv; |
805 |
|
} |
806 |
|
|
807 |
|
int _PLfuse_removexattr (const char *file, const char *name) { |
808 |
|
int rv; |
809 |
|
char *rvstr; |
810 |
|
FUSE_CONTEXT_PRE; |
811 |
|
dSP; |
812 |
|
DEBUGf("removexattr begin\n"); |
813 |
|
ENTER; |
814 |
|
SAVETMPS; |
815 |
|
PUSHMARK(SP); |
816 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
817 |
|
XPUSHs(sv_2mortal(newSVpv(name,0))); |
818 |
|
PUTBACK; |
819 |
|
rv = call_sv(_PLfuse_callbacks[24],G_SCALAR); |
820 |
|
SPAGAIN; |
821 |
|
if(rv) |
822 |
|
rv = POPi; |
823 |
|
else |
824 |
|
rv = 0; |
825 |
|
FREETMPS; |
826 |
|
LEAVE; |
827 |
|
PUTBACK; |
828 |
|
DEBUGf("removexattr end: %i\n",rv); |
829 |
|
FUSE_CONTEXT_POST; |
830 |
return rv; |
return rv; |
831 |
} |
} |
832 |
|
|
833 |
struct fuse_operations _available_ops = { |
struct fuse_operations _available_ops = { |
834 |
getattr: _PLfuse_getattr, |
getattr: _PLfuse_getattr, |
835 |
_PLfuse_readlink, |
readlink: _PLfuse_readlink, |
836 |
_PLfuse_getdir, |
getdir: _PLfuse_getdir, |
837 |
_PLfuse_mknod, |
mknod: _PLfuse_mknod, |
838 |
_PLfuse_mkdir, |
mkdir: _PLfuse_mkdir, |
839 |
_PLfuse_unlink, |
unlink: _PLfuse_unlink, |
840 |
_PLfuse_rmdir, |
rmdir: _PLfuse_rmdir, |
841 |
_PLfuse_symlink, |
symlink: _PLfuse_symlink, |
842 |
_PLfuse_rename, |
rename: _PLfuse_rename, |
843 |
_PLfuse_link, |
link: _PLfuse_link, |
844 |
_PLfuse_chmod, |
chmod: _PLfuse_chmod, |
845 |
_PLfuse_chown, |
chown: _PLfuse_chown, |
846 |
_PLfuse_truncate, |
truncate: _PLfuse_truncate, |
847 |
_PLfuse_utime, |
utime: _PLfuse_utime, |
848 |
_PLfuse_open, |
open: _PLfuse_open, |
849 |
_PLfuse_read, |
read: _PLfuse_read, |
850 |
_PLfuse_write, |
write: _PLfuse_write, |
851 |
_PLfuse_statfs |
statfs: _PLfuse_statfs, |
852 |
|
flush: _PLfuse_flush, |
853 |
|
release: _PLfuse_release, |
854 |
|
fsync: _PLfuse_fsync, |
855 |
|
setxattr: _PLfuse_setxattr, |
856 |
|
getxattr: _PLfuse_getxattr, |
857 |
|
listxattr: _PLfuse_listxattr, |
858 |
|
removexattr: _PLfuse_removexattr, |
859 |
}; |
}; |
860 |
|
|
861 |
MODULE = Fuse PACKAGE = Fuse |
MODULE = Fuse PACKAGE = Fuse |
864 |
void |
void |
865 |
perl_fuse_main(...) |
perl_fuse_main(...) |
866 |
PREINIT: |
PREINIT: |
867 |
struct fuse_operations fops = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
struct fuse_operations fops = |
868 |
int i, fd, varnum = 0, debug, have_mnt; |
{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, |
869 |
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
870 |
|
int i, fd, varnum = 0, debug, threaded, have_mnt; |
871 |
char *mountpoint; |
char *mountpoint; |
872 |
|
char *mountopts; |
873 |
STRLEN n_a; |
STRLEN n_a; |
874 |
STRLEN l; |
STRLEN l; |
875 |
INIT: |
INIT: |
876 |
if(items != 20) { |
if(items != 29) { |
877 |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
878 |
XSRETURN_UNDEF; |
XSRETURN_UNDEF; |
879 |
} |
} |
880 |
CODE: |
CODE: |
881 |
debug = SvIV(ST(0)); |
debug = SvIV(ST(0)); |
882 |
mountpoint = SvPV_nolen(ST(1)); |
threaded = SvIV(ST(1)); |
883 |
/* FIXME: reevaluate multithreading support when perl6 arrives */ |
if(threaded) { |
884 |
for(i=0;i<18;i++) { |
#ifdef FUSE_USE_ITHREADS |
885 |
SV *var = ST(i+2); |
master_interp = PERL_GET_INTERP; |
886 |
if((var != &PL_sv_undef) && SvROK(var)) { |
#else |
887 |
if(SvTYPE(SvRV(var)) == SVt_PVCV) { |
fprintf(stderr,"FUSE warning: Your script has requested multithreaded " |
888 |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
"mode, but your perl was not built with -Dusethreads. " |
889 |
tmp2[i] = tmp1[i]; |
"Threads are disabled.\n"); |
890 |
_PLfuse_callbacks[i] = var; |
threaded = 0; |
891 |
} else |
#endif |
892 |
croak("arg is not a code reference!"); |
} |
893 |
|
mountpoint = SvPV_nolen(ST(2)); |
894 |
|
mountopts = SvPV_nolen(ST(3)); |
895 |
|
for(i=0;i<N_CALLBACKS;i++) { |
896 |
|
SV *var = ST(i+4); |
897 |
|
/* allow symbolic references, or real code references. */ |
898 |
|
if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) { |
899 |
|
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
900 |
|
tmp2[i] = tmp1[i]; |
901 |
|
#ifdef FUSE_USE_ITHREADS |
902 |
|
if(threaded) |
903 |
|
/* note: under 5.8.7, this croaks for code references. */ |
904 |
|
SvSHARE(var); |
905 |
|
#endif |
906 |
|
_PLfuse_callbacks[i] = var; |
907 |
|
} else |
908 |
|
if(SvOK(var)) { |
909 |
|
croak("invalid callback passed to perl_fuse_main " |
910 |
|
"(%s is not a string, code ref, or undef).\n", |
911 |
|
i+4,SvPVbyte_nolen(var)); |
912 |
} |
} |
913 |
} |
} |
914 |
/* FIXME: need to pass fusermount arguments */ |
/* FIXME: need to pass fusermount arguments */ |
915 |
fd = fuse_mount(mountpoint,NULL); |
fd = fuse_mount(mountpoint,mountopts); |
916 |
if(fd < 0) |
if(fd < 0) |
917 |
croak("could not mount fuse filesystem!"); |
croak("could not mount fuse filesystem!"); |
918 |
fuse_loop(fuse_new(fd,debug ? "debug" : NULL,&fops)); |
if(threaded) { |
919 |
|
fuse_loop_mt(fuse_new(fd,debug ? "debug" : NULL,&fops)); |
920 |
|
} else |
921 |
|
fuse_loop(fuse_new(fd,debug ? "debug" : NULL,&fops)); |