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 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 |
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); |
556 |
SPAGAIN; |
SPAGAIN; |
557 |
if(rv > 5) { |
if(rv > 5) { |
558 |
st->f_bsize = POPi; |
st->f_bsize = POPi; |
559 |
st->f_bfree = POPi; |
st->f_bfree = st->f_bavail = POPi; |
560 |
st->f_blocks = POPi; |
st->f_blocks = POPi; |
561 |
st->f_ffree = POPi; |
st->f_ffree = st->f_favail = POPi; |
562 |
st->f_files = POPi; |
st->f_files = POPi; |
563 |
st->f_namelen = POPi; |
st->f_namemax = POPi; |
564 |
|
/* zero all other */ |
565 |
|
st->f_frsize = 4096; |
566 |
|
st->f_fsid = 0; |
567 |
|
st->f_flag = 0; |
568 |
|
|
569 |
if(rv > 6) |
if(rv > 6) |
570 |
rv = POPi; |
rv = POPi; |
571 |
else |
else |
581 |
FREETMPS; |
FREETMPS; |
582 |
LEAVE; |
LEAVE; |
583 |
PUTBACK; |
PUTBACK; |
584 |
DEBUGf("statfs end: %i\n",sp-PL_stack_base); |
DEBUGf("statfs end: %i\n",rv); |
585 |
|
FUSE_CONTEXT_POST; |
586 |
|
return rv; |
587 |
|
} |
588 |
|
|
589 |
|
int _PLfuse_flush (const char *file) { |
590 |
|
int rv; |
591 |
|
char *rvstr; |
592 |
|
FUSE_CONTEXT_PRE; |
593 |
|
dSP; |
594 |
|
DEBUGf("flush begin\n"); |
595 |
|
ENTER; |
596 |
|
SAVETMPS; |
597 |
|
PUSHMARK(SP); |
598 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
599 |
|
PUTBACK; |
600 |
|
rv = call_sv(_PLfuse_callbacks[18],G_SCALAR); |
601 |
|
SPAGAIN; |
602 |
|
if(rv) |
603 |
|
rv = POPi; |
604 |
|
else |
605 |
|
rv = 0; |
606 |
|
FREETMPS; |
607 |
|
LEAVE; |
608 |
|
PUTBACK; |
609 |
|
DEBUGf("flush end: %i\n",rv); |
610 |
|
FUSE_CONTEXT_POST; |
611 |
|
return rv; |
612 |
|
} |
613 |
|
|
614 |
|
int _PLfuse_release (const char *file, int flags) { |
615 |
|
int rv; |
616 |
|
char *rvstr; |
617 |
|
FUSE_CONTEXT_PRE; |
618 |
|
dSP; |
619 |
|
DEBUGf("release begin\n"); |
620 |
|
ENTER; |
621 |
|
SAVETMPS; |
622 |
|
PUSHMARK(SP); |
623 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
624 |
|
XPUSHs(sv_2mortal(newSViv(flags))); |
625 |
|
PUTBACK; |
626 |
|
rv = call_sv(_PLfuse_callbacks[19],G_SCALAR); |
627 |
|
SPAGAIN; |
628 |
|
if(rv) |
629 |
|
rv = POPi; |
630 |
|
else |
631 |
|
rv = 0; |
632 |
|
FREETMPS; |
633 |
|
LEAVE; |
634 |
|
PUTBACK; |
635 |
|
DEBUGf("release end: %i\n",rv); |
636 |
|
FUSE_CONTEXT_POST; |
637 |
|
return rv; |
638 |
|
} |
639 |
|
|
640 |
|
int _PLfuse_fsync (const char *file, int flags) { |
641 |
|
int rv; |
642 |
|
char *rvstr; |
643 |
|
FUSE_CONTEXT_PRE; |
644 |
|
dSP; |
645 |
|
DEBUGf("fsync begin\n"); |
646 |
|
ENTER; |
647 |
|
SAVETMPS; |
648 |
|
PUSHMARK(SP); |
649 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
650 |
|
XPUSHs(sv_2mortal(newSViv(flags))); |
651 |
|
PUTBACK; |
652 |
|
rv = call_sv(_PLfuse_callbacks[20],G_SCALAR); |
653 |
|
SPAGAIN; |
654 |
|
if(rv) |
655 |
|
rv = POPi; |
656 |
|
else |
657 |
|
rv = 0; |
658 |
|
FREETMPS; |
659 |
|
LEAVE; |
660 |
|
PUTBACK; |
661 |
|
DEBUGf("fsync end: %i\n",rv); |
662 |
|
FUSE_CONTEXT_POST; |
663 |
|
return rv; |
664 |
|
} |
665 |
|
|
666 |
|
int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) { |
667 |
|
int rv; |
668 |
|
char *rvstr; |
669 |
|
FUSE_CONTEXT_PRE; |
670 |
|
dSP; |
671 |
|
DEBUGf("setxattr begin\n"); |
672 |
|
ENTER; |
673 |
|
SAVETMPS; |
674 |
|
PUSHMARK(SP); |
675 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
676 |
|
XPUSHs(sv_2mortal(newSVpv(name,0))); |
677 |
|
XPUSHs(sv_2mortal(newSVpvn(buf,buflen))); |
678 |
|
XPUSHs(sv_2mortal(newSViv(flags))); |
679 |
|
PUTBACK; |
680 |
|
rv = call_sv(_PLfuse_callbacks[21],G_SCALAR); |
681 |
|
SPAGAIN; |
682 |
|
if(rv) |
683 |
|
rv = POPi; |
684 |
|
else |
685 |
|
rv = 0; |
686 |
|
FREETMPS; |
687 |
|
LEAVE; |
688 |
|
PUTBACK; |
689 |
|
DEBUGf("setxattr end: %i\n",rv); |
690 |
|
FUSE_CONTEXT_POST; |
691 |
|
return rv; |
692 |
|
} |
693 |
|
|
694 |
|
int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) { |
695 |
|
int rv; |
696 |
|
char *rvstr; |
697 |
|
FUSE_CONTEXT_PRE; |
698 |
|
dSP; |
699 |
|
DEBUGf("getxattr begin\n"); |
700 |
|
ENTER; |
701 |
|
SAVETMPS; |
702 |
|
PUSHMARK(SP); |
703 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
704 |
|
XPUSHs(sv_2mortal(newSVpv(name,0))); |
705 |
|
PUTBACK; |
706 |
|
rv = call_sv(_PLfuse_callbacks[22],G_SCALAR); |
707 |
|
SPAGAIN; |
708 |
|
if(!rv) |
709 |
|
rv = -ENOENT; |
710 |
|
else { |
711 |
|
SV *mysv = POPs; |
712 |
|
|
713 |
|
rv = 0; |
714 |
|
if(SvTYPE(mysv) == SVt_NV || SvTYPE(mysv) == SVt_IV) |
715 |
|
rv = SvIV(mysv); |
716 |
|
else { |
717 |
|
if(SvPOK(mysv)) { |
718 |
|
rv = SvCUR(mysv); |
719 |
|
} else { |
720 |
|
rv = 0; |
721 |
|
} |
722 |
|
if ((rv > 0) && (buflen > 0)) |
723 |
|
{ |
724 |
|
if(rv > buflen) |
725 |
|
rv = -ERANGE; |
726 |
|
else |
727 |
|
memcpy(buf,SvPV_nolen(mysv),rv); |
728 |
|
} |
729 |
|
} |
730 |
|
} |
731 |
|
FREETMPS; |
732 |
|
LEAVE; |
733 |
|
PUTBACK; |
734 |
|
DEBUGf("getxattr end: %i\n",rv); |
735 |
|
FUSE_CONTEXT_POST; |
736 |
|
return rv; |
737 |
|
} |
738 |
|
|
739 |
|
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
740 |
|
int prv, rv; |
741 |
|
char *rvstr; |
742 |
|
FUSE_CONTEXT_PRE; |
743 |
|
dSP; |
744 |
|
DEBUGf("listxattr begin\n"); |
745 |
|
ENTER; |
746 |
|
SAVETMPS; |
747 |
|
PUSHMARK(SP); |
748 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
749 |
|
PUTBACK; |
750 |
|
prv = call_sv(_PLfuse_callbacks[23],G_ARRAY); |
751 |
|
SPAGAIN; |
752 |
|
if(!prv) |
753 |
|
rv = -ENOENT; |
754 |
|
else { |
755 |
|
|
756 |
|
char *p = list; |
757 |
|
int spc = size; |
758 |
|
int total_len = 0; |
759 |
|
int i; |
760 |
|
|
761 |
|
rv = POPi; |
762 |
|
prv--; |
763 |
|
|
764 |
|
/* Always nul terminate */ |
765 |
|
if (list && (size > 0)) |
766 |
|
list[0] = '\0'; |
767 |
|
|
768 |
|
while (prv > 0) |
769 |
|
{ |
770 |
|
SV *mysv = POPs; |
771 |
|
prv--; |
772 |
|
|
773 |
|
if (SvPOK(mysv)) { |
774 |
|
/* Copy nul too */ |
775 |
|
int s = SvCUR(mysv) + 1; |
776 |
|
total_len += s; |
777 |
|
|
778 |
|
if (p && (size > 0) && (spc >= s)) |
779 |
|
{ |
780 |
|
memcpy(p,SvPV_nolen(mysv),s); |
781 |
|
p += s; |
782 |
|
spc -= s; |
783 |
|
} |
784 |
|
} |
785 |
|
} |
786 |
|
|
787 |
|
/* |
788 |
|
* If the Perl returned an error, return that. |
789 |
|
* Otherwise check that the buffer was big enough. |
790 |
|
*/ |
791 |
|
if (rv == 0) |
792 |
|
{ |
793 |
|
rv = total_len; |
794 |
|
if ((size > 0) && (size < total_len)) |
795 |
|
rv = -ERANGE; |
796 |
|
} |
797 |
|
} |
798 |
|
FREETMPS; |
799 |
|
LEAVE; |
800 |
|
PUTBACK; |
801 |
|
DEBUGf("listxattr end: %i\n",rv); |
802 |
|
FUSE_CONTEXT_POST; |
803 |
|
return rv; |
804 |
|
} |
805 |
|
|
806 |
|
int _PLfuse_removexattr (const char *file, const char *name) { |
807 |
|
int rv; |
808 |
|
char *rvstr; |
809 |
|
FUSE_CONTEXT_PRE; |
810 |
|
dSP; |
811 |
|
DEBUGf("removexattr begin\n"); |
812 |
|
ENTER; |
813 |
|
SAVETMPS; |
814 |
|
PUSHMARK(SP); |
815 |
|
XPUSHs(sv_2mortal(newSVpv(file,0))); |
816 |
|
XPUSHs(sv_2mortal(newSVpv(name,0))); |
817 |
|
PUTBACK; |
818 |
|
rv = call_sv(_PLfuse_callbacks[24],G_SCALAR); |
819 |
|
SPAGAIN; |
820 |
|
if(rv) |
821 |
|
rv = POPi; |
822 |
|
else |
823 |
|
rv = 0; |
824 |
|
FREETMPS; |
825 |
|
LEAVE; |
826 |
|
PUTBACK; |
827 |
|
DEBUGf("removexattr end: %i\n",rv); |
828 |
|
FUSE_CONTEXT_POST; |
829 |
return rv; |
return rv; |
830 |
} |
} |
831 |
|
|
832 |
struct fuse_operations _available_ops = { |
struct fuse_operations _available_ops = { |
833 |
getattr: _PLfuse_getattr, |
getattr: _PLfuse_getattr, |
834 |
_PLfuse_readlink, |
readlink: _PLfuse_readlink, |
835 |
_PLfuse_getdir, |
getdir: _PLfuse_getdir, |
836 |
_PLfuse_mknod, |
mknod: _PLfuse_mknod, |
837 |
_PLfuse_mkdir, |
mkdir: _PLfuse_mkdir, |
838 |
_PLfuse_unlink, |
unlink: _PLfuse_unlink, |
839 |
_PLfuse_rmdir, |
rmdir: _PLfuse_rmdir, |
840 |
_PLfuse_symlink, |
symlink: _PLfuse_symlink, |
841 |
_PLfuse_rename, |
rename: _PLfuse_rename, |
842 |
_PLfuse_link, |
link: _PLfuse_link, |
843 |
_PLfuse_chmod, |
chmod: _PLfuse_chmod, |
844 |
_PLfuse_chown, |
chown: _PLfuse_chown, |
845 |
_PLfuse_truncate, |
truncate: _PLfuse_truncate, |
846 |
_PLfuse_utime, |
utime: _PLfuse_utime, |
847 |
_PLfuse_open, |
open: _PLfuse_open, |
848 |
_PLfuse_read, |
read: _PLfuse_read, |
849 |
_PLfuse_write, |
write: _PLfuse_write, |
850 |
_PLfuse_statfs |
statfs: _PLfuse_statfs, |
851 |
|
flush: _PLfuse_flush, |
852 |
|
release: _PLfuse_release, |
853 |
|
fsync: _PLfuse_fsync, |
854 |
|
setxattr: _PLfuse_setxattr, |
855 |
|
getxattr: _PLfuse_getxattr, |
856 |
|
listxattr: _PLfuse_listxattr, |
857 |
|
removexattr: _PLfuse_removexattr, |
858 |
}; |
}; |
859 |
|
|
860 |
MODULE = Fuse PACKAGE = Fuse |
MODULE = Fuse PACKAGE = Fuse |
863 |
void |
void |
864 |
perl_fuse_main(...) |
perl_fuse_main(...) |
865 |
PREINIT: |
PREINIT: |
866 |
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 = |
867 |
int i, fd, varnum = 0, debug, have_mnt; |
{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, |
868 |
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
869 |
|
int i, fd, varnum = 0, debug, threaded, have_mnt; |
870 |
char *mountpoint; |
char *mountpoint; |
871 |
|
char *mountopts; |
872 |
STRLEN n_a; |
STRLEN n_a; |
873 |
STRLEN l; |
STRLEN l; |
874 |
INIT: |
INIT: |
875 |
if(items != 20) { |
if(items != 29) { |
876 |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
877 |
XSRETURN_UNDEF; |
XSRETURN_UNDEF; |
878 |
} |
} |
879 |
CODE: |
CODE: |
880 |
debug = SvIV(ST(0)); |
debug = SvIV(ST(0)); |
881 |
mountpoint = SvPV_nolen(ST(1)); |
threaded = SvIV(ST(1)); |
882 |
/* FIXME: reevaluate multithreading support when perl6 arrives */ |
if(threaded) { |
883 |
for(i=0;i<18;i++) { |
#ifdef FUSE_USE_ITHREADS |
884 |
SV *var = ST(i+2); |
master_interp = PERL_GET_INTERP; |
885 |
if((var != &PL_sv_undef) && SvROK(var)) { |
#else |
886 |
if(SvTYPE(SvRV(var)) == SVt_PVCV) { |
fprintf(stderr,"FUSE warning: Your script has requested multithreaded " |
887 |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
"mode, but your perl was not built with -Dusethreads. " |
888 |
tmp2[i] = tmp1[i]; |
"Threads are disabled.\n"); |
889 |
_PLfuse_callbacks[i] = var; |
threaded = 0; |
890 |
} else |
#endif |
891 |
croak("arg is not a code reference!"); |
} |
892 |
|
mountpoint = SvPV_nolen(ST(2)); |
893 |
|
mountopts = SvPV_nolen(ST(3)); |
894 |
|
for(i=0;i<N_CALLBACKS;i++) { |
895 |
|
SV *var = ST(i+4); |
896 |
|
/* allow symbolic references, or real code references. */ |
897 |
|
if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) { |
898 |
|
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
899 |
|
tmp2[i] = tmp1[i]; |
900 |
|
#ifdef FUSE_USE_ITHREADS |
901 |
|
if(threaded) |
902 |
|
/* note: under 5.8.7, this croaks for code references. */ |
903 |
|
SvSHARE(var); |
904 |
|
#endif |
905 |
|
_PLfuse_callbacks[i] = var; |
906 |
|
} else |
907 |
|
if(SvOK(var)) { |
908 |
|
croak("invalid callback passed to perl_fuse_main " |
909 |
|
"(%s is not a string, code ref, or undef).\n", |
910 |
|
i+4,SvPVbyte_nolen(var)); |
911 |
} |
} |
912 |
} |
} |
913 |
/* FIXME: need to pass fusermount arguments */ |
/* FIXME: need to pass fusermount arguments */ |
914 |
fd = fuse_mount(mountpoint,NULL); |
fd = fuse_mount(mountpoint,mountopts); |
915 |
if(fd < 0) |
if(fd < 0) |
916 |
croak("could not mount fuse filesystem!"); |
croak("could not mount fuse filesystem!"); |
917 |
fuse_loop(fuse_new(fd,debug ? "debug" : NULL,&fops)); |
if(threaded) { |
918 |
|
fuse_loop_mt(fuse_new(fd,debug ? "debug" : NULL,&fops)); |
919 |
|
} else |
920 |
|
fuse_loop(fuse_new(fd,debug ? "debug" : NULL,&fops)); |