X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Fuse.xs;h=639adf896b2e580bf0b143e312faed1eec9cab2c;hb=d3ec2fb34879325afdc0c9f889bdbd7af8cac0c7;hp=01fcafbb3f460fa8ef9e95bc3c88628530cab8d3;hpb=9497c2fcd8e0940552f724f218863318217136f6;p=perl-fuse.git diff --git a/Fuse.xs b/Fuse.xs index 01fcafb..639adf8 100755 --- a/Fuse.xs +++ b/Fuse.xs @@ -3,23 +3,27 @@ #include "perl.h" #include "XSUB.h" -/* - * XXX: Fuse on FreeBSD does not support extended attributes (see - * /usr/local/share/doc/fusefs/kmod/doc.text). Also, 'extattr_set_file' syscall - * declared in 'sys/extattr.h' does not accept any flags. We could either skip - * defining XATTR_CREATE and XATTR_REPLACE constants (as further below, and - * which breaks their usage if Perl module exports them), set them to some - * dummy values, or not allow them to be exported at all on FreeBSD. - */ -#ifndef __FreeBSD__ +#include + +#if (defined(__FreeBSD__) && __FreeBSD__ < 10) || defined(__NetBSD__) +# define XATTR_CREATE 1 +# define XATTR_REPLACE 2 +#else # include #endif -#include /* Determine if threads support should be included */ #ifdef USE_ITHREADS # ifdef I_PTHREAD # define FUSE_USE_ITHREADS +# if (PERL_VERSION < 8) || (PERL_VERSION == 8 && PERL_SUBVERSION < 9) +# define tTHX PerlInterpreter* +# define STR_WITH_LEN(s) ("" s ""), (sizeof(s)-1) +# define hv_fetchs(hv,key,lval) Perl_hv_fetch(aTHX_ hv, STR_WITH_LEN(key), lval) +# define dMY_CXT_INTERP(interp) \ + SV *my_cxt_sv = *hv_fetchs(interp->Imodglobal, MY_CXT_KEY, TRUE); \ + my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)) +# endif # else # warning "Sorry, I don't know how to handle ithreads on this architecture. Building non-threaded version" # endif @@ -28,9 +32,9 @@ /* Global Data */ #define MY_CXT_KEY "Fuse::_guts" XS_VERSION -/* #if FUSE_VERSION >= 28 -# define N_CALLBACKS 41 */ -#if FUSE_VERSION >= 26 +#if FUSE_VERSION >= 28 +# define N_CALLBACKS 41 +#elif FUSE_VERSION >= 26 # define N_CALLBACKS 38 #elif FUSE_VERSION >= 25 # define N_CALLBACKS 35 @@ -43,9 +47,13 @@ typedef struct { SV *callback[N_CALLBACKS]; HV *handles; +#ifdef USE_ITHREADS tTHX self; +#endif int threaded; +#ifdef USE_ITHREADS perl_mutex mutex; +#endif } my_cxt_t; START_MY_CXT; @@ -54,6 +62,9 @@ tTHX master_interp = NULL; #define CLONE_INTERP(parent) S_clone_interp(parent) tTHX S_clone_interp(tTHX parent) { +# if (PERL_VERSION < 10) + tTHX my_perl = parent; +#endif dMY_CXT_INTERP(parent); if(MY_CXT.threaded) { MUTEX_LOCK(&MY_CXT.mutex); @@ -118,8 +129,10 @@ void S_fh_store_handle(pTHX_ pMY_CXT_ struct fuse_file_info *fi, SV *sv) { SvSHARE(sv); } #endif - MAGIC *mg = (SvTYPE(sv) == SVt_PVMG) ? mg_find(sv, PERL_MAGIC_shared_scalar) : NULL; - fi->fh = mg ? PTR2IV(mg->mg_ptr) : PTR2IV(sv); + /* This seems to be screwing things up... */ + // MAGIC *mg = (SvTYPE(sv) == SVt_PVMG) ? mg_find(sv, PERL_MAGIC_shared_scalar) : NULL; + // fi->fh = mg ? PTR2IV(mg->mg_ptr) : PTR2IV(sv); + fi->fh = PTR2IV(sv); if(hv_store_ent(MY_CXT.handles, FH_KEY(fi), SvREFCNT_inc(sv), 0) == NULL) { SvREFCNT_dec(sv); } @@ -499,7 +512,7 @@ int _PLfuse_open (const char *file, struct fuse_file_info *fi) { (void) hv_store(fihash, "direct_io", 9, newSViv(fi->direct_io), 0); (void) hv_store(fihash, "keep_cache", 10, newSViv(fi->keep_cache), 0); #endif -#if FUSE_VERSION >= 29 +#if FUSE_VERSION >= 28 (void) hv_store(fihash, "nonseekable", 11, newSViv(fi->nonseekable), 0); #endif XPUSHs(sv_2mortal(newRV_noinc((SV*) fihash))); @@ -527,7 +540,7 @@ int _PLfuse_open (const char *file, struct fuse_file_info *fi) { if ((svp = hv_fetch(fihash, "keep_cache", 10, 0)) != NULL) fi->keep_cache = SvIV(*svp); #endif -#if FUSE_VERSION >= 29 +#if FUSE_VERSION >= 28 if ((svp = hv_fetch(fihash, "nonseekable", 11, 0)) != NULL) fi->nonseekable = SvIV(*svp); #endif @@ -737,7 +750,11 @@ int _PLfuse_fsync (const char *file, int datasync, struct fuse_file_info *fi) { return rv; } +#if __FreeBSD__ >= 10 +int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags, uint32_t position) { +#else int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_t buflen, int flags) { +#endif int rv; FUSE_CONTEXT_PRE; DEBUGf("setxattr begin\n"); @@ -760,7 +777,11 @@ int _PLfuse_setxattr (const char *file, const char *name, const char *buf, size_ return rv; } +#if __FreeBSD__ >= 10 +int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen, uint32_t position) { +#else int _PLfuse_getxattr (const char *file, const char *name, char *buf, size_t buflen) { +#endif int rv; FUSE_CONTEXT_PRE; DEBUGf("getxattr begin\n"); @@ -1149,7 +1170,7 @@ int _PLfuse_create(const char *file, mode_t mode, struct fuse_file_info *fi) { fihash = newHV(); (void) hv_store(fihash, "direct_io", 9, newSViv(fi->direct_io), 0); (void) hv_store(fihash, "keep_cache", 10, newSViv(fi->keep_cache), 0); -#if FUSE_VERSION >= 29 +#if FUSE_VERSION >= 28 (void) hv_store(fihash, "nonseekable", 11, newSViv(fi->nonseekable), 0); #endif XPUSHs(sv_2mortal(newRV_noinc((SV*) fihash))); @@ -1175,7 +1196,7 @@ int _PLfuse_create(const char *file, mode_t mode, struct fuse_file_info *fi) { fi->direct_io = SvIV(*svp); if ((svp = hv_fetch(fihash, "keep_cache", 10, 0)) != NULL) fi->keep_cache = SvIV(*svp); -#if FUSE_VERSION >= 29 +#if FUSE_VERSION >= 28 if ((svp = hv_fetch(fihash, "nonseekable", 11, 0)) != NULL) fi->nonseekable = SvIV(*svp); #endif @@ -1399,20 +1420,23 @@ int _PLfuse_bmap(const char *file, size_t blocksize, uint64_t *idx) { } #endif /* FUSE_VERSION >= 26 */ -#if 0 #if FUSE_VERSION >= 28 int _PLfuse_ioctl(const char *file, int cmd, void *arg, struct fuse_file_info *fi, unsigned int flags, void *data) { int rv; + SV *sv = NULL; FUSE_CONTEXT_PRE; DEBUGf("ioctl begin\n"); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpv(file,0))); - XPUSHs(sv_2mortal(newSViv(cmd))); + /* I don't know why cmd is a signed int in the first place; + * casting as unsigned so stupid tricks don't have to be done on + * the perl side */ + XPUSHs(sv_2mortal(newSViv((unsigned int)cmd))); XPUSHs(sv_2mortal(newSViv(flags))); - if (_IOC_DIR(cmd) & _IOC_READ) + if (_IOC_DIR(cmd) & _IOC_WRITE) XPUSHs(sv_2mortal(newSVpvn(data, _IOC_SIZE(cmd)))); else XPUSHs(&PL_sv_undef); @@ -1420,11 +1444,19 @@ int _PLfuse_ioctl(const char *file, int cmd, void *arg, PUTBACK; rv = call_sv(MY_CXT.callback[39],G_ARRAY); SPAGAIN; - if (_IOC_DIR(cmd) & _IOC_WRITE) { - if (rv == 2) { - SV *sv = POPs; - unsigned int len; + if ((_IOC_DIR(cmd) & _IOC_READ) && (rv == 2)) { + sv = POPs; + rv--; + } + + if (rv > 0) + rv = POPi; + + if ((_IOC_DIR(cmd) & _IOC_READ) && !rv) { + if (sv) { + size_t len; char *rdata = SvPV(sv, len); + if (len > _IOC_SIZE(cmd)) { fprintf(stderr, "ioctl(): returned data was too large for data area\n"); rv = -EFBIG; @@ -1433,16 +1465,12 @@ int _PLfuse_ioctl(const char *file, int cmd, void *arg, memset(data, 0, _IOC_SIZE(cmd)); memcpy(data, rdata, len); } - - rv--; } else { - fprintf(stderr, "ioctl(): ioctl was a write op, but no data was returned from call?\n"); + fprintf(stderr, "ioctl(): ioctl was a read op, but no data was returned from call?\n"); rv = -EFAULT; } } - if (rv > 0) - rv = POPi; FREETMPS; LEAVE; PUTBACK; @@ -1453,10 +1481,41 @@ int _PLfuse_ioctl(const char *file, int cmd, void *arg, int _PLfuse_poll(const char *file, struct fuse_file_info *fi, struct fuse_pollhandle *ph, unsigned *reventsp) { - + int rv; + SV *sv = NULL; + FUSE_CONTEXT_PRE; + DEBUGf("poll begin\n"); + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs(sv_2mortal(newSVpv(file,0))); + if (ph) { + /* Still gotta figure out how to do this right... */ + sv = newSViv(PTR2IV(ph)); + SvREADONLY_on(sv); + SvSHARE(sv); + XPUSHs(sv); + } + else + XPUSHs(&PL_sv_undef); + XPUSHs(sv_2mortal(newSViv(*reventsp))); + XPUSHs(FH_GETHANDLE(fi)); + PUTBACK; + rv = call_sv(MY_CXT.callback[40],G_ARRAY); + SPAGAIN; + if (rv > 1) { + *reventsp = POPi; + rv--; + } + rv = (rv ? POPi : 0); + FREETMPS; + LEAVE; + PUTBACK; + DEBUGf("poll end: %i\n", rv); + FUSE_CONTEXT_POST; + return rv; } #endif /* FUSE_VERSION >= 28 */ -#endif struct fuse_operations _available_ops = { getattr: _PLfuse_getattr, @@ -1503,12 +1562,10 @@ lock: _PLfuse_lock, utimens: _PLfuse_utimens, bmap: _PLfuse_bmap, #endif /* FUSE_VERSION >= 26 */ -#if 0 #if FUSE_VERSION >= 28 ioctl: _PLfuse_ioctl, poll: _PLfuse_poll, #endif /* FUSE_VERSION >= 28 */ -#endif }; MODULE = Fuse PACKAGE = Fuse @@ -1516,14 +1573,19 @@ PROTOTYPES: DISABLE BOOT: MY_CXT_INIT; +#ifdef USE_ITHREADS MY_CXT.self = aTHX; +#endif void CLONE(...) PREINIT: +#ifdef USE_ITHREADS int i; dTHX; +#endif CODE: +#ifdef USE_ITHREADS MY_CXT_CLONE; tTHX parent = MY_CXT.self; MY_CXT.self = my_perl; @@ -1539,7 +1601,7 @@ CLONE(...) { CLONE_PARAMS *clone_param; #if (PERL_VERSION > 13) || (PERL_VERSION == 13 && PERL_SUBVERSION >= 2) - clone_param = clone_params_new(parent, aTHX); + clone_param = Perl_clone_params_new(parent, aTHX); #else CLONE_PARAMS raw_param; raw_param.flags = 0; @@ -1552,9 +1614,10 @@ CLONE(...) } MY_CXT.handles = (HV*)sv_dup((SV*)MY_CXT.handles, clone_param); #if (PERL_VERSION > 13) || (PERL_VERSION == 13 && PERL_SUBVERSION >= 2) - clone_params_del(clone_param); + Perl_clone_params_del(clone_param); #endif } +#endif SV* fuse_get_context() @@ -1586,7 +1649,6 @@ fuse_version() OUTPUT: RETVAL -#ifndef __FreeBSD__ SV * XATTR_CREATE() CODE: @@ -1601,8 +1663,6 @@ XATTR_REPLACE() OUTPUT: RETVAL -#endif - void perl_fuse_main(...) PREINIT: @@ -1691,3 +1751,35 @@ perl_fuse_main(...) fuse_loop(fuse_new(fc,&args,&fops,sizeof(fops),NULL)); fuse_unmount(mountpoint,fc); fuse_opt_free_args(&args); + +#if FUSE_VERSION >= 28 + +void +pollhandle_destroy(...) + PREINIT: + struct fuse_pollhandle *ph; + INIT: + if (items != 1) { + fprintf(stderr, "No pollhandle passed?\n"); + XSRETURN_UNDEF; + } + CODE: + ph = INT2PTR(struct fuse_pollhandle*, SvIV(ST(0))); + fuse_pollhandle_destroy(ph); + +int +notify_poll(...) + PREINIT: + struct fuse_pollhandle *ph; + INIT: + if (items != 1) { + fprintf(stderr, "No pollhandle passed?\n"); + XSRETURN_UNDEF; + } + CODE: + ph = INT2PTR(struct fuse_pollhandle*, SvIV(ST(0))); + RETVAL = fuse_notify_poll(ph); + OUTPUT: + RETVAL + +#endif