bug fix EOF handling
[rrq/fusefile.git] / fusefile.c
index 8e09b588316719670810ebdc1013c5e1076e60c7..a0f09818da187d7958c75d6117ef5ed6bdebd06c 100644 (file)
@@ -217,7 +217,7 @@ static int fusefile_read(const char *path, char *buf, size_t size,
 #endif
        int i = find_source( off );
        if ( i < 0 ) {
-           return ( off == sources.size )? 0 : -ENOENT;
+           return ( off == sources.size )? rr : -ENOENT;
        }
        if ( sources.array[i].fd < 0 ) {
            return -ENOENT;
@@ -256,6 +256,25 @@ static int fusefile_read(const char *path, char *buf, size_t size,
     return rr;
 }
 
+/**
+ * Poll for IO readiness.
+ */
+int fusefile_poll(const char *path, struct fuse_file_info *fi,
+                  struct fuse_pollhandle *ph, unsigned *reventsp )
+{
+#if DEBUG
+    fprintf( stderr, "fusefile_poll( %s ) %p %d\n", path, ph, *reventsp );
+#endif
+    if( strcmp( path, "/" ) != 0 ) {
+       return -ENOENT;
+    }
+    if ( ph ) {
+       return fuse_notify_poll( ph );
+    }
+    return 0;
+}
+
+
 /**
  * Write a full block of data over the sources at the offset
  */
@@ -397,6 +416,7 @@ static struct fuse_operations fusefile_oper = {
     .chmod = fusefile_chmod,
     .open = fusefile_open,
     .read = fusefile_read,
+    .poll = fusefile_poll,
     .write = fusefile_write,
     .write_buf = fusefile_write_buf,
     .destroy = fusefile_destroy,
@@ -420,28 +440,31 @@ static void usage() {
 
 /**
  * Set up the arguments for the fuse_main call, adding our own.
+ * argv[argc] is the mount point argument
  */
 static int setup_argv(int argc,char ***argv) {
+    // note: (*argv)[ argc ] is the mount point argument
     char *OURS[] = {
        "-odefault_permissions",
-       (*argv)[ --argc ]  // note: (*argv)[ argc-1 ] = the mount point
+       (*argv)[ argc ]
     };
 #define OURSN ( sizeof( OURS ) / sizeof( char* ) )
-    int N = argc + OURSN; // new argv-tobe size, excluding null
-    char **out = malloc( ( N + 1 ) * sizeof( char* ) );
+    int N = argc + OURSN;
+    // Allocate new arg array plus terminating null pointer
+    char **out = malloc( ( N + 1 ) * sizeof( char* ) ); 
     int i;
     for ( i = 0; i < argc; i++ ) {
        out[ i ] = (*argv)[i];
-       fprintf( stderr, " %s", out[ i ] );
+       //fprintf( stderr, " %s", out[ i ] );
     }
     for ( i = 0; i < OURSN; i++ ) {
        out[ argc + i ] = OURS[i];
-       fprintf( stderr, " %s", out[ i ] );
+       //fprintf( stderr, " %s", out[ i ] );
     }
     out[ N ] = 0;
-    fprintf( stderr, "\n" );
+    //fprintf( stderr, "\n" );
     (*argv) = out;
-    return N;
+    return N; // Don't include the terminating null pointer
 }
 
 /**
@@ -466,8 +489,8 @@ int main(int argc, char *argv[])
     if ( i > argc - 2 ) { // At least mount point plus one source
        usage();
     }
-    mnt = argv[ i++ ]; // First non-option argument is the mount pount
     fuseargc = i;
+    mnt = argv[ i++ ]; // First non-option argument is the mount pount
     if ( setup_sources( argv, i, argc-i ) ) {
        return 1;
     }