Remove the todo about the test path, I think that's fixed now.
[perl-fuse.git] / Fuse.xs
diff --git a/Fuse.xs b/Fuse.xs
index fb73a12..31d6d2b 100755 (executable)
--- a/Fuse.xs
+++ b/Fuse.xs
@@ -1423,6 +1423,7 @@ int _PLfuse_bmap(const char *file, size_t blocksize, uint64_t *idx) {
 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;
@@ -1430,9 +1431,8 @@ int _PLfuse_ioctl(const char *file, int cmd, void *arg,
        PUSHMARK(SP);
        XPUSHs(sv_2mortal(newSVpv(file,0)));
        XPUSHs(sv_2mortal(newSViv(cmd)));
-    XPUSHs(sv_2mortal(newSViv((uintptr_t)arg)));
        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);
@@ -1440,12 +1440,18 @@ 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;
+       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);
-            rv--;
 
                        if (len > _IOC_SIZE(cmd)) {
                                fprintf(stderr, "ioctl(): returned data was too large for data area\n");
@@ -1457,12 +1463,10 @@ int _PLfuse_ioctl(const char *file, int cmd, void *arg,
                        }
                }
                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;