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 |
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) { |
|
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; |
return rv; |
588 |
} |
} |
589 |
|
|
590 |
int _PLfuse_flush (const char *file) { |
int _PLfuse_flush (const char *file) { |
591 |
int rv; |
int rv; |
592 |
char *rvstr; |
char *rvstr; |
593 |
|
FUSE_CONTEXT_PRE; |
594 |
dSP; |
dSP; |
595 |
DEBUGf("flush begin: %i\n",sp-PL_stack_base); |
DEBUGf("flush begin\n"); |
596 |
ENTER; |
ENTER; |
597 |
SAVETMPS; |
SAVETMPS; |
598 |
PUSHMARK(SP); |
PUSHMARK(SP); |
607 |
FREETMPS; |
FREETMPS; |
608 |
LEAVE; |
LEAVE; |
609 |
PUTBACK; |
PUTBACK; |
610 |
DEBUGf("flush end: %i\n",sp-PL_stack_base); |
DEBUGf("flush end: %i\n",rv); |
611 |
|
FUSE_CONTEXT_POST; |
612 |
return rv; |
return rv; |
613 |
} |
} |
614 |
|
|
615 |
int _PLfuse_release (const char *file, int flags) { |
int _PLfuse_release (const char *file, int flags) { |
616 |
int rv; |
int rv; |
617 |
char *rvstr; |
char *rvstr; |
618 |
|
FUSE_CONTEXT_PRE; |
619 |
dSP; |
dSP; |
620 |
DEBUGf("release begin: %i\n",sp-PL_stack_base); |
DEBUGf("release begin\n"); |
621 |
ENTER; |
ENTER; |
622 |
SAVETMPS; |
SAVETMPS; |
623 |
PUSHMARK(SP); |
PUSHMARK(SP); |
633 |
FREETMPS; |
FREETMPS; |
634 |
LEAVE; |
LEAVE; |
635 |
PUTBACK; |
PUTBACK; |
636 |
DEBUGf("release end: %i\n",sp-PL_stack_base); |
DEBUGf("release end: %i\n",rv); |
637 |
|
FUSE_CONTEXT_POST; |
638 |
return rv; |
return rv; |
639 |
} |
} |
640 |
|
|
641 |
int _PLfuse_fsync (const char *file, int flags) { |
int _PLfuse_fsync (const char *file, int flags) { |
642 |
int rv; |
int rv; |
643 |
char *rvstr; |
char *rvstr; |
644 |
|
FUSE_CONTEXT_PRE; |
645 |
dSP; |
dSP; |
646 |
DEBUGf("fsync begin: %i\n",sp-PL_stack_base); |
DEBUGf("fsync begin\n"); |
647 |
ENTER; |
ENTER; |
648 |
SAVETMPS; |
SAVETMPS; |
649 |
PUSHMARK(SP); |
PUSHMARK(SP); |
659 |
FREETMPS; |
FREETMPS; |
660 |
LEAVE; |
LEAVE; |
661 |
PUTBACK; |
PUTBACK; |
662 |
DEBUGf("fsync end: %i\n",sp-PL_stack_base); |
DEBUGf("fsync end: %i\n",rv); |
663 |
|
FUSE_CONTEXT_POST; |
664 |
return rv; |
return rv; |
665 |
} |
} |
666 |
|
|
667 |
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) { |
668 |
int rv; |
int rv; |
669 |
char *rvstr; |
char *rvstr; |
670 |
|
FUSE_CONTEXT_PRE; |
671 |
dSP; |
dSP; |
672 |
DEBUGf("setxattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("setxattr begin\n"); |
673 |
ENTER; |
ENTER; |
674 |
SAVETMPS; |
SAVETMPS; |
675 |
PUSHMARK(SP); |
PUSHMARK(SP); |
687 |
FREETMPS; |
FREETMPS; |
688 |
LEAVE; |
LEAVE; |
689 |
PUTBACK; |
PUTBACK; |
690 |
DEBUGf("setxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("setxattr end: %i\n",rv); |
691 |
|
FUSE_CONTEXT_POST; |
692 |
return rv; |
return rv; |
693 |
} |
} |
694 |
|
|
695 |
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) { |
696 |
int rv; |
int rv; |
697 |
char *rvstr; |
char *rvstr; |
698 |
|
FUSE_CONTEXT_PRE; |
699 |
dSP; |
dSP; |
700 |
DEBUGf("getxattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("getxattr begin\n"); |
701 |
ENTER; |
ENTER; |
702 |
SAVETMPS; |
SAVETMPS; |
703 |
PUSHMARK(SP); |
PUSHMARK(SP); |
732 |
FREETMPS; |
FREETMPS; |
733 |
LEAVE; |
LEAVE; |
734 |
PUTBACK; |
PUTBACK; |
735 |
DEBUGf("getxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("getxattr end: %i\n",rv); |
736 |
|
FUSE_CONTEXT_POST; |
737 |
return rv; |
return rv; |
738 |
} |
} |
739 |
|
|
740 |
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
741 |
int prv, rv; |
int prv, rv; |
742 |
char *rvstr; |
char *rvstr; |
743 |
|
FUSE_CONTEXT_PRE; |
744 |
dSP; |
dSP; |
745 |
DEBUGf("listxattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("listxattr begin\n"); |
746 |
ENTER; |
ENTER; |
747 |
SAVETMPS; |
SAVETMPS; |
748 |
PUSHMARK(SP); |
PUSHMARK(SP); |
799 |
FREETMPS; |
FREETMPS; |
800 |
LEAVE; |
LEAVE; |
801 |
PUTBACK; |
PUTBACK; |
802 |
DEBUGf("listxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("listxattr end: %i\n",rv); |
803 |
|
FUSE_CONTEXT_POST; |
804 |
return rv; |
return rv; |
805 |
} |
} |
806 |
|
|
807 |
int _PLfuse_removexattr (const char *file, const char *name) { |
int _PLfuse_removexattr (const char *file, const char *name) { |
808 |
int rv; |
int rv; |
809 |
char *rvstr; |
char *rvstr; |
810 |
|
FUSE_CONTEXT_PRE; |
811 |
dSP; |
dSP; |
812 |
DEBUGf("removexattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("removexattr begin\n"); |
813 |
ENTER; |
ENTER; |
814 |
SAVETMPS; |
SAVETMPS; |
815 |
PUSHMARK(SP); |
PUSHMARK(SP); |
825 |
FREETMPS; |
FREETMPS; |
826 |
LEAVE; |
LEAVE; |
827 |
PUTBACK; |
PUTBACK; |
828 |
DEBUGf("removexattr end: %i\n",sp-PL_stack_base); |
DEBUGf("removexattr end: %i\n",rv); |
829 |
|
FUSE_CONTEXT_POST; |
830 |
return rv; |
return rv; |
831 |
} |
} |
832 |
|
|
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,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 != 27) { |
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 |
|
#ifdef FUSE_USE_ITHREADS |
885 |
|
master_interp = PERL_GET_INTERP; |
886 |
|
#else |
887 |
|
fprintf(stderr,"FUSE warning: Your script has requested multithreaded " |
888 |
|
"mode, but your perl was not built with -Dusethreads. " |
889 |
|
"Threads are disabled.\n"); |
890 |
|
threaded = 0; |
891 |
|
#endif |
892 |
|
} |
893 |
|
mountpoint = SvPV_nolen(ST(2)); |
894 |
|
mountopts = SvPV_nolen(ST(3)); |
895 |
for(i=0;i<N_CALLBACKS;i++) { |
for(i=0;i<N_CALLBACKS;i++) { |
896 |
SV *var = ST(i+2); |
SV *var = ST(i+4); |
897 |
if((var != &PL_sv_undef) && SvROK(var)) { |
/* allow symbolic references, or real code references. */ |
898 |
if(SvTYPE(SvRV(var)) == SVt_PVCV) { |
if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) { |
899 |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
900 |
tmp2[i] = tmp1[i]; |
tmp2[i] = tmp1[i]; |
901 |
_PLfuse_callbacks[i] = var; |
#ifdef FUSE_USE_ITHREADS |
902 |
} else |
if(threaded) |
903 |
croak("arg is not a code reference!"); |
/* 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)); |