X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Fuse.xs;h=893f1a0fd83615cfa07c25115cbaac253290bfb1;hb=7f982ef01e7f172d79086ef68ddfd5591397f541;hp=7f31e93b7e46e2772e49bc878bbcfa123718ec0e;hpb=0c31abbf53ee07d05fbb98f9fd752e8251663066;p=perl-fuse.git diff --git a/Fuse.xs b/Fuse.xs index 7f31e93..893f1a0 100755 --- a/Fuse.xs +++ b/Fuse.xs @@ -5,10 +5,25 @@ #include +#if (defined(__FreeBSD__) && __FreeBSD__ < 10) || defined(__NetBSD__) +# define XATTR_CREATE 1 +# define XATTR_REPLACE 2 +#else +# include +#endif + /* 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 @@ -17,9 +32,10 @@ /* 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 40 +/* # define N_CALLBACKS 41 */ +#elif FUSE_VERSION >= 26 # define N_CALLBACKS 38 #elif FUSE_VERSION >= 25 # define N_CALLBACKS 35 @@ -32,9 +48,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; @@ -43,6 +63,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); @@ -485,8 +508,8 @@ int _PLfuse_open (const char *file, struct fuse_file_info *fi) { fi->fh = 0; /* Ensure it starts with 0 - important if they don't set it */ fihash = newHV(); #if FUSE_VERSION >= 24 - (void) hv_store(fihash, "direct_io", 9, newSViv(fi->direct_io), 0); - (void) hv_store(fihash, "keep_cache", 10, newSViv(fi->keep_cache), 0); + (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 (void) hv_store(fihash, "nonseekable", 11, newSViv(fi->nonseekable), 0); @@ -511,13 +534,13 @@ int _PLfuse_open (const char *file, struct fuse_file_info *fi) { /* Success, so copy the file handle which they returned */ #if FUSE_VERSION >= 24 SV **svp; - if ((svp = hv_fetch(fihash, "direct_io", 9, 0))) + if ((svp = hv_fetch(fihash, "direct_io", 9, 0)) != NULL) fi->direct_io = SvIV(*svp); - if ((svp = hv_fetch(fihash, "keep_cache", 10, 0))) + if ((svp = hv_fetch(fihash, "keep_cache", 10, 0)) != NULL) fi->keep_cache = SvIV(*svp); #endif #if FUSE_VERSION >= 29 - if ((svp = hv_fetch(fihash, "nonseekable", 11, 0))) + if ((svp = hv_fetch(fihash, "nonseekable", 11, 0)) != NULL) fi->nonseekable = SvIV(*svp); #endif } @@ -726,7 +749,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"); @@ -749,7 +776,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"); @@ -892,7 +923,7 @@ int _PLfuse_opendir(const char *file, struct fuse_file_info *fi) { SPAGAIN; if (rv) { if (rv > 1) { - FH_STOREHANDLE(fi, POPs); + FH_STOREHANDLE(fi, POPs); } rv = POPi; } else @@ -1136,10 +1167,8 @@ int _PLfuse_create(const char *file, mode_t mode, struct fuse_file_info *fi) { * which we can look at or modify. */ fihash = newHV(); -#if FUSE_VERSION >= 24 - (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 + (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 (void) hv_store(fihash, "nonseekable", 11, newSViv(fi->nonseekable), 0); #endif @@ -1161,18 +1190,13 @@ int _PLfuse_create(const char *file, mode_t mode, struct fuse_file_info *fi) { } if (rv == 0) { /* Success, so copy the file handle which they returned */ -#if FUSE_VERSION >= 24 SV **svp; - svp = hv_fetch(fihash, "direct_io", 9, 0); - if (svp != NULL) - fi->direct_io = SvIV(*svp); - svp = hv_fetch(fihash, "keep_cache", 10, 0); - if (svp != NULL) - fi->keep_cache = SvIV(*svp); -#endif + if ((svp = hv_fetch(fihash, "direct_io", 9, 0)) != NULL) + fi->direct_io = SvIV(*svp); + if ((svp = hv_fetch(fihash, "keep_cache", 10, 0)) != NULL) + fi->keep_cache = SvIV(*svp); #if FUSE_VERSION >= 29 - svp = hv_fetch(fihash, "nonseekable", 11, 0); - if (svp != NULL) + if ((svp = hv_fetch(fihash, "nonseekable", 11, 0)) != NULL) fi->nonseekable = SvIV(*svp); #endif } @@ -1313,15 +1337,15 @@ int _PLfuse_lock(const char *file, struct fuse_file_info *fi, int cmd, /* Need to copy back any altered values from the hash into * the struct... */ SV **svp; - if ((svp = hv_fetch(lihash, "l_type", 6, 0))) + if ((svp = hv_fetch(lihash, "l_type", 6, 0)) != NULL) lockinfo->l_type = SvIV(*svp); - if ((svp = hv_fetch(lihash, "l_whence", 8, 0))) + if ((svp = hv_fetch(lihash, "l_whence", 8, 0)) != NULL) lockinfo->l_whence = SvIV(*svp); - if ((svp = hv_fetch(lihash, "l_start", 7, 0))) + if ((svp = hv_fetch(lihash, "l_start", 7, 0)) != NULL) lockinfo->l_start = SvNV(*svp); - if ((svp = hv_fetch(lihash, "l_len", 5, 0))) + if ((svp = hv_fetch(lihash, "l_len", 5, 0)) != NULL) lockinfo->l_len = SvNV(*svp); - if ((svp = hv_fetch(lihash, "l_pid", 5, 0))) + if ((svp = hv_fetch(lihash, "l_pid", 5, 0)) != NULL) lockinfo->l_pid = SvIV(*svp); } FREETMPS; @@ -1395,20 +1419,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); @@ -1416,11 +1443,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; @@ -1429,16 +1464,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; @@ -1447,12 +1478,13 @@ int _PLfuse_ioctl(const char *file, int cmd, void *arg, return rv; } +#if 0 int _PLfuse_poll(const char *file, struct fuse_file_info *fi, struct fuse_pollhandle *ph, unsigned *reventsp) { } -#endif /* FUSE_VERSION >= 28 */ #endif +#endif /* FUSE_VERSION >= 28 */ struct fuse_operations _available_ops = { getattr: _PLfuse_getattr, @@ -1499,12 +1531,12 @@ lock: _PLfuse_lock, utimens: _PLfuse_utimens, bmap: _PLfuse_bmap, #endif /* FUSE_VERSION >= 26 */ -#if 0 #if FUSE_VERSION >= 28 ioctl: _PLfuse_ioctl, +#if 0 poll: _PLfuse_poll, -#endif /* FUSE_VERSION >= 28 */ #endif +#endif /* FUSE_VERSION >= 28 */ }; MODULE = Fuse PACKAGE = Fuse @@ -1512,14 +1544,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; @@ -1535,7 +1572,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; @@ -1548,9 +1585,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() @@ -1568,7 +1606,6 @@ fuse_get_context() #if FUSE_VERSION >= 28 (void) hv_store(hash, "umask", 5, newSViv(fc->umask), 0); #endif /* FUSE_VERSION >= 28 */ - RETVAL = newRV_noinc((SV*)hash); } else { XSRETURN_UNDEF; @@ -1583,6 +1620,20 @@ fuse_version() OUTPUT: RETVAL +SV * +XATTR_CREATE() + CODE: + RETVAL = newSViv(XATTR_CREATE); + OUTPUT: + RETVAL + +SV * +XATTR_REPLACE() + CODE: + RETVAL = newSViv(XATTR_REPLACE); + OUTPUT: + RETVAL + void perl_fuse_main(...) PREINIT: @@ -1636,7 +1687,7 @@ perl_fuse_main(...) } else if(SvOK(var)) { croak("invalid callback (%i) passed to perl_fuse_main " "(%s is not a string, code ref, or undef).\n", - i+4,SvPVbyte_nolen(var)); + i+5,SvPVbyte_nolen(var)); } else { MY_CXT.callback[i] = NULL; } @@ -1646,9 +1697,12 @@ perl_fuse_main(...) * to hack on compatibility with other parts of the new API. First and * foremost, real C argc/argv would be good to get at... */ - if (mountopts && - (fuse_opt_add_arg(&args, "") == -1 || - fuse_opt_add_arg(&args, "-o") == -1 || + if ((mountopts || debug) && fuse_opt_add_arg(&args, "") == -1) { + fuse_opt_free_args(&args); + croak("out of memory\n"); + } + if (mountopts && strcmp("", mountopts) && + (fuse_opt_add_arg(&args, "-o") == -1 || fuse_opt_add_arg(&args, mountopts) == -1)) { fuse_opt_free_args(&args); croak("out of memory\n");