X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Fuse.xs;h=814fb47736abc8f8c3b20363f15908f4ce8f1e27;hb=77b8ae12839c2799580ab9cfcaa08a3bf2c463e5;hp=26b80e070ab233ede506c20c85944938f339d44d;hpb=83a53bb0cf47e91a5935a09d94545134c1a35b65;p=perl-fuse.git diff --git a/Fuse.xs b/Fuse.xs index 26b80e0..814fb47 100755 --- a/Fuse.xs +++ b/Fuse.xs @@ -12,6 +12,38 @@ # include #endif +#if defined(__linux__) +# define STAT_NSEC(st, st_xtim) ((st)->st_xtim.tv_nsec) +#else +# define STAT_NSEC(st, st_xtim) ((st)->st_xtim##espec.tv_nsec) +#endif + +/* Implement a macro to handle multiple formats (integer, float, and array + * containing seconds and nanoseconds). */ +#define PULL_TIME(st, st_xtim, svp) \ +{ \ + SV *sv = svp; \ + if (SvROK(sv)) { \ + AV *av = (AV *)SvRV(sv); \ + if (SvTYPE((SV *)av) != SVt_PVAV) { \ + Perl_croak_nocontext("Reference was not array ref"); \ + } \ + if (av_len(av) != 1) { \ + Perl_croak_nocontext("Array of incorrect dimension"); \ + } \ + (st)->st_xtim##e = SvIV(*(av_fetch(av, 0, FALSE))); \ + STAT_NSEC(st, st_xtim) = SvIV(*(av_fetch(av, 1, FALSE))); \ + } \ + else if (SvNOK(sv) || SvIOK(sv)) { \ + double tm = SvNV(sv); \ + (st)->st_xtim##e = (int)tm; \ + STAT_NSEC(st, st_xtim) = (tm - (int)tm) * 1000000000; \ + } \ + else { \ + Perl_croak_nocontext("Invalid data type passed"); \ + } \ +} + /* Determine if threads support should be included */ #ifdef USE_ITHREADS # ifdef I_PTHREAD @@ -33,8 +65,7 @@ #define MY_CXT_KEY "Fuse::_guts" XS_VERSION #if FUSE_VERSION >= 28 -# define N_CALLBACKS 40 -/* # define N_CALLBACKS 41 */ +# define N_CALLBACKS 41 #elif FUSE_VERSION >= 26 # define N_CALLBACKS 38 #elif FUSE_VERSION >= 25 @@ -55,6 +86,7 @@ typedef struct { #ifdef USE_ITHREADS perl_mutex mutex; #endif + int utimens_as_array; } my_cxt_t; START_MY_CXT; @@ -130,8 +162,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); } @@ -161,9 +195,9 @@ int _PLfuse_getattr(const char *file, struct stat *result) { } else { result->st_blocks = POPi; result->st_blksize = POPi; - result->st_ctime = POPi; - result->st_mtime = POPi; - result->st_atime = POPi; + PULL_TIME(result, st_ctim, POPs); + PULL_TIME(result, st_mtim, POPs); + PULL_TIME(result, st_atim, POPs); result->st_size = POPn; // we pop double here to support files larger than 4Gb (long limit) result->st_rdev = POPi; result->st_gid = POPi; @@ -996,9 +1030,9 @@ int _PLfuse_readdir(const char *file, void *dirh, fuse_fill_dir_t dirfil, st.st_gid = SvIV(*(av_fetch(av2, 5, FALSE))); st.st_rdev = SvIV(*(av_fetch(av2, 6, FALSE))); st.st_size = SvNV(*(av_fetch(av2, 7, FALSE))); - st.st_atime = SvIV(*(av_fetch(av2, 8, FALSE))); - st.st_mtime = SvIV(*(av_fetch(av2, 9, FALSE))); - st.st_ctime = SvIV(*(av_fetch(av2, 10, FALSE))); + PULL_TIME(&st, st_atim, *(av_fetch(av2, 8, FALSE))); + PULL_TIME(&st, st_mtim, *(av_fetch(av2, 9, FALSE))); + PULL_TIME(&st, st_ctim, *(av_fetch(av2, 10, FALSE))); st.st_blksize = SvIV(*(av_fetch(av2, 11, FALSE))); st.st_blocks = SvIV(*(av_fetch(av2, 12, FALSE))); st_filled = 1; @@ -1264,9 +1298,9 @@ int _PLfuse_fgetattr(const char *file, struct stat *result, } else { result->st_blocks = POPi; result->st_blksize = POPi; - result->st_ctime = POPi; - result->st_mtime = POPi; - result->st_atime = POPi; + PULL_TIME(result, st_ctim, POPs); + PULL_TIME(result, st_mtim, POPs); + PULL_TIME(result, st_atim, POPs); result->st_size = POPn; // we pop double here to support files larger than 4Gb (long limit) result->st_rdev = POPi; result->st_gid = POPi; @@ -1364,8 +1398,30 @@ int _PLfuse_utimens(const char *file, const struct timespec tv[2]) { SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVpv(file,0))); - XPUSHs(tv ? sv_2mortal(newSVnv(tv[0].tv_sec + (tv[0].tv_nsec / 1000000000.0))) : &PL_sv_undef); - XPUSHs(tv ? sv_2mortal(newSVnv(tv[1].tv_sec + (tv[1].tv_nsec / 1000000000.0))) : &PL_sv_undef); + if (MY_CXT.utimens_as_array) { + /* Pushing timespecs as 2-element arrays (if tv is present). */ + AV *av; + if (tv) { + av = newAV(); + av_push(av, newSViv(tv[0].tv_sec)); + av_push(av, newSViv(tv[0].tv_nsec)); + XPUSHs(sv_2mortal(newRV_noinc((SV *)av))); + av = newAV(); + av_push(av, newSViv(tv[1].tv_sec)); + av_push(av, newSViv(tv[1].tv_nsec)); + XPUSHs(sv_2mortal(newRV_noinc((SV *)av))); + } + else { + XPUSHs(&PL_sv_undef); + XPUSHs(&PL_sv_undef); + } + + } + else { + /* Pushing timespecs as floating point (double) values. */ + XPUSHs(tv ? sv_2mortal(newSVnv(tv[0].tv_sec + (tv[0].tv_nsec / 1000000000.0))) : &PL_sv_undef); + XPUSHs(tv ? sv_2mortal(newSVnv(tv[1].tv_sec + (tv[1].tv_nsec / 1000000000.0))) : &PL_sv_undef); + } PUTBACK; rv = call_sv(MY_CXT.callback[36],G_SCALAR); SPAGAIN; @@ -1433,7 +1489,7 @@ int _PLfuse_ioctl(const char *file, int cmd, void *arg, /* 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(newSVuv((unsigned int)cmd))); XPUSHs(sv_2mortal(newSViv(flags))); if (_IOC_DIR(cmd) & _IOC_WRITE) XPUSHs(sv_2mortal(newSVpvn(data, _IOC_SIZE(cmd)))); @@ -1478,12 +1534,42 @@ 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) { - + 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 #endif /* FUSE_VERSION >= 28 */ struct fuse_operations _available_ops = { @@ -1533,9 +1619,7 @@ bmap: _PLfuse_bmap, #endif /* FUSE_VERSION >= 26 */ #if FUSE_VERSION >= 28 ioctl: _PLfuse_ioctl, -#if 0 poll: _PLfuse_poll, -#endif #endif /* FUSE_VERSION >= 28 */ }; @@ -1645,7 +1729,7 @@ perl_fuse_main(...) struct fuse_chan *fc; dMY_CXT; INIT: - if(items != N_CALLBACKS + 5) { + if(items != N_CALLBACKS + 6) { fprintf(stderr,"Perl<->C inconsistency or internal error\n"); XSRETURN_UNDEF; } @@ -1671,8 +1755,9 @@ perl_fuse_main(...) #if FUSE_VERSION >= 28 fops.flag_nullpath_ok = SvIV(ST(4)); #endif /* FUSE_VERSION >= 28 */ + MY_CXT.utimens_as_array = SvIV(ST(5)); for(i=0;i= 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