+/*
+ * vim:ts=8:noet
+ */
+
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
result->st_ctime = POPi;
result->st_mtime = POPi;
result->st_atime = POPi;
- result->st_size = POPi;
+ result->st_size = POPn; // we pop double here to support files larger than 4Gb (long limit)
result->st_rdev = POPi;
result->st_gid = POPi;
result->st_uid = POPi;
int _PLfuse_open (const char *file, struct fuse_file_info *fi) {
int rv;
int flags = fi->flags;
+ HV *fihash;
FUSE_CONTEXT_PRE;
DEBUGf("open begin\n");
ENTER;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(file,0)));
XPUSHs(sv_2mortal(newSViv(flags)));
+ /* Create a hashref containing the details from fi
+ * which we can look at or modify.
+ */
+ fi->fh = 0; /* Ensure it starts with 0 - important if they don't set it */
+ fihash = newHV();
+#if FUSE_VERSION >= 24
+ hv_store(fihash, "direct_io", 9, newSViv(fi->direct_io), 0);
+ hv_store(fihash, "keep_cache", 10, newSViv(fi->keep_cache), 0);
+#endif
+#if FUSE_VERSION >= 29
+ hv_store(fihash, "nonseekable", 11, newSViv(fi->nonseekable), 0);
+#endif
+ XPUSHs(sv_2mortal(newRV_noinc((SV*) fihash)));
+ /* All hashref things done */
+
PUTBACK;
- rv = call_sv(_PLfuse_callbacks[14],G_SCALAR);
+ /* Open called with filename, flags */
+ rv = call_sv(_PLfuse_callbacks[14],G_ARRAY);
SPAGAIN;
if(rv)
+ {
+ SV *sv;
+ if (rv > 1)
+ {
+ sv = POPs;
+ if (SvOK(sv))
+ {
+ /* We're holding on to the sv reference until
+ * after exit of this function, so we need to
+ * increment its reference count
+ */
+ fi->fh = SvREFCNT_inc(sv);
+ }
+ }
rv = POPi;
+ }
else
rv = 0;
+ 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 FUSE_VERSION >= 29
+ svp = hv_fetch(fihash, "nonseekable", 11, 0);
+ if (svp != NULL)
+ {
+ fi->nonseekable = SvIV(*svp);
+ }
+#endif
+ }
FREETMPS;
LEAVE;
PUTBACK;
XPUSHs(sv_2mortal(newSVpv(file,0)));
XPUSHs(sv_2mortal(newSViv(buflen)));
XPUSHs(sv_2mortal(newSViv(off)));
+ XPUSHs(fi->fh==0 ? &PL_sv_undef : (SV *)fi->fh);
PUTBACK;
rv = call_sv(_PLfuse_callbacks[15],G_SCALAR);
SPAGAIN;
XPUSHs(sv_2mortal(newSVpv(file,0)));
XPUSHs(sv_2mortal(newSVpvn(buf,buflen)));
XPUSHs(sv_2mortal(newSViv(off)));
+ XPUSHs(fi->fh==0 ? &PL_sv_undef : (SV *)fi->fh);
PUTBACK;
rv = call_sv(_PLfuse_callbacks[16],G_SCALAR);
SPAGAIN;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(file,0)));
+ XPUSHs(fi->fh==0 ? &PL_sv_undef : (SV *)fi->fh);
PUTBACK;
rv = call_sv(_PLfuse_callbacks[18],G_SCALAR);
SPAGAIN;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(file,0)));
XPUSHs(sv_2mortal(newSViv(flags)));
+ XPUSHs(fi->fh==0 ? &PL_sv_undef : (SV *)fi->fh);
PUTBACK;
rv = call_sv(_PLfuse_callbacks[19],G_SCALAR);
SPAGAIN;
rv = POPi;
else
rv = 0;
+ /* We're now finished with the handle that we were given, so
+ * we should decrement its count so that it can be freed.
+ */
+ if (fi->fh != 0)
+ {
+ SvREFCNT_dec((SV *)fi->fh);
+ fi->fh = 0;
+ }
FREETMPS;
LEAVE;
PUTBACK;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(file,0)));
XPUSHs(sv_2mortal(newSViv(flags)));
+ XPUSHs(fi->fh==0 ? &PL_sv_undef : (SV *)fi->fh);
PUTBACK;
rv = call_sv(_PLfuse_callbacks[20],G_SCALAR);
SPAGAIN;
int i, fd, debug, threaded;
char *mountpoint;
char *mountopts;
+ char *fuseopts = NULL;
struct fuse_args margs = FUSE_ARGS_INIT(0, NULL);
struct fuse_args fargs = FUSE_ARGS_INIT(0, NULL);
INIT:
- if(items != 29) {
+ if(items != 30) {
fprintf(stderr,"Perl<->C inconsistency or internal error\n");
XSRETURN_UNDEF;
}
}
mountpoint = SvPV_nolen(ST(2));
mountopts = SvPV_nolen(ST(3));
+ if (SvCUR(ST(4))) fuseopts = SvPV_nolen(ST(4));
for(i=0;i<N_CALLBACKS;i++) {
- SV *var = ST(i+4);
+ SV *var = ST(i+5);
/* allow symbolic references, or real code references. */
if(SvOK(var) && (SvPOK(var) || (SvROK(var) && SvTYPE(SvRV(var)) == SVt_PVCV))) {
void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops;
_PLfuse_callbacks[i] = var;
} else
if(SvOK(var)) {
- croak("invalid callback passed to perl_fuse_main "
+ croak("invalid callback (%i) passed to perl_fuse_main "
"(%s is not a string, code ref, or undef).\n",
i+4,SvPVbyte_nolen(var));
}
fuse_opt_free_args(&margs);
croak("out of memory\n");
}
+ if (fuse_opt_add_arg(&fargs, "") == -1) {
+ fuse_opt_free_args(&fargs);
+ croak("out of memory\n");
+ }
+ if (fuseopts &&
+ (fuse_opt_add_arg(&fargs, "-o") == -1 ||
+ fuse_opt_add_arg(&fargs, fuseopts) == -1)) {
+ fuse_opt_free_args(&fargs);
+ croak("out of memory\n");
+ }
+ if (debug && (fuse_opt_add_arg(&fargs, "-d") == -1)) {
+ fuse_opt_free_args(&fargs);
+ croak("out of memory\n");
+ }
+
fd = fuse_mount(mountpoint,&margs);
fuse_opt_free_args(&margs);
if(fd < 0)
croak("could not mount fuse filesystem!\n");
- if (debug) {
- if ( fuse_opt_add_arg(&fargs, "") == -1 ||
- fuse_opt_add_arg(&fargs, "-d") == -1) {
- fuse_opt_free_args(&fargs);
- croak("out of memory\n");
- }
- } else {
- if (fuse_opt_add_arg(&fargs, "") == -1)
- croak("out of memory\n");
- }
if(threaded) {
fuse_loop_mt(fuse_new(fd,&fargs,&fops,sizeof(fops)));