/[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 9 by dpavlin, Fri Jan 7 23:38:41 2005 UTC perl-llin/Fuse.xs revision 89 by dpavlin, Tue May 23 14:45:53 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) {
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);
# Line 43  int _PLfuse_getattr(const char *file, st Line 71  int _PLfuse_getattr(const char *file, st
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);
# Line 82  int _PLfuse_readlink(const char *file,ch Line 112  int _PLfuse_readlink(const char *file,ch
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);
# Line 98  int _PLfuse_getdir(const char *file, fus Line 139  int _PLfuse_getdir(const char *file, fus
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;
# Line 106  int _PLfuse_getdir(const char *file, fus Line 147  int _PLfuse_getdir(const char *file, fus
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);
# Line 130  int _PLfuse_mknod (const char *file, mod Line 173  int _PLfuse_mknod (const char *file, mod
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);
# Line 154  int _PLfuse_mkdir (const char *file, mod Line 198  int _PLfuse_mkdir (const char *file, mod
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);
# Line 179  int _PLfuse_unlink (const char *file) { Line 223  int _PLfuse_unlink (const char *file) {
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);
# Line 203  int _PLfuse_rmdir (const char *file) { Line 247  int _PLfuse_rmdir (const char *file) {
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);
# Line 228  int _PLfuse_symlink (const char *file, c Line 272  int _PLfuse_symlink (const char *file, c
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);
# Line 253  int _PLfuse_rename (const char *file, co Line 297  int _PLfuse_rename (const char *file, co
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);
# Line 278  int _PLfuse_link (const char *file, cons Line 322  int _PLfuse_link (const char *file, cons
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);
# Line 303  int _PLfuse_chmod (const char *file, mod Line 347  int _PLfuse_chmod (const char *file, mod
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);
# Line 329  int _PLfuse_chown (const char *file, uid Line 373  int _PLfuse_chown (const char *file, uid
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);
# Line 354  int _PLfuse_truncate (const char *file, Line 398  int _PLfuse_truncate (const char *file,
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);
# Line 380  int _PLfuse_utime (const char *file, str Line 424  int _PLfuse_utime (const char *file, str
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);
# Line 405  int _PLfuse_open (const char *file, int Line 450  int _PLfuse_open (const char *file, int
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);
# Line 444  int _PLfuse_read (const char *file, char Line 490  int _PLfuse_read (const char *file, char
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);
# Line 469  int _PLfuse_write (const char *file, con Line 516  int _PLfuse_write (const char *file, con
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;
# Line 506  int _PLfuse_statfs (const char *file, st Line 562  int _PLfuse_statfs (const char *file, st
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;
568    }
569    
570    int _PLfuse_flush (const char *file, struct fuse_file_info *fi) {
571            int rv;
572            FUSE_CONTEXT_PRE;
573            dSP;
574            DEBUGf("flush begin\n");
575            ENTER;
576            SAVETMPS;
577            PUSHMARK(SP);
578            XPUSHs(sv_2mortal(newSVpv(file,0)));
579            PUTBACK;
580            rv = call_sv(_PLfuse_callbacks[18],G_SCALAR);
581            SPAGAIN;
582            if(rv)
583                    rv = POPi;
584            else
585                    rv = 0;
586            FREETMPS;
587            LEAVE;
588            PUTBACK;
589            DEBUGf("flush end: %i\n",rv);
590            FUSE_CONTEXT_POST;
591            return rv;
592    }
593    
594    int _PLfuse_release (const char *file, struct fuse_file_info *fi) {
595            int rv;
596            int flags = fi->flags;
597            FUSE_CONTEXT_PRE;
598            dSP;
599            DEBUGf("release begin\n");
600            ENTER;
601            SAVETMPS;
602            PUSHMARK(SP);
603            XPUSHs(sv_2mortal(newSVpv(file,0)));
604            XPUSHs(sv_2mortal(newSViv(flags)));
605            PUTBACK;
606            rv = call_sv(_PLfuse_callbacks[19],G_SCALAR);
607            SPAGAIN;
608            if(rv)
609                    rv = POPi;
610            else
611                    rv = 0;
612            FREETMPS;
613            LEAVE;
614            PUTBACK;
615            DEBUGf("release end: %i\n",rv);
616            FUSE_CONTEXT_POST;
617            return rv;
618    }
619    
620    int _PLfuse_fsync (const char *file, int datasync, struct fuse_file_info *fi) {
621            int rv;
622            int flags = fi->flags;
623            FUSE_CONTEXT_PRE;
624            dSP;
625            DEBUGf("fsync begin\n");
626            ENTER;
627            SAVETMPS;
628            PUSHMARK(SP);
629            XPUSHs(sv_2mortal(newSVpv(file,0)));
630            XPUSHs(sv_2mortal(newSViv(flags)));
631            PUTBACK;
632            rv = call_sv(_PLfuse_callbacks[20],G_SCALAR);
633            SPAGAIN;
634            if(rv)
635                    rv = POPi;
636            else
637                    rv = 0;
638            FREETMPS;
639            LEAVE;
640            PUTBACK;
641            DEBUGf("fsync end: %i\n",rv);
642            FUSE_CONTEXT_POST;
643            return rv;
644    }
645    
646    int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) {
647            int rv;
648            FUSE_CONTEXT_PRE;
649            dSP;
650            DEBUGf("setxattr begin\n");
651            ENTER;
652            SAVETMPS;
653            PUSHMARK(SP);
654            XPUSHs(sv_2mortal(newSVpv(file,0)));
655            XPUSHs(sv_2mortal(newSVpv(name,0)));
656            XPUSHs(sv_2mortal(newSVpvn(buf,buflen)));
657            XPUSHs(sv_2mortal(newSViv(flags)));
658            PUTBACK;
659            rv = call_sv(_PLfuse_callbacks[21],G_SCALAR);
660            SPAGAIN;
661            if(rv)
662                    rv = POPi;
663            else
664                    rv = 0;
665            FREETMPS;
666            LEAVE;
667            PUTBACK;
668            DEBUGf("setxattr end: %i\n",rv);
669            FUSE_CONTEXT_POST;
670            return rv;
671    }
672    
673    int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) {
674            int rv;
675            FUSE_CONTEXT_PRE;
676            dSP;
677            DEBUGf("getxattr begin\n");
678            ENTER;
679            SAVETMPS;
680            PUSHMARK(SP);
681            XPUSHs(sv_2mortal(newSVpv(file,0)));
682            XPUSHs(sv_2mortal(newSVpv(name,0)));
683            PUTBACK;
684            rv = call_sv(_PLfuse_callbacks[22],G_SCALAR);
685            SPAGAIN;
686            if(!rv)
687                    rv = -ENOENT;
688            else {
689                    SV *mysv = POPs;
690    
691                    rv = 0;
692                    if(SvTYPE(mysv) == SVt_NV || SvTYPE(mysv) == SVt_IV)
693                            rv = SvIV(mysv);
694                    else {
695                            if(SvPOK(mysv)) {
696                                    rv = SvCUR(mysv);
697                            } else {
698                                    rv = 0;
699                            }
700                            if ((rv > 0) && (buflen > 0))
701                            {
702                                    if(rv > buflen)
703                                            rv = -ERANGE;
704                                    else
705                                            memcpy(buf,SvPV_nolen(mysv),rv);
706                            }
707                    }
708            }
709            FREETMPS;
710            LEAVE;
711            PUTBACK;
712            DEBUGf("getxattr end: %i\n",rv);
713            FUSE_CONTEXT_POST;
714            return rv;
715    }
716    
717    int _PLfuse_listxattr (const char *file, char *list, size_t size) {
718            int prv, rv;
719            FUSE_CONTEXT_PRE;
720            dSP;
721            DEBUGf("listxattr begin\n");
722            ENTER;
723            SAVETMPS;
724            PUSHMARK(SP);
725            XPUSHs(sv_2mortal(newSVpv(file,0)));
726            PUTBACK;
727            prv = call_sv(_PLfuse_callbacks[23],G_ARRAY);
728            SPAGAIN;
729            if(!prv)
730                    rv = -ENOENT;
731            else {
732    
733                    char *p = list;
734                    int spc = size;
735                    int total_len = 0;
736    
737                    rv = POPi;
738                    prv--;
739    
740                    /* Always nul terminate */
741                    if (list && (size > 0))
742                            list[0] = '\0';
743    
744                    while (prv > 0)
745                    {
746                            SV *mysv = POPs;
747                            prv--;
748    
749                            if (SvPOK(mysv)) {
750                                    /* Copy nul too */
751                                    int s = SvCUR(mysv) + 1;
752                                    total_len += s;
753    
754                                    if (p && (size > 0) && (spc >= s))
755                                    {
756                                            memcpy(p,SvPV_nolen(mysv),s);
757                                            p += s;
758                                            spc -= s;
759                                    }
760                            }
761                    }
762    
763                    /*
764                     * If the Perl returned an error, return that.
765                     * Otherwise check that the buffer was big enough.
766                     */
767                    if (rv == 0)
768                    {
769                            rv = total_len;
770                            if ((size > 0) && (size < total_len))
771                                    rv = -ERANGE;
772                    }
773            }
774            FREETMPS;
775            LEAVE;
776            PUTBACK;
777            DEBUGf("listxattr end: %i\n",rv);
778            FUSE_CONTEXT_POST;
779            return rv;
780    }
781    
782    int _PLfuse_removexattr (const char *file, const char *name) {
783            int rv;
784            FUSE_CONTEXT_PRE;
785            dSP;
786            DEBUGf("removexattr begin\n");
787            ENTER;
788            SAVETMPS;
789            PUSHMARK(SP);
790            XPUSHs(sv_2mortal(newSVpv(file,0)));
791            XPUSHs(sv_2mortal(newSVpv(name,0)));
792            PUTBACK;
793            rv = call_sv(_PLfuse_callbacks[24],G_SCALAR);
794            SPAGAIN;
795            if(rv)
796                    rv = POPi;
797            else
798                    rv = 0;
799            FREETMPS;
800            LEAVE;
801            PUTBACK;
802            DEBUGf("removexattr end: %i\n",rv);
803            FUSE_CONTEXT_POST;
804          return rv;          return rv;
805  }  }
806    
807  struct fuse_operations _available_ops = {  struct fuse_operations _available_ops = {
808  getattr:        _PLfuse_getattr,  getattr:                _PLfuse_getattr,
809                          _PLfuse_readlink,  readlink:               _PLfuse_readlink,
810                          _PLfuse_getdir,  getdir:                 _PLfuse_getdir,
811                          _PLfuse_mknod,  #if 0
812                          _PLfuse_mkdir,  readdir:                _PLfuse_readdir,
813                          _PLfuse_unlink,  #endif
814                          _PLfuse_rmdir,  mknod:                  _PLfuse_mknod,
815                          _PLfuse_symlink,  mkdir:                  _PLfuse_mkdir,
816                          _PLfuse_rename,  unlink:                 _PLfuse_unlink,
817                          _PLfuse_link,  rmdir:                  _PLfuse_rmdir,
818                          _PLfuse_chmod,  symlink:                _PLfuse_symlink,
819                          _PLfuse_chown,  rename:                 _PLfuse_rename,
820                          _PLfuse_truncate,  link:                   _PLfuse_link,
821                          _PLfuse_utime,  chmod:                  _PLfuse_chmod,
822                          _PLfuse_open,  chown:                  _PLfuse_chown,
823                          _PLfuse_read,  truncate:               _PLfuse_truncate,
824                          _PLfuse_write,  utime:                  _PLfuse_utime,
825                          _PLfuse_statfs  open:                   _PLfuse_open,
826    read:                   _PLfuse_read,
827    write:                  _PLfuse_write,
828    statfs:                 _PLfuse_statfs,
829    flush:                  _PLfuse_flush,
830    release:                _PLfuse_release,
831    fsync:                  _PLfuse_fsync,
832    setxattr:               _PLfuse_setxattr,
833    getxattr:               _PLfuse_getxattr,
834    listxattr:              _PLfuse_listxattr,
835    removexattr:            _PLfuse_removexattr,
836  };  };
837    
838  MODULE = Fuse           PACKAGE = Fuse  MODULE = Fuse           PACKAGE = Fuse
# Line 537  PROTOTYPES: DISABLE Line 841  PROTOTYPES: DISABLE
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};          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 != 20) {          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          for(i=0;i<18;i++) {  #ifdef FUSE_USE_ITHREADS
862                  SV *var = ST(i+2);                  master_interp = PERL_GET_INTERP;
863                  if((var != &PL_sv_undef) && SvROK(var)) {  #else
864                          if(SvTYPE(SvRV(var)) == SVt_PVCV) {                  fprintf(stderr,"FUSE warning: Your script has requested multithreaded "
865                                  void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops;                                 "mode, but your perl was not built with -Dusethreads.  "
866                                  tmp2[i] = tmp1[i];                                 "Threads are disabled.\n");
867                                  _PLfuse_callbacks[i] = var;                  threaded = 0;
868                          } else  #endif
869                                  croak("arg is not a code reference!");          }
870            mountpoint = SvPV_nolen(ST(2));
871            mountopts = SvPV_nolen(ST(3));
872            for(i=0;i<N_CALLBACKS;i++) {
873                    SV *var = ST(i+4);
874                    /* allow symbolic references, or real code references. */
875                    if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) {
876                            void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops;
877                            tmp2[i] = tmp1[i];
878    #ifdef FUSE_USE_ITHREADS
879                            if(threaded)
880                    /* 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)/sizeof(void*)));
920            } else
921                    fuse_loop(fuse_new(fd,&fargs,&fops,sizeof(fops)/sizeof(void*)));
922            fuse_opt_free_args(&fargs);

Legend:
Removed from v.9  
changed lines
  Added in v.89

  ViewVC Help
Powered by ViewVC 1.1.26