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(); { |
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.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 |
|
int rv; |
44 |
|
FUSE_CONTEXT_PRE; |
45 |
dSP; |
dSP; |
46 |
int rv, statcount; |
DEBUGf("getattr begin: %s\n",file); |
47 |
ENTER; |
ENTER; |
48 |
SAVETMPS; |
SAVETMPS; |
49 |
PUSHMARK(SP); |
PUSHMARK(SP); |
71 |
result->st_uid = POPi; |
result->st_uid = POPi; |
72 |
result->st_nlink = POPi; |
result->st_nlink = POPi; |
73 |
result->st_mode = POPi; |
result->st_mode = POPi; |
74 |
/*result->st_ino =*/ POPi; |
result->st_ino = POPi; |
75 |
result->st_dev = POPi; |
result->st_dev = POPi; |
76 |
rv = 0; |
rv = 0; |
77 |
} |
} |
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; |
FUSE_CONTEXT_PRE; |
89 |
dSP; |
dSP; |
|
I32 ax; |
|
90 |
if(buflen < 1) |
if(buflen < 1) |
91 |
return EINVAL; |
return EINVAL; |
92 |
|
DEBUGf("readlink begin\n"); |
93 |
ENTER; |
ENTER; |
94 |
SAVETMPS; |
SAVETMPS; |
95 |
PUSHMARK(SP); |
PUSHMARK(SP); |
112 |
LEAVE; |
LEAVE; |
113 |
buf[buflen-1] = 0; |
buf[buflen-1] = 0; |
114 |
PUTBACK; |
PUTBACK; |
115 |
|
DEBUGf("readlink end: %i\n",rv); |
116 |
|
FUSE_CONTEXT_POST; |
117 |
return rv; |
return rv; |
118 |
} |
} |
119 |
|
|
120 |
|
#if 0 |
121 |
|
/* |
122 |
|
* This doesn't yet work... we alwas get ENOSYS when trying to use readdir(). |
123 |
|
* Well, of course, getdir() is fine as well. |
124 |
|
*/ |
125 |
|
int _PLfuse_readdir(const char *file, void *dirh, fuse_fill_dir_t dirfil, off_t off, struct fuse_file_info *fi) { |
126 |
|
#endif |
127 |
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) { |
128 |
int prv, rv; |
int prv, rv; |
129 |
|
FUSE_CONTEXT_PRE; |
130 |
dSP; |
dSP; |
131 |
|
DEBUGf("getdir begin\n"); |
132 |
ENTER; |
ENTER; |
133 |
SAVETMPS; |
SAVETMPS; |
134 |
PUSHMARK(SP); |
PUSHMARK(SP); |
139 |
if(prv) { |
if(prv) { |
140 |
rv = POPi; |
rv = POPi; |
141 |
while(--prv) |
while(--prv) |
142 |
dirfil(dirh,POPp,0); |
dirfil(dirh,POPp,0,0); |
143 |
} else { |
} else { |
144 |
fprintf(stderr,"getdir() handler returned nothing!\n"); |
fprintf(stderr,"getdir() handler returned nothing!\n"); |
145 |
rv = -ENOSYS; |
rv = -ENOSYS; |
147 |
FREETMPS; |
FREETMPS; |
148 |
LEAVE; |
LEAVE; |
149 |
PUTBACK; |
PUTBACK; |
150 |
|
DEBUGf("getdir end: %i\n",rv); |
151 |
|
FUSE_CONTEXT_POST; |
152 |
return rv; |
return rv; |
153 |
} |
} |
154 |
|
|
155 |
int _PLfuse_mknod (const char *file, mode_t mode, dev_t dev) { |
int _PLfuse_mknod (const char *file, mode_t mode, dev_t dev) { |
156 |
int rv; |
int rv; |
157 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
158 |
dSP; |
dSP; |
159 |
|
DEBUGf("mknod begin\n"); |
160 |
ENTER; |
ENTER; |
161 |
SAVETMPS; |
SAVETMPS; |
162 |
PUSHMARK(SP); |
PUSHMARK(SP); |
173 |
FREETMPS; |
FREETMPS; |
174 |
LEAVE; |
LEAVE; |
175 |
PUTBACK; |
PUTBACK; |
176 |
|
DEBUGf("mknod end: %i\n",rv); |
177 |
|
FUSE_CONTEXT_POST; |
178 |
return rv; |
return rv; |
179 |
} |
} |
180 |
|
|
181 |
int _PLfuse_mkdir (const char *file, mode_t mode) { |
int _PLfuse_mkdir (const char *file, mode_t mode) { |
182 |
int rv; |
int rv; |
183 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
184 |
dSP; |
dSP; |
185 |
DEBUGf("mkdir begin: %i\n",sp-PL_stack_base); |
DEBUGf("mkdir begin\n"); |
186 |
ENTER; |
ENTER; |
187 |
SAVETMPS; |
SAVETMPS; |
188 |
PUSHMARK(SP); |
PUSHMARK(SP); |
198 |
FREETMPS; |
FREETMPS; |
199 |
LEAVE; |
LEAVE; |
200 |
PUTBACK; |
PUTBACK; |
201 |
DEBUGf("mkdir end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("mkdir end: %i\n",rv); |
202 |
|
FUSE_CONTEXT_POST; |
203 |
return rv; |
return rv; |
204 |
} |
} |
205 |
|
|
206 |
|
|
207 |
int _PLfuse_unlink (const char *file) { |
int _PLfuse_unlink (const char *file) { |
208 |
int rv; |
int rv; |
209 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
210 |
dSP; |
dSP; |
211 |
DEBUGf("unlink begin: %i\n",sp-PL_stack_base); |
DEBUGf("unlink begin\n"); |
212 |
ENTER; |
ENTER; |
213 |
SAVETMPS; |
SAVETMPS; |
214 |
PUSHMARK(SP); |
PUSHMARK(SP); |
223 |
FREETMPS; |
FREETMPS; |
224 |
LEAVE; |
LEAVE; |
225 |
PUTBACK; |
PUTBACK; |
226 |
DEBUGf("unlink end: %i\n",sp-PL_stack_base); |
DEBUGf("unlink end: %i\n",rv); |
227 |
|
FUSE_CONTEXT_POST; |
228 |
return rv; |
return rv; |
229 |
} |
} |
230 |
|
|
231 |
int _PLfuse_rmdir (const char *file) { |
int _PLfuse_rmdir (const char *file) { |
232 |
int rv; |
int rv; |
233 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
234 |
dSP; |
dSP; |
235 |
DEBUGf("rmdir begin: %i\n",sp-PL_stack_base); |
DEBUGf("rmdir begin\n"); |
236 |
ENTER; |
ENTER; |
237 |
SAVETMPS; |
SAVETMPS; |
238 |
PUSHMARK(SP); |
PUSHMARK(SP); |
247 |
FREETMPS; |
FREETMPS; |
248 |
LEAVE; |
LEAVE; |
249 |
PUTBACK; |
PUTBACK; |
250 |
DEBUGf("rmdir end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("rmdir end: %i\n",rv); |
251 |
|
FUSE_CONTEXT_POST; |
252 |
return rv; |
return rv; |
253 |
} |
} |
254 |
|
|
255 |
int _PLfuse_symlink (const char *file, const char *new) { |
int _PLfuse_symlink (const char *file, const char *new) { |
256 |
int rv; |
int rv; |
257 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
258 |
dSP; |
dSP; |
259 |
DEBUGf("symlink begin: %i\n",sp-PL_stack_base); |
DEBUGf("symlink begin\n"); |
260 |
ENTER; |
ENTER; |
261 |
SAVETMPS; |
SAVETMPS; |
262 |
PUSHMARK(SP); |
PUSHMARK(SP); |
272 |
FREETMPS; |
FREETMPS; |
273 |
LEAVE; |
LEAVE; |
274 |
PUTBACK; |
PUTBACK; |
275 |
DEBUGf("symlink end: %i\n",sp-PL_stack_base); |
DEBUGf("symlink end: %i\n",rv); |
276 |
|
FUSE_CONTEXT_POST; |
277 |
return rv; |
return rv; |
278 |
} |
} |
279 |
|
|
280 |
int _PLfuse_rename (const char *file, const char *new) { |
int _PLfuse_rename (const char *file, const char *new) { |
281 |
int rv; |
int rv; |
282 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
283 |
dSP; |
dSP; |
284 |
DEBUGf("rename begin: %i\n",sp-PL_stack_base); |
DEBUGf("rename begin\n"); |
285 |
ENTER; |
ENTER; |
286 |
SAVETMPS; |
SAVETMPS; |
287 |
PUSHMARK(SP); |
PUSHMARK(SP); |
297 |
FREETMPS; |
FREETMPS; |
298 |
LEAVE; |
LEAVE; |
299 |
PUTBACK; |
PUTBACK; |
300 |
DEBUGf("rename end: %i\n",sp-PL_stack_base); |
DEBUGf("rename end: %i\n",rv); |
301 |
|
FUSE_CONTEXT_POST; |
302 |
return rv; |
return rv; |
303 |
} |
} |
304 |
|
|
305 |
int _PLfuse_link (const char *file, const char *new) { |
int _PLfuse_link (const char *file, const char *new) { |
306 |
int rv; |
int rv; |
307 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
308 |
dSP; |
dSP; |
309 |
DEBUGf("link begin: %i\n",sp-PL_stack_base); |
DEBUGf("link begin\n"); |
310 |
ENTER; |
ENTER; |
311 |
SAVETMPS; |
SAVETMPS; |
312 |
PUSHMARK(SP); |
PUSHMARK(SP); |
322 |
FREETMPS; |
FREETMPS; |
323 |
LEAVE; |
LEAVE; |
324 |
PUTBACK; |
PUTBACK; |
325 |
DEBUGf("link end: %i\n",sp-PL_stack_base); |
DEBUGf("link end: %i\n",rv); |
326 |
|
FUSE_CONTEXT_POST; |
327 |
return rv; |
return rv; |
328 |
} |
} |
329 |
|
|
330 |
int _PLfuse_chmod (const char *file, mode_t mode) { |
int _PLfuse_chmod (const char *file, mode_t mode) { |
331 |
int rv; |
int rv; |
332 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
333 |
dSP; |
dSP; |
334 |
DEBUGf("chmod begin: %i\n",sp-PL_stack_base); |
DEBUGf("chmod begin\n"); |
335 |
ENTER; |
ENTER; |
336 |
SAVETMPS; |
SAVETMPS; |
337 |
PUSHMARK(SP); |
PUSHMARK(SP); |
347 |
FREETMPS; |
FREETMPS; |
348 |
LEAVE; |
LEAVE; |
349 |
PUTBACK; |
PUTBACK; |
350 |
DEBUGf("chmod end: %i\n",sp-PL_stack_base); |
DEBUGf("chmod end: %i\n",rv); |
351 |
|
FUSE_CONTEXT_POST; |
352 |
return rv; |
return rv; |
353 |
} |
} |
354 |
|
|
355 |
int _PLfuse_chown (const char *file, uid_t uid, gid_t gid) { |
int _PLfuse_chown (const char *file, uid_t uid, gid_t gid) { |
356 |
int rv; |
int rv; |
357 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
358 |
dSP; |
dSP; |
359 |
DEBUGf("chown begin: %i\n",sp-PL_stack_base); |
DEBUGf("chown begin\n"); |
360 |
ENTER; |
ENTER; |
361 |
SAVETMPS; |
SAVETMPS; |
362 |
PUSHMARK(SP); |
PUSHMARK(SP); |
373 |
FREETMPS; |
FREETMPS; |
374 |
LEAVE; |
LEAVE; |
375 |
PUTBACK; |
PUTBACK; |
376 |
DEBUGf("chown end: %i\n",sp-PL_stack_base); |
DEBUGf("chown end: %i\n",rv); |
377 |
|
FUSE_CONTEXT_POST; |
378 |
return rv; |
return rv; |
379 |
} |
} |
380 |
|
|
381 |
int _PLfuse_truncate (const char *file, off_t off) { |
int _PLfuse_truncate (const char *file, off_t off) { |
382 |
int rv; |
int rv; |
383 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
384 |
dSP; |
dSP; |
385 |
DEBUGf("truncate begin: %i\n",sp-PL_stack_base); |
DEBUGf("truncate begin\n"); |
386 |
ENTER; |
ENTER; |
387 |
SAVETMPS; |
SAVETMPS; |
388 |
PUSHMARK(SP); |
PUSHMARK(SP); |
398 |
FREETMPS; |
FREETMPS; |
399 |
LEAVE; |
LEAVE; |
400 |
PUTBACK; |
PUTBACK; |
401 |
DEBUGf("truncate end: %i\n",sp-PL_stack_base); |
DEBUGf("truncate end: %i\n",rv); |
402 |
|
FUSE_CONTEXT_POST; |
403 |
return rv; |
return rv; |
404 |
} |
} |
405 |
|
|
406 |
int _PLfuse_utime (const char *file, struct utimbuf *uti) { |
int _PLfuse_utime (const char *file, struct utimbuf *uti) { |
407 |
int rv; |
int rv; |
408 |
SV *rvsv; |
FUSE_CONTEXT_PRE; |
|
char *rvstr; |
|
409 |
dSP; |
dSP; |
410 |
DEBUGf("utime begin: %i\n",sp-PL_stack_base); |
DEBUGf("utime begin\n"); |
411 |
ENTER; |
ENTER; |
412 |
SAVETMPS; |
SAVETMPS; |
413 |
PUSHMARK(SP); |
PUSHMARK(SP); |
424 |
FREETMPS; |
FREETMPS; |
425 |
LEAVE; |
LEAVE; |
426 |
PUTBACK; |
PUTBACK; |
427 |
DEBUGf("utime end: %i\n",sp-PL_stack_base); |
DEBUGf("utime end: %i\n",rv); |
428 |
|
FUSE_CONTEXT_POST; |
429 |
return rv; |
return rv; |
430 |
} |
} |
431 |
|
|
432 |
int _PLfuse_open (const char *file, int flags) { |
int _PLfuse_open (const char *file, struct fuse_file_info *fi) { |
433 |
int rv; |
int rv; |
434 |
SV *rvsv; |
int flags = fi->flags; |
435 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
436 |
dSP; |
dSP; |
437 |
DEBUGf("open begin: %i\n",sp-PL_stack_base); |
DEBUGf("open begin\n"); |
438 |
ENTER; |
ENTER; |
439 |
SAVETMPS; |
SAVETMPS; |
440 |
PUSHMARK(SP); |
PUSHMARK(SP); |
450 |
FREETMPS; |
FREETMPS; |
451 |
LEAVE; |
LEAVE; |
452 |
PUTBACK; |
PUTBACK; |
453 |
DEBUGf("open end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("open end: %i\n",rv); |
454 |
|
FUSE_CONTEXT_POST; |
455 |
return rv; |
return rv; |
456 |
} |
} |
457 |
|
|
458 |
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) { |
459 |
int rv; |
int rv; |
460 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
461 |
dSP; |
dSP; |
462 |
DEBUGf("read begin: %i\n",sp-PL_stack_base); |
DEBUGf("read begin\n"); |
463 |
ENTER; |
ENTER; |
464 |
SAVETMPS; |
SAVETMPS; |
465 |
PUSHMARK(SP); |
PUSHMARK(SP); |
490 |
FREETMPS; |
FREETMPS; |
491 |
LEAVE; |
LEAVE; |
492 |
PUTBACK; |
PUTBACK; |
493 |
DEBUGf("read end: %i %i\n",sp-PL_stack_base,rv); |
DEBUGf("read end: %i\n",rv); |
494 |
|
FUSE_CONTEXT_POST; |
495 |
return rv; |
return rv; |
496 |
} |
} |
497 |
|
|
498 |
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) { |
499 |
int rv; |
int rv; |
500 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
501 |
dSP; |
dSP; |
502 |
DEBUGf("write begin: %i\n",sp-PL_stack_base); |
DEBUGf("write begin\n"); |
503 |
ENTER; |
ENTER; |
504 |
SAVETMPS; |
SAVETMPS; |
505 |
PUSHMARK(SP); |
PUSHMARK(SP); |
516 |
FREETMPS; |
FREETMPS; |
517 |
LEAVE; |
LEAVE; |
518 |
PUTBACK; |
PUTBACK; |
519 |
DEBUGf("write end: %i\n",sp-PL_stack_base); |
DEBUGf("write end: %i\n",rv); |
520 |
|
FUSE_CONTEXT_POST; |
521 |
return rv; |
return rv; |
522 |
} |
} |
523 |
|
|
524 |
int _PLfuse_statfs (const char *file, struct statfs *st) { |
int _PLfuse_statfs (const char *file, struct statvfs *st) { |
525 |
int rv; |
int rv; |
526 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
527 |
dSP; |
dSP; |
528 |
DEBUGf("statfs begin: %i\n",sp-PL_stack_base); |
DEBUGf("statfs begin\n"); |
529 |
ENTER; |
ENTER; |
530 |
SAVETMPS; |
SAVETMPS; |
531 |
PUSHMARK(SP); |
PUSHMARK(SP); |
532 |
PUTBACK; |
PUTBACK; |
533 |
rv = call_sv(_PLfuse_callbacks[17],G_ARRAY); |
rv = call_sv(_PLfuse_callbacks[17],G_ARRAY); |
534 |
SPAGAIN; |
SPAGAIN; |
535 |
if(rv > 5) { |
DEBUGf("statfs got %i params\n",rv); |
536 |
st->f_bsize = POPi; |
if(rv == 6 || rv == 7) { |
537 |
st->f_bfree = POPi; |
st->f_bsize = POPi; |
538 |
st->f_blocks = POPi; |
st->f_bfree = POPi; |
539 |
st->f_ffree = POPi; |
st->f_blocks = POPi; |
540 |
st->f_files = POPi; |
st->f_ffree = POPi; |
541 |
st->f_namelen = POPi; |
st->f_files = POPi; |
542 |
if(rv > 6) |
st->f_namemax = POPi; |
543 |
|
/* zero and fill-in other */ |
544 |
|
st->f_fsid = 0; |
545 |
|
st->f_frsize = 4096; |
546 |
|
st->f_flag = 0; |
547 |
|
st->f_bavail = st->f_bfree; |
548 |
|
st->f_favail = st->f_ffree; |
549 |
|
|
550 |
|
if(rv == 7) |
551 |
rv = POPi; |
rv = POPi; |
552 |
else |
else |
553 |
rv = 0; |
rv = 0; |
562 |
FREETMPS; |
FREETMPS; |
563 |
LEAVE; |
LEAVE; |
564 |
PUTBACK; |
PUTBACK; |
565 |
DEBUGf("statfs end: %i\n",sp-PL_stack_base); |
DEBUGf("statfs end: %i\n",rv); |
566 |
|
FUSE_CONTEXT_POST; |
567 |
return rv; |
return rv; |
568 |
} |
} |
569 |
|
|
570 |
int _PLfuse_flush (const char *file) { |
int _PLfuse_flush (const char *file, struct fuse_file_info *fi) { |
571 |
int rv; |
int rv; |
572 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
573 |
dSP; |
dSP; |
574 |
DEBUGf("flush begin: %i\n",sp-PL_stack_base); |
DEBUGf("flush begin\n"); |
575 |
ENTER; |
ENTER; |
576 |
SAVETMPS; |
SAVETMPS; |
577 |
PUSHMARK(SP); |
PUSHMARK(SP); |
586 |
FREETMPS; |
FREETMPS; |
587 |
LEAVE; |
LEAVE; |
588 |
PUTBACK; |
PUTBACK; |
589 |
DEBUGf("flush end: %i\n",sp-PL_stack_base); |
DEBUGf("flush end: %i\n",rv); |
590 |
|
FUSE_CONTEXT_POST; |
591 |
return rv; |
return rv; |
592 |
} |
} |
593 |
|
|
594 |
int _PLfuse_release (const char *file, int flags) { |
int _PLfuse_release (const char *file, struct fuse_file_info *fi) { |
595 |
int rv; |
int rv; |
596 |
char *rvstr; |
int flags = fi->flags; |
597 |
|
FUSE_CONTEXT_PRE; |
598 |
dSP; |
dSP; |
599 |
DEBUGf("release begin: %i\n",sp-PL_stack_base); |
DEBUGf("release begin\n"); |
600 |
ENTER; |
ENTER; |
601 |
SAVETMPS; |
SAVETMPS; |
602 |
PUSHMARK(SP); |
PUSHMARK(SP); |
612 |
FREETMPS; |
FREETMPS; |
613 |
LEAVE; |
LEAVE; |
614 |
PUTBACK; |
PUTBACK; |
615 |
DEBUGf("release end: %i\n",sp-PL_stack_base); |
DEBUGf("release end: %i\n",rv); |
616 |
|
FUSE_CONTEXT_POST; |
617 |
return rv; |
return rv; |
618 |
} |
} |
619 |
|
|
620 |
int _PLfuse_fsync (const char *file, int flags) { |
int _PLfuse_fsync (const char *file, int datasync, struct fuse_file_info *fi) { |
621 |
int rv; |
int rv; |
622 |
char *rvstr; |
int flags = fi->flags; |
623 |
|
FUSE_CONTEXT_PRE; |
624 |
dSP; |
dSP; |
625 |
DEBUGf("fsync begin: %i\n",sp-PL_stack_base); |
DEBUGf("fsync begin\n"); |
626 |
ENTER; |
ENTER; |
627 |
SAVETMPS; |
SAVETMPS; |
628 |
PUSHMARK(SP); |
PUSHMARK(SP); |
638 |
FREETMPS; |
FREETMPS; |
639 |
LEAVE; |
LEAVE; |
640 |
PUTBACK; |
PUTBACK; |
641 |
DEBUGf("fsync end: %i\n",sp-PL_stack_base); |
DEBUGf("fsync end: %i\n",rv); |
642 |
|
FUSE_CONTEXT_POST; |
643 |
return rv; |
return rv; |
644 |
} |
} |
645 |
|
|
646 |
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) { |
647 |
int rv; |
int rv; |
648 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
649 |
dSP; |
dSP; |
650 |
DEBUGf("setxattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("setxattr begin\n"); |
651 |
ENTER; |
ENTER; |
652 |
SAVETMPS; |
SAVETMPS; |
653 |
PUSHMARK(SP); |
PUSHMARK(SP); |
665 |
FREETMPS; |
FREETMPS; |
666 |
LEAVE; |
LEAVE; |
667 |
PUTBACK; |
PUTBACK; |
668 |
DEBUGf("setxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("setxattr end: %i\n",rv); |
669 |
|
FUSE_CONTEXT_POST; |
670 |
return rv; |
return rv; |
671 |
} |
} |
672 |
|
|
673 |
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) { |
674 |
int rv; |
int rv; |
675 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
676 |
dSP; |
dSP; |
677 |
DEBUGf("getxattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("getxattr begin\n"); |
678 |
ENTER; |
ENTER; |
679 |
SAVETMPS; |
SAVETMPS; |
680 |
PUSHMARK(SP); |
PUSHMARK(SP); |
709 |
FREETMPS; |
FREETMPS; |
710 |
LEAVE; |
LEAVE; |
711 |
PUTBACK; |
PUTBACK; |
712 |
DEBUGf("getxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("getxattr end: %i\n",rv); |
713 |
|
FUSE_CONTEXT_POST; |
714 |
return rv; |
return rv; |
715 |
} |
} |
716 |
|
|
717 |
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
int _PLfuse_listxattr (const char *file, char *list, size_t size) { |
718 |
int prv, rv; |
int prv, rv; |
719 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
720 |
dSP; |
dSP; |
721 |
DEBUGf("listxattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("listxattr begin\n"); |
722 |
ENTER; |
ENTER; |
723 |
SAVETMPS; |
SAVETMPS; |
724 |
PUSHMARK(SP); |
PUSHMARK(SP); |
733 |
char *p = list; |
char *p = list; |
734 |
int spc = size; |
int spc = size; |
735 |
int total_len = 0; |
int total_len = 0; |
|
int i; |
|
736 |
|
|
737 |
rv = POPi; |
rv = POPi; |
738 |
prv--; |
prv--; |
774 |
FREETMPS; |
FREETMPS; |
775 |
LEAVE; |
LEAVE; |
776 |
PUTBACK; |
PUTBACK; |
777 |
DEBUGf("listxattr end: %i\n",sp-PL_stack_base); |
DEBUGf("listxattr end: %i\n",rv); |
778 |
|
FUSE_CONTEXT_POST; |
779 |
return rv; |
return rv; |
780 |
} |
} |
781 |
|
|
782 |
int _PLfuse_removexattr (const char *file, const char *name) { |
int _PLfuse_removexattr (const char *file, const char *name) { |
783 |
int rv; |
int rv; |
784 |
char *rvstr; |
FUSE_CONTEXT_PRE; |
785 |
dSP; |
dSP; |
786 |
DEBUGf("removexattr begin: %i\n",sp-PL_stack_base); |
DEBUGf("removexattr begin\n"); |
787 |
ENTER; |
ENTER; |
788 |
SAVETMPS; |
SAVETMPS; |
789 |
PUSHMARK(SP); |
PUSHMARK(SP); |
799 |
FREETMPS; |
FREETMPS; |
800 |
LEAVE; |
LEAVE; |
801 |
PUTBACK; |
PUTBACK; |
802 |
DEBUGf("removexattr end: %i\n",sp-PL_stack_base); |
DEBUGf("removexattr end: %i\n",rv); |
803 |
|
FUSE_CONTEXT_POST; |
804 |
return rv; |
return rv; |
805 |
} |
} |
806 |
|
|
808 |
getattr: _PLfuse_getattr, |
getattr: _PLfuse_getattr, |
809 |
readlink: _PLfuse_readlink, |
readlink: _PLfuse_readlink, |
810 |
getdir: _PLfuse_getdir, |
getdir: _PLfuse_getdir, |
811 |
|
#if 0 |
812 |
|
readdir: _PLfuse_readdir, |
813 |
|
#endif |
814 |
mknod: _PLfuse_mknod, |
mknod: _PLfuse_mknod, |
815 |
mkdir: _PLfuse_mkdir, |
mkdir: _PLfuse_mkdir, |
816 |
unlink: _PLfuse_unlink, |
unlink: _PLfuse_unlink, |
841 |
void |
void |
842 |
perl_fuse_main(...) |
perl_fuse_main(...) |
843 |
PREINIT: |
PREINIT: |
844 |
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 = |
845 |
int i, fd, varnum = 0, debug, have_mnt; |
{NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, |
846 |
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
847 |
|
int i, fd, debug, threaded; |
848 |
char *mountpoint; |
char *mountpoint; |
849 |
STRLEN n_a; |
char *mountopts; |
850 |
STRLEN l; |
struct fuse_args margs = FUSE_ARGS_INIT(0, NULL); |
851 |
|
struct fuse_args fargs = FUSE_ARGS_INIT(0, NULL); |
852 |
INIT: |
INIT: |
853 |
if(items != 27) { |
if(items != 29) { |
854 |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
fprintf(stderr,"Perl<->C inconsistency or internal error\n"); |
855 |
XSRETURN_UNDEF; |
XSRETURN_UNDEF; |
856 |
} |
} |
857 |
CODE: |
CODE: |
858 |
debug = SvIV(ST(0)); |
debug = SvIV(ST(0)); |
859 |
mountpoint = SvPV_nolen(ST(1)); |
threaded = SvIV(ST(1)); |
860 |
/* FIXME: reevaluate multithreading support when perl6 arrives */ |
if(threaded) { |
861 |
|
#ifdef FUSE_USE_ITHREADS |
862 |
|
master_interp = PERL_GET_INTERP; |
863 |
|
#else |
864 |
|
fprintf(stderr,"FUSE warning: Your script has requested multithreaded " |
865 |
|
"mode, but your perl was not built with -Dusethreads. " |
866 |
|
"Threads are disabled.\n"); |
867 |
|
threaded = 0; |
868 |
|
#endif |
869 |
|
} |
870 |
|
mountpoint = SvPV_nolen(ST(2)); |
871 |
|
mountopts = SvPV_nolen(ST(3)); |
872 |
for(i=0;i<N_CALLBACKS;i++) { |
for(i=0;i<N_CALLBACKS;i++) { |
873 |
SV *var = ST(i+2); |
SV *var = ST(i+4); |
874 |
if((var != &PL_sv_undef) && SvROK(var)) { |
/* allow symbolic references, or real code references. */ |
875 |
if(SvTYPE(SvRV(var)) == SVt_PVCV) { |
if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) { |
876 |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; |
877 |
tmp2[i] = tmp1[i]; |
tmp2[i] = tmp1[i]; |
878 |
_PLfuse_callbacks[i] = var; |
#ifdef FUSE_USE_ITHREADS |
879 |
} else |
if(threaded) |
880 |
croak("arg is not a code reference!"); |
/* note: under 5.8.7, this croaks for code references. */ |
881 |
|
SvSHARE(var); |
882 |
|
#endif |
883 |
|
_PLfuse_callbacks[i] = var; |
884 |
|
} else |
885 |
|
if(SvOK(var)) { |
886 |
|
croak("invalid callback passed to perl_fuse_main " |
887 |
|
"(%s is not a string, code ref, or undef).\n", |
888 |
|
i+4,SvPVbyte_nolen(var)); |
889 |
} |
} |
890 |
} |
} |
891 |
/* FIXME: need to pass fusermount arguments */ |
/* |
892 |
fd = fuse_mount(mountpoint,NULL); |
* XXX: What comes here is just a ridiculous use of the option parsing API |
893 |
|
* to hack on compatibility with other parts of the new API. First and |
894 |
|
* foremost, real C argc/argv would be good to get at... |
895 |
|
*/ |
896 |
|
if (mountopts && |
897 |
|
(fuse_opt_add_arg(&margs, "") == -1 || |
898 |
|
fuse_opt_add_arg(&margs, "-o") == -1 || |
899 |
|
fuse_opt_add_arg(&margs, mountopts) == -1)) { |
900 |
|
fuse_opt_free_args(&margs); |
901 |
|
croak("out of memory\n"); |
902 |
|
} |
903 |
|
fd = fuse_mount(mountpoint,&margs); |
904 |
|
fuse_opt_free_args(&margs); |
905 |
if(fd < 0) |
if(fd < 0) |
906 |
croak("could not mount fuse filesystem!"); |
croak("could not mount fuse filesystem!\n"); |
907 |
fuse_loop(fuse_new(fd,debug ? "debug" : NULL,&fops)); |
if (debug) { |
908 |
|
if ( fuse_opt_add_arg(&fargs, "") == -1 || |
909 |
|
fuse_opt_add_arg(&fargs, "-d") == -1) { |
910 |
|
fuse_opt_free_args(&fargs); |
911 |
|
croak("out of memory\n"); |
912 |
|
} |
913 |
|
} else { |
914 |
|
if (fuse_opt_add_arg(&fargs, "") == -1) |
915 |
|
croak("out of memory\n"); |
916 |
|
} |
917 |
|
|
918 |
|
if(threaded) { |
919 |
|
fuse_loop_mt(fuse_new(fd,&fargs,&fops,sizeof(fops))); |
920 |
|
} else |
921 |
|
fuse_loop(fuse_new(fd,&fargs,&fops,sizeof(fops))); |
922 |
|
fuse_opt_free_args(&fargs); |