/[fuse.before_github]/perl-llin/Fuse.xs
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /perl-llin/Fuse.xs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

perl/trunk/Fuse.xs revision 8 by dpavlin, Fri Nov 26 20:38:56 2004 UTC perl-llin/Fuse.xs revision 85 by dpavlin, Tue Jan 17 17:00:12 2006 UTC
# Line 2  Line 2 
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
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);
# Line 50  int _PLfuse_getattr(const char *file, st Line 78  int _PLfuse_getattr(const char *file, st
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);
# Line 82  int _PLfuse_readlink(const char *file,ch Line 114  int _PLfuse_readlink(const char *file,ch
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    #if 0
123    /*
124     * This doesn't yet work... we alwas get ENOSYS when trying to use readdir().
125     * Well, of course, getdir() is fine as well.
126     */
127     int _PLfuse_readdir(const char *file, void *dirh, fuse_fill_dir_t dirfil, off_t off, struct fuse_file_info *fi) {
128    #endif
129  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) {
130          int prv, rv;          int prv, rv;
131            FUSE_CONTEXT_PRE;
132          dSP;          dSP;
133            DEBUGf("getdir begin\n");
134          ENTER;          ENTER;
135          SAVETMPS;          SAVETMPS;
136          PUSHMARK(SP);          PUSHMARK(SP);
# Line 106  int _PLfuse_getdir(const char *file, fus Line 149  int _PLfuse_getdir(const char *file, fus
149          FREETMPS;          FREETMPS;
150          LEAVE;          LEAVE;
151          PUTBACK;          PUTBACK;
152            DEBUGf("getdir end: %i\n",rv);
153            FUSE_CONTEXT_POST;
154          return rv;          return rv;
155  }  }
156    
# Line 113  int _PLfuse_mknod (const char *file, mod Line 158  int _PLfuse_mknod (const char *file, mod
158          int rv;          int rv;
159          SV *rvsv;          SV *rvsv;
160          char *rvstr;          char *rvstr;
161            FUSE_CONTEXT_PRE;
162          dSP;          dSP;
163            DEBUGf("mknod begin\n");
164          ENTER;          ENTER;
165          SAVETMPS;          SAVETMPS;
166          PUSHMARK(SP);          PUSHMARK(SP);
# Line 130  int _PLfuse_mknod (const char *file, mod Line 177  int _PLfuse_mknod (const char *file, mod
177          FREETMPS;          FREETMPS;
178          LEAVE;          LEAVE;
179          PUTBACK;          PUTBACK;
180            DEBUGf("mknod end: %i\n",rv);
181            FUSE_CONTEXT_POST;
182          return rv;          return rv;
183  }  }
184    
# Line 137  int _PLfuse_mkdir (const char *file, mod Line 186  int _PLfuse_mkdir (const char *file, mod
186          int rv;          int rv;
187          SV *rvsv;          SV *rvsv;
188          char *rvstr;          char *rvstr;
189            FUSE_CONTEXT_PRE;
190          dSP;          dSP;
191          DEBUGf("mkdir begin: %i\n",sp-PL_stack_base);          DEBUGf("mkdir begin\n");
192          ENTER;          ENTER;
193          SAVETMPS;          SAVETMPS;
194          PUSHMARK(SP);          PUSHMARK(SP);
# Line 154  int _PLfuse_mkdir (const char *file, mod Line 204  int _PLfuse_mkdir (const char *file, mod
204          FREETMPS;          FREETMPS;
205          LEAVE;          LEAVE;
206          PUTBACK;          PUTBACK;
207          DEBUGf("mkdir end: %i %i\n",sp-PL_stack_base,rv);          DEBUGf("mkdir end: %i\n",rv);
208            FUSE_CONTEXT_POST;
209          return rv;          return rv;
210  }  }
211    
# Line 163  int _PLfuse_unlink (const char *file) { Line 214  int _PLfuse_unlink (const char *file) {
214          int rv;          int rv;
215          SV *rvsv;          SV *rvsv;
216          char *rvstr;          char *rvstr;
217            FUSE_CONTEXT_PRE;
218          dSP;          dSP;
219          DEBUGf("unlink begin: %i\n",sp-PL_stack_base);          DEBUGf("unlink begin\n");
220          ENTER;          ENTER;
221          SAVETMPS;          SAVETMPS;
222          PUSHMARK(SP);          PUSHMARK(SP);
# Line 179  int _PLfuse_unlink (const char *file) { Line 231  int _PLfuse_unlink (const char *file) {
231          FREETMPS;          FREETMPS;
232          LEAVE;          LEAVE;
233          PUTBACK;          PUTBACK;
234          DEBUGf("unlink end: %i\n",sp-PL_stack_base);          DEBUGf("unlink end: %i\n",rv);
235            FUSE_CONTEXT_POST;
236          return rv;          return rv;
237  }  }
238    
# Line 187  int _PLfuse_rmdir (const char *file) { Line 240  int _PLfuse_rmdir (const char *file) {
240          int rv;          int rv;
241          SV *rvsv;          SV *rvsv;
242          char *rvstr;          char *rvstr;
243            FUSE_CONTEXT_PRE;
244          dSP;          dSP;
245          DEBUGf("rmdir begin: %i\n",sp-PL_stack_base);          DEBUGf("rmdir begin\n");
246          ENTER;          ENTER;
247          SAVETMPS;          SAVETMPS;
248          PUSHMARK(SP);          PUSHMARK(SP);
# Line 203  int _PLfuse_rmdir (const char *file) { Line 257  int _PLfuse_rmdir (const char *file) {
257          FREETMPS;          FREETMPS;
258          LEAVE;          LEAVE;
259          PUTBACK;          PUTBACK;
260          DEBUGf("rmdir end: %i %i\n",sp-PL_stack_base,rv);          DEBUGf("rmdir end: %i\n",rv);
261            FUSE_CONTEXT_POST;
262          return rv;          return rv;
263  }  }
264    
# Line 211  int _PLfuse_symlink (const char *file, c Line 266  int _PLfuse_symlink (const char *file, c
266          int rv;          int rv;
267          SV *rvsv;          SV *rvsv;
268          char *rvstr;          char *rvstr;
269            FUSE_CONTEXT_PRE;
270          dSP;          dSP;
271          DEBUGf("symlink begin: %i\n",sp-PL_stack_base);          DEBUGf("symlink begin\n");
272          ENTER;          ENTER;
273          SAVETMPS;          SAVETMPS;
274          PUSHMARK(SP);          PUSHMARK(SP);
# Line 228  int _PLfuse_symlink (const char *file, c Line 284  int _PLfuse_symlink (const char *file, c
284          FREETMPS;          FREETMPS;
285          LEAVE;          LEAVE;
286          PUTBACK;          PUTBACK;
287          DEBUGf("symlink end: %i\n",sp-PL_stack_base);          DEBUGf("symlink end: %i\n",rv);
288            FUSE_CONTEXT_POST;
289          return rv;          return rv;
290  }  }
291    
# Line 236  int _PLfuse_rename (const char *file, co Line 293  int _PLfuse_rename (const char *file, co
293          int rv;          int rv;
294          SV *rvsv;          SV *rvsv;
295          char *rvstr;          char *rvstr;
296            FUSE_CONTEXT_PRE;
297          dSP;          dSP;
298          DEBUGf("rename begin: %i\n",sp-PL_stack_base);          DEBUGf("rename begin\n");
299          ENTER;          ENTER;
300          SAVETMPS;          SAVETMPS;
301          PUSHMARK(SP);          PUSHMARK(SP);
# Line 253  int _PLfuse_rename (const char *file, co Line 311  int _PLfuse_rename (const char *file, co
311          FREETMPS;          FREETMPS;
312          LEAVE;          LEAVE;
313          PUTBACK;          PUTBACK;
314          DEBUGf("rename end: %i\n",sp-PL_stack_base);          DEBUGf("rename end: %i\n",rv);
315            FUSE_CONTEXT_POST;
316          return rv;          return rv;
317  }  }
318    
# Line 261  int _PLfuse_link (const char *file, cons Line 320  int _PLfuse_link (const char *file, cons
320          int rv;          int rv;
321          SV *rvsv;          SV *rvsv;
322          char *rvstr;          char *rvstr;
323            FUSE_CONTEXT_PRE;
324          dSP;          dSP;
325          DEBUGf("link begin: %i\n",sp-PL_stack_base);          DEBUGf("link begin\n");
326          ENTER;          ENTER;
327          SAVETMPS;          SAVETMPS;
328          PUSHMARK(SP);          PUSHMARK(SP);
# Line 278  int _PLfuse_link (const char *file, cons Line 338  int _PLfuse_link (const char *file, cons
338          FREETMPS;          FREETMPS;
339          LEAVE;          LEAVE;
340          PUTBACK;          PUTBACK;
341          DEBUGf("link end: %i\n",sp-PL_stack_base);          DEBUGf("link end: %i\n",rv);
342            FUSE_CONTEXT_POST;
343          return rv;          return rv;
344  }  }
345    
# Line 286  int _PLfuse_chmod (const char *file, mod Line 347  int _PLfuse_chmod (const char *file, mod
347          int rv;          int rv;
348          SV *rvsv;          SV *rvsv;
349          char *rvstr;          char *rvstr;
350            FUSE_CONTEXT_PRE;
351          dSP;          dSP;
352          DEBUGf("chmod begin: %i\n",sp-PL_stack_base);          DEBUGf("chmod begin\n");
353          ENTER;          ENTER;
354          SAVETMPS;          SAVETMPS;
355          PUSHMARK(SP);          PUSHMARK(SP);
# Line 303  int _PLfuse_chmod (const char *file, mod Line 365  int _PLfuse_chmod (const char *file, mod
365          FREETMPS;          FREETMPS;
366          LEAVE;          LEAVE;
367          PUTBACK;          PUTBACK;
368          DEBUGf("chmod end: %i\n",sp-PL_stack_base);          DEBUGf("chmod end: %i\n",rv);
369            FUSE_CONTEXT_POST;
370          return rv;          return rv;
371  }  }
372    
# Line 311  int _PLfuse_chown (const char *file, uid Line 374  int _PLfuse_chown (const char *file, uid
374          int rv;          int rv;
375          SV *rvsv;          SV *rvsv;
376          char *rvstr;          char *rvstr;
377            FUSE_CONTEXT_PRE;
378          dSP;          dSP;
379          DEBUGf("chown begin: %i\n",sp-PL_stack_base);          DEBUGf("chown begin\n");
380          ENTER;          ENTER;
381          SAVETMPS;          SAVETMPS;
382          PUSHMARK(SP);          PUSHMARK(SP);
# Line 329  int _PLfuse_chown (const char *file, uid Line 393  int _PLfuse_chown (const char *file, uid
393          FREETMPS;          FREETMPS;
394          LEAVE;          LEAVE;
395          PUTBACK;          PUTBACK;
396          DEBUGf("chown end: %i\n",sp-PL_stack_base);          DEBUGf("chown end: %i\n",rv);
397            FUSE_CONTEXT_POST;
398          return rv;          return rv;
399  }  }
400    
# Line 337  int _PLfuse_truncate (const char *file, Line 402  int _PLfuse_truncate (const char *file,
402          int rv;          int rv;
403          SV *rvsv;          SV *rvsv;
404          char *rvstr;          char *rvstr;
405            FUSE_CONTEXT_PRE;
406          dSP;          dSP;
407          DEBUGf("truncate begin: %i\n",sp-PL_stack_base);          DEBUGf("truncate begin\n");
408          ENTER;          ENTER;
409          SAVETMPS;          SAVETMPS;
410          PUSHMARK(SP);          PUSHMARK(SP);
# Line 354  int _PLfuse_truncate (const char *file, Line 420  int _PLfuse_truncate (const char *file,
420          FREETMPS;          FREETMPS;
421          LEAVE;          LEAVE;
422          PUTBACK;          PUTBACK;
423          DEBUGf("truncate end: %i\n",sp-PL_stack_base);          DEBUGf("truncate end: %i\n",rv);
424            FUSE_CONTEXT_POST;
425          return rv;          return rv;
426  }  }
427    
# Line 362  int _PLfuse_utime (const char *file, str Line 429  int _PLfuse_utime (const char *file, str
429          int rv;          int rv;
430          SV *rvsv;          SV *rvsv;
431          char *rvstr;          char *rvstr;
432            FUSE_CONTEXT_PRE;
433          dSP;          dSP;
434          DEBUGf("utime begin: %i\n",sp-PL_stack_base);          DEBUGf("utime begin\n");
435          ENTER;          ENTER;
436          SAVETMPS;          SAVETMPS;
437          PUSHMARK(SP);          PUSHMARK(SP);
# Line 380  int _PLfuse_utime (const char *file, str Line 448  int _PLfuse_utime (const char *file, str
448          FREETMPS;          FREETMPS;
449          LEAVE;          LEAVE;
450          PUTBACK;          PUTBACK;
451          DEBUGf("utime end: %i\n",sp-PL_stack_base);          DEBUGf("utime end: %i\n",rv);
452            FUSE_CONTEXT_POST;
453          return rv;          return rv;
454  }  }
455    
456  int _PLfuse_open (const char *file, int flags) {  int _PLfuse_open (const char *file, struct fuse_file_info *fi) {
457          int rv;          int rv;
458          SV *rvsv;          SV *rvsv;
459          char *rvstr;          char *rvstr;
460            int flags = fi->flags;
461            FUSE_CONTEXT_PRE;
462          dSP;          dSP;
463          DEBUGf("open begin: %i\n",sp-PL_stack_base);          DEBUGf("open begin\n");
464          ENTER;          ENTER;
465          SAVETMPS;          SAVETMPS;
466          PUSHMARK(SP);          PUSHMARK(SP);
# Line 405  int _PLfuse_open (const char *file, int Line 476  int _PLfuse_open (const char *file, int
476          FREETMPS;          FREETMPS;
477          LEAVE;          LEAVE;
478          PUTBACK;          PUTBACK;
479          DEBUGf("open end: %i %i\n",sp-PL_stack_base,rv);          DEBUGf("open end: %i\n",rv);
480            FUSE_CONTEXT_POST;
481          return rv;          return rv;
482  }  }
483    
484  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) {
485          int rv;          int rv;
486          char *rvstr;          char *rvstr;
487            FUSE_CONTEXT_PRE;
488          dSP;          dSP;
489          DEBUGf("read begin: %i\n",sp-PL_stack_base);          DEBUGf("read begin\n");
490          ENTER;          ENTER;
491          SAVETMPS;          SAVETMPS;
492          PUSHMARK(SP);          PUSHMARK(SP);
# Line 444  int _PLfuse_read (const char *file, char Line 517  int _PLfuse_read (const char *file, char
517          FREETMPS;          FREETMPS;
518          LEAVE;          LEAVE;
519          PUTBACK;          PUTBACK;
520          DEBUGf("read end: %i %i\n",sp-PL_stack_base,rv);          DEBUGf("read end: %i\n",rv);
521            FUSE_CONTEXT_POST;
522          return rv;          return rv;
523  }  }
524    
525  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) {
526          int rv;          int rv;
527          char *rvstr;          char *rvstr;
528            FUSE_CONTEXT_PRE;
529          dSP;          dSP;
530          DEBUGf("write begin: %i\n",sp-PL_stack_base);          DEBUGf("write begin\n");
531          ENTER;          ENTER;
532          SAVETMPS;          SAVETMPS;
533          PUSHMARK(SP);          PUSHMARK(SP);
# Line 469  int _PLfuse_write (const char *file, con Line 544  int _PLfuse_write (const char *file, con
544          FREETMPS;          FREETMPS;
545          LEAVE;          LEAVE;
546          PUTBACK;          PUTBACK;
547          DEBUGf("write end: %i\n",sp-PL_stack_base);          DEBUGf("write end: %i\n",rv);
548            FUSE_CONTEXT_POST;
549          return rv;          return rv;
550  }  }
551    
552  int _PLfuse_statfs (const char *file, struct statfs *st) {  int _PLfuse_statfs (const char *file, struct statvfs *st) {
553          int rv;          int rv;
554          char *rvstr;          char *rvstr;
555            FUSE_CONTEXT_PRE;
556          dSP;          dSP;
557          DEBUGf("statfs begin: %i\n",sp-PL_stack_base);          DEBUGf("statfs begin\n");
558          ENTER;          ENTER;
559          SAVETMPS;          SAVETMPS;
560          PUSHMARK(SP);          PUSHMARK(SP);
561          PUTBACK;          PUTBACK;
562          rv = call_sv(_PLfuse_callbacks[17],G_ARRAY);          rv = call_sv(_PLfuse_callbacks[17],G_ARRAY);
563          SPAGAIN;          SPAGAIN;
564          if(rv > 5) {          DEBUGf("statfs got %i params\n",rv);
565                  st->f_bsize    = POPi;          if(rv == 6 || rv == 7) {
566                  st->f_bfree    = POPi;                  st->f_bsize     = POPi;
567                  st->f_blocks   = POPi;                  st->f_bfree     = POPi;
568                  st->f_ffree    = POPi;                  st->f_blocks    = POPi;
569                  st->f_files    = POPi;                  st->f_ffree     = POPi;
570                  st->f_namelen  = POPi;                  st->f_files     = POPi;
571                  if(rv > 6)                  st->f_namemax   = POPi;
572                    /* zero and fill-in other */
573                    st->f_fsid = 0;
574                    st->f_frsize = 4096;
575                    st->f_flag = 0;
576                    st->f_bavail = st->f_bfree;
577                    st->f_favail = st->f_ffree;
578    
579                    if(rv == 7)
580                          rv = POPi;                          rv = POPi;
581                  else                  else
582                          rv = 0;                          rv = 0;
# Line 506  int _PLfuse_statfs (const char *file, st Line 591  int _PLfuse_statfs (const char *file, st
591          FREETMPS;          FREETMPS;
592          LEAVE;          LEAVE;
593          PUTBACK;          PUTBACK;
594          DEBUGf("statfs end: %i\n",sp-PL_stack_base);          DEBUGf("statfs end: %i\n",rv);
595            FUSE_CONTEXT_POST;
596            return rv;
597    }
598    
599    int _PLfuse_flush (const char *file, struct fuse_file_info *fi) {
600            int rv;
601            char *rvstr;
602            FUSE_CONTEXT_PRE;
603            dSP;
604            DEBUGf("flush begin\n");
605            ENTER;
606            SAVETMPS;
607            PUSHMARK(SP);
608            XPUSHs(sv_2mortal(newSVpv(file,0)));
609            PUTBACK;
610            rv = call_sv(_PLfuse_callbacks[18],G_SCALAR);
611            SPAGAIN;
612            if(rv)
613                    rv = POPi;
614            else
615                    rv = 0;
616            FREETMPS;
617            LEAVE;
618            PUTBACK;
619            DEBUGf("flush end: %i\n",rv);
620            FUSE_CONTEXT_POST;
621            return rv;
622    }
623    
624    int _PLfuse_release (const char *file, struct fuse_file_info *fi) {
625            int rv;
626            char *rvstr;
627            int flags = fi->flags;
628            FUSE_CONTEXT_PRE;
629            dSP;
630            DEBUGf("release begin\n");
631            ENTER;
632            SAVETMPS;
633            PUSHMARK(SP);
634            XPUSHs(sv_2mortal(newSVpv(file,0)));
635            XPUSHs(sv_2mortal(newSViv(flags)));
636            PUTBACK;
637            rv = call_sv(_PLfuse_callbacks[19],G_SCALAR);
638            SPAGAIN;
639            if(rv)
640                    rv = POPi;
641            else
642                    rv = 0;
643            FREETMPS;
644            LEAVE;
645            PUTBACK;
646            DEBUGf("release end: %i\n",rv);
647            FUSE_CONTEXT_POST;
648            return rv;
649    }
650    
651    int _PLfuse_fsync (const char *file, int datasync, struct fuse_file_info *fi) {
652            int rv;
653            char *rvstr;
654            int flags = fi->flags;
655            FUSE_CONTEXT_PRE;
656            dSP;
657            DEBUGf("fsync begin\n");
658            ENTER;
659            SAVETMPS;
660            PUSHMARK(SP);
661            XPUSHs(sv_2mortal(newSVpv(file,0)));
662            XPUSHs(sv_2mortal(newSViv(flags)));
663            PUTBACK;
664            rv = call_sv(_PLfuse_callbacks[20],G_SCALAR);
665            SPAGAIN;
666            if(rv)
667                    rv = POPi;
668            else
669                    rv = 0;
670            FREETMPS;
671            LEAVE;
672            PUTBACK;
673            DEBUGf("fsync end: %i\n",rv);
674            FUSE_CONTEXT_POST;
675            return rv;
676    }
677    
678    int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) {
679            int rv;
680            char *rvstr;
681            FUSE_CONTEXT_PRE;
682            dSP;
683            DEBUGf("setxattr begin\n");
684            ENTER;
685            SAVETMPS;
686            PUSHMARK(SP);
687            XPUSHs(sv_2mortal(newSVpv(file,0)));
688            XPUSHs(sv_2mortal(newSVpv(name,0)));
689            XPUSHs(sv_2mortal(newSVpvn(buf,buflen)));
690            XPUSHs(sv_2mortal(newSViv(flags)));
691            PUTBACK;
692            rv = call_sv(_PLfuse_callbacks[21],G_SCALAR);
693            SPAGAIN;
694            if(rv)
695                    rv = POPi;
696            else
697                    rv = 0;
698            FREETMPS;
699            LEAVE;
700            PUTBACK;
701            DEBUGf("setxattr end: %i\n",rv);
702            FUSE_CONTEXT_POST;
703            return rv;
704    }
705    
706    int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) {
707            int rv;
708            char *rvstr;
709            FUSE_CONTEXT_PRE;
710            dSP;
711            DEBUGf("getxattr begin\n");
712            ENTER;
713            SAVETMPS;
714            PUSHMARK(SP);
715            XPUSHs(sv_2mortal(newSVpv(file,0)));
716            XPUSHs(sv_2mortal(newSVpv(name,0)));
717            PUTBACK;
718            rv = call_sv(_PLfuse_callbacks[22],G_SCALAR);
719            SPAGAIN;
720            if(!rv)
721                    rv = -ENOENT;
722            else {
723                    SV *mysv = POPs;
724    
725                    rv = 0;
726                    if(SvTYPE(mysv) == SVt_NV || SvTYPE(mysv) == SVt_IV)
727                            rv = SvIV(mysv);
728                    else {
729                            if(SvPOK(mysv)) {
730                                    rv = SvCUR(mysv);
731                            } else {
732                                    rv = 0;
733                            }
734                            if ((rv > 0) && (buflen > 0))
735                            {
736                                    if(rv > buflen)
737                                            rv = -ERANGE;
738                                    else
739                                            memcpy(buf,SvPV_nolen(mysv),rv);
740                            }
741                    }
742            }
743            FREETMPS;
744            LEAVE;
745            PUTBACK;
746            DEBUGf("getxattr end: %i\n",rv);
747            FUSE_CONTEXT_POST;
748            return rv;
749    }
750    
751    int _PLfuse_listxattr (const char *file, char *list, size_t size) {
752            int prv, rv;
753            char *rvstr;
754            FUSE_CONTEXT_PRE;
755            dSP;
756            DEBUGf("listxattr begin\n");
757            ENTER;
758            SAVETMPS;
759            PUSHMARK(SP);
760            XPUSHs(sv_2mortal(newSVpv(file,0)));
761            PUTBACK;
762            prv = call_sv(_PLfuse_callbacks[23],G_ARRAY);
763            SPAGAIN;
764            if(!prv)
765                    rv = -ENOENT;
766            else {
767    
768                    char *p = list;
769                    int spc = size;
770                    int total_len = 0;
771                    int i;
772    
773                    rv = POPi;
774                    prv--;
775    
776                    /* Always nul terminate */
777                    if (list && (size > 0))
778                            list[0] = '\0';
779    
780                    while (prv > 0)
781                    {
782                            SV *mysv = POPs;
783                            prv--;
784    
785                            if (SvPOK(mysv)) {
786                                    /* Copy nul too */
787                                    int s = SvCUR(mysv) + 1;
788                                    total_len += s;
789    
790                                    if (p && (size > 0) && (spc >= s))
791                                    {
792                                            memcpy(p,SvPV_nolen(mysv),s);
793                                            p += s;
794                                            spc -= s;
795                                    }
796                            }
797                    }
798    
799                    /*
800                     * If the Perl returned an error, return that.
801                     * Otherwise check that the buffer was big enough.
802                     */
803                    if (rv == 0)
804                    {
805                            rv = total_len;
806                            if ((size > 0) && (size < total_len))
807                                    rv = -ERANGE;
808                    }
809            }
810            FREETMPS;
811            LEAVE;
812            PUTBACK;
813            DEBUGf("listxattr end: %i\n",rv);
814            FUSE_CONTEXT_POST;
815            return rv;
816    }
817    
818    int _PLfuse_removexattr (const char *file, const char *name) {
819            int rv;
820            char *rvstr;
821            FUSE_CONTEXT_PRE;
822            dSP;
823            DEBUGf("removexattr begin\n");
824            ENTER;
825            SAVETMPS;
826            PUSHMARK(SP);
827            XPUSHs(sv_2mortal(newSVpv(file,0)));
828            XPUSHs(sv_2mortal(newSVpv(name,0)));
829            PUTBACK;
830            rv = call_sv(_PLfuse_callbacks[24],G_SCALAR);
831            SPAGAIN;
832            if(rv)
833                    rv = POPi;
834            else
835                    rv = 0;
836            FREETMPS;
837            LEAVE;
838            PUTBACK;
839            DEBUGf("removexattr end: %i\n",rv);
840            FUSE_CONTEXT_POST;
841          return rv;          return rv;
842  }  }
843    
844  struct fuse_operations _available_ops = {  struct fuse_operations _available_ops = {
845  getattr:        _PLfuse_getattr,  getattr:                _PLfuse_getattr,
846                          _PLfuse_readlink,  readlink:               _PLfuse_readlink,
847                          _PLfuse_getdir,  getdir:                 _PLfuse_getdir,
848                          _PLfuse_mknod,  #if 0
849                          _PLfuse_mkdir,  readdir:                _PLfuse_readdir,
850                          _PLfuse_unlink,  #endif
851                          _PLfuse_rmdir,  mknod:                  _PLfuse_mknod,
852                          _PLfuse_symlink,  mkdir:                  _PLfuse_mkdir,
853                          _PLfuse_rename,  unlink:                 _PLfuse_unlink,
854                          _PLfuse_link,  rmdir:                  _PLfuse_rmdir,
855                          _PLfuse_chmod,  symlink:                _PLfuse_symlink,
856                          _PLfuse_chown,  rename:                 _PLfuse_rename,
857                          _PLfuse_truncate,  link:                   _PLfuse_link,
858                          _PLfuse_utime,  chmod:                  _PLfuse_chmod,
859                          _PLfuse_open,  chown:                  _PLfuse_chown,
860                          _PLfuse_read,  truncate:               _PLfuse_truncate,
861                          _PLfuse_write,  utime:                  _PLfuse_utime,
862                          _PLfuse_statfs  open:                   _PLfuse_open,
863    read:                   _PLfuse_read,
864    write:                  _PLfuse_write,
865    statfs:                 _PLfuse_statfs,
866    flush:                  _PLfuse_flush,
867    release:                _PLfuse_release,
868    fsync:                  _PLfuse_fsync,
869    setxattr:               _PLfuse_setxattr,
870    getxattr:               _PLfuse_getxattr,
871    listxattr:              _PLfuse_listxattr,
872    removexattr:            _PLfuse_removexattr,
873  };  };
874    
875  MODULE = Fuse           PACKAGE = Fuse  MODULE = Fuse           PACKAGE = Fuse
# Line 537  PROTOTYPES: DISABLE Line 878  PROTOTYPES: DISABLE
878  void  void
879  perl_fuse_main(...)  perl_fuse_main(...)
880          PREINIT:          PREINIT:
881          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 =
882          int i, fd, varnum = 0, debug, have_mnt;                  {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
883                     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
884            int i, fd, varnum = 0, debug, threaded, have_mnt;
885          char *mountpoint;          char *mountpoint;
886            char *mountopts;
887            struct fuse_args margs = FUSE_ARGS_INIT(0, NULL);
888            struct fuse_args fargs = FUSE_ARGS_INIT(0, NULL);
889          STRLEN n_a;          STRLEN n_a;
890          STRLEN l;          STRLEN l;
891          INIT:          INIT:
892          if(items != 20) {          if(items != 29) {
893                  fprintf(stderr,"Perl<->C inconsistency or internal error\n");                  fprintf(stderr,"Perl<->C inconsistency or internal error\n");
894                  XSRETURN_UNDEF;                  XSRETURN_UNDEF;
895          }          }
896          CODE:          CODE:
897          debug = SvIV(ST(0));          debug = SvIV(ST(0));
898          mountpoint = SvPV_nolen(ST(1));          threaded = SvIV(ST(1));
899          /* FIXME: reevaluate multithreading support when perl6 arrives */          if(threaded) {
900          for(i=0;i<18;i++) {  #ifdef FUSE_USE_ITHREADS
901                  SV *var = ST(i+2);                  master_interp = PERL_GET_INTERP;
902                  if((var != &PL_sv_undef) && SvROK(var)) {  #else
903                          if(SvTYPE(SvRV(var)) == SVt_PVCV) {                  fprintf(stderr,"FUSE warning: Your script has requested multithreaded "
904                                  void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops;                                 "mode, but your perl was not built with -Dusethreads.  "
905                                  tmp2[i] = tmp1[i];                                 "Threads are disabled.\n");
906                                  _PLfuse_callbacks[i] = var;                  threaded = 0;
907                          } else  #endif
908                                  croak("arg is not a code reference!");          }
909            mountpoint = SvPV_nolen(ST(2));
910            mountopts = SvPV_nolen(ST(3));
911            for(i=0;i<N_CALLBACKS;i++) {
912                    SV *var = ST(i+4);
913                    /* allow symbolic references, or real code references. */
914                    if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) {
915                            void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops;
916                            tmp2[i] = tmp1[i];
917    #ifdef FUSE_USE_ITHREADS
918                            if(threaded)
919                    /* note: under 5.8.7, this croaks for code references. */
920                    SvSHARE(var);
921    #endif
922                            _PLfuse_callbacks[i] = var;
923                    } else
924                    if(SvOK(var)) {
925                            croak("invalid callback passed to perl_fuse_main "
926                                  "(%s is not a string, code ref, or undef).\n",
927                                  i+4,SvPVbyte_nolen(var));
928                  }                  }
929          }          }
930          /* FIXME: need to pass fusermount arguments */          /*
931          fd = fuse_mount(mountpoint,NULL);           * XXX: What comes here is just a ridiculous use of the option parsing API
932             * to hack on compatibility with other parts of the new API. First and
933             * foremost, real C argc/argv would be good to get at...
934             */
935            if (mountopts &&
936                (fuse_opt_add_arg(&margs, "") == -1 ||
937                 fuse_opt_add_arg(&margs, "-o") == -1 ||
938                 fuse_opt_add_arg(&margs, mountopts) == -1)) {
939                    fuse_opt_free_args(&margs);
940                    croak("out of memory\n");
941            }
942            fd = fuse_mount(mountpoint,&margs);
943            fuse_opt_free_args(&margs);        
944          if(fd < 0)          if(fd < 0)
945                  croak("could not mount fuse filesystem!");                  croak("could not mount fuse filesystem!");
946          fuse_loop(fuse_new(fd,debug ? "debug" : NULL,&fops));          if (debug &&
947                (fuse_opt_add_arg(&fargs, "") == -1 ||
948                 fuse_opt_add_arg(&fargs, "-d") == -1)) {
949                    fuse_opt_free_args(&fargs);
950                    croak("out of memory\n");
951            }
952            if(threaded) {
953                    fuse_loop_mt(fuse_new(fd,&fargs,&fops,sizeof(fops)/sizeof(void*)));
954            } else
955                    fuse_loop(fuse_new(fd,&fargs,&fops,sizeof(fops)/sizeof(void*)));
956            fuse_opt_free_args(&fargs);

Legend:
Removed from v.8  
changed lines
  Added in v.85

  ViewVC Help
Powered by ViewVC 1.1.26