test of asynchronous write/read
[rrq/fusefile.git] / fusefile.c
index c8964f4d580bf1a99bd7085c9d14869b77962dbd..2c7bc8da769a74e7d701da846afa86b9ba0de0e4 100644 (file)
@@ -25,8 +25,8 @@
 
 #define FUSE_USE_VERSION 33
 
-#include <fuse.h>
-#include <fuse/fuse_lowlevel.h>
+#include <fuse3/fuse.h>
+#include <fuse3/fuse_lowlevel.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -329,7 +329,7 @@ static int setup_source(struct Source *p,char *frag) {
        perror( p->filename );
        return 1; // Error return
     }
-    if ( ( range == 0 ) && stat( p->filename, &filestat ) ) {
+    if ( ( range != 0 ) && stat( p->filename, &filestat ) ) {
        perror( p->filename );
        return 1; 
     }
@@ -415,7 +415,9 @@ static int setup_sources(char **argv,int i,int n) {
     return 0;
 }
 
-static int fusefile_getattr(const char *path,struct stat *stbuf) {
+static int fusefile_getattr(const char *path, struct stat *stbuf,
+                           struct fuse_file_info *ffi)
+{
 #if DEBUG
     fprintf( stderr, "fusefile_getattr( %s )\n", path );
 #endif
@@ -437,17 +439,19 @@ static int fusefile_getattr(const char *path,struct stat *stbuf) {
     return 0;
 }
 
-static int fusefile_chmod(const char *path,mode_t m) {
+static int fusefile_chmod(const char *path, mode_t m,
+                         struct fuse_file_info *ffi)
+{
 #if DEBUG
     fprintf( stderr, "fusefile_chmod( %s, %d )\n", path, m );
 #endif
     return -1;
 }
 
-static int fusefile_open(const char *path,struct fuse_file_info *fi) {
+static int fusefile_open(const char *path, struct fuse_file_info *ffi) {
 #if DEBUG
-    fprintf( stderr, "fusefile_open( %s, %d )\n", path, fi->flags );
-    fprintf( stderr, "fixing( %d )\n", fi->flags | O_CLOEXEC );
+    fprintf( stderr, "fusefile_open( %s, %d )\n", path, ffi->flags );
+    fprintf( stderr, "fixing( %d )\n", ffi->flags | O_CLOEXEC );
 #endif
     if ( strcmp( path, "/" ) != 0 ) {
        return -ENOENT;
@@ -507,7 +511,7 @@ static int overlay_merge(char *buf,off_t beg,off_t end) {
 
 // Read <size> bytes from <offset> in file
 static int fusefile_read(const char *path, char *buf, size_t size,
-                        off_t off, struct fuse_file_info *fi)
+                        off_t off, struct fuse_file_info *ffi)
 {
     if( strcmp( path, "/" ) != 0 ) {
        return -ENOENT;
@@ -576,8 +580,8 @@ static int fusefile_read(const char *path, char *buf, size_t size,
 /**
  * Poll for IO readiness.
  */
-int fusefile_poll(const char *path, struct fuse_file_info *fi,
-                  struct fuse_pollhandle *ph, unsigned *reventsp )
+int fusefile_poll(const char *path, struct fuse_file_info *ffi,
+                 struct fuse_pollhandle *ph, unsigned *reventsp )
 {
 #if DEBUG
     fprintf( stderr, "fusefile_poll( %s ) %p %d\n", path, ph, *reventsp );
@@ -798,7 +802,7 @@ static int write_block(off_t off,const char *buf,size_t size) {
 }
 
 static int fusefile_write_buf(const char *path, struct fuse_bufvec *buf,
-                             off_t off, struct fuse_file_info *fi) {
+                             off_t off, struct fuse_file_info *ffi) {
 #if DEBUG
     fprintf( stderr, "fusefile_write_buf( %s )\n", path );
 #endif
@@ -830,7 +834,7 @@ static int fusefile_write_buf(const char *path, struct fuse_bufvec *buf,
  * Write a fragment at <off>. This overwrites files.
  */
 static int fusefile_write(const char *path, const char *buf, size_t size,
-                         off_t off, struct fuse_file_info *fi)
+                         off_t off, struct fuse_file_info *ffi)
 {
 #if DEBUG
     fprintf( stderr, "fusefile_write( %s %ld )\n", path, size );
@@ -903,7 +907,7 @@ static void fsync_all_dirty() {
     }
 }
 
-static int fusefile_flush(const char *path, struct fuse_file_info *info) {
+static int fusefile_flush(const char *path, struct fuse_file_info *ffi) {
 #if DEBUG
     fprintf( stderr, "fusefile_flush( %s )\n", path );
 #endif
@@ -914,7 +918,7 @@ static int fusefile_flush(const char *path, struct fuse_file_info *info) {
     return 0;
 }
 
-static int fusefile_release(const char *path, struct fuse_file_info *fi) {
+static int fusefile_release(const char *path, struct fuse_file_info *ffi) {
 #if DEBUG
     fprintf( stderr, "fusefile_release( %s, %d )\n", path, fi->flags );
 #endif
@@ -924,7 +928,8 @@ static int fusefile_release(const char *path, struct fuse_file_info *fi) {
     return 0;
 }
 
-static int fusefile_fsync(const char *path, int x, struct fuse_file_info *fi) {
+static int fusefile_fsync(const char *path, int x,
+                         struct fuse_file_info *ffi) {
 #if DEBUG
     fprintf( stderr, "fusefile_fsync( %s, %d )\n", path, x );
 #endif
@@ -938,7 +943,8 @@ static int fusefile_fsync(const char *path, int x, struct fuse_file_info *fi) {
 /**
  * 
  */
-static int fusefile_truncate(const char *path, off_t len) {
+static int fusefile_truncate(const char *path, off_t len,
+                            struct fuse_file_info *ffi) {
 #if DEBUG
     fprintf( stderr, "fusefile_truncate( %s, %ld )\n", path, len );
 #endif
@@ -948,13 +954,12 @@ static int fusefile_truncate(const char *path, off_t len) {
     return -EIO;
 }
 
-void *fusefile_init(struct fuse_conn_info *fci) {
+void *fusefile_init(struct fuse_conn_info *fci, struct fuse_config *fc) {
 #if DEBUG
     fprintf( stderr, "fusefile_init( %d, %d )\n", fci->async_read, fci->want );
 #endif
-    // Disable asynchronous reading
-    fci->async_read = 0;
-    fci->want &= ~FUSE_CAP_ASYNC_READ;
+    // Disable asynchronous operations, both reading and direct I/O
+    fci->want &= ~ ( FUSE_CAP_ASYNC_READ | FUSE_CAP_ASYNC_DIO );
 #if DEBUG
     fprintf( stderr, "fusefile_init( %d, %d )\n", fci->async_read, fci->want );
 #endif
@@ -975,7 +980,7 @@ static int dump_fragments(int push) {
                  ENDSOURCE( sources.array[ src ] ) <= x; src++ ) {
            // Dump sources.array[src] in full
            if ( !push ) {
-               fprintf( stdout, "%s/%ld:%ld\n",
+               fprintf( stdout, "%s/%ld:%ld\n",
                         sources.array[ src ].filename,
                         pos - sources.array[ src ].start +
                         sources.array[ src ].from,
@@ -986,10 +991,10 @@ static int dump_fragments(int push) {
        if ( ( src < sources.count ) && ( sources.array[ src ].start < x ) ) {
            // Dump sources.array[src] up to x;
            if ( !push ) {
-               fprintf( stdout, "%s/%ld:%ld\n",
+               fprintf( stdout, "%s/%ld:%ld\n",
                         sources.array[ src ].filename,
-                        sources.array[ src ].from,
-                        //pos - sources.array[ src ].start,
+                        sources.array[ src ].from +
+                        pos - sources.array[ src ].start,
                         x - sources.array[ src ].start +
                         sources.array[ src ].from
                         );
@@ -1031,7 +1036,6 @@ static struct fuse_operations fusefile_oper = {
     .fsync = fusefile_fsync,
     // NYI .ftruncate = fusefile_ftruncate,
     .truncate = fusefile_truncate,
-    //.truncate = fusefile_truncate,
     //.release = fusefile_release,
     .init = fusefile_init,
 };
@@ -1082,8 +1086,6 @@ static int setup_argv(int argc,char ***argv) {
 int main(int argc, char *argv[])
 {
     char *mnt;
-    int mt;
-    int fg;
     int i;
     int fuseargc;
     struct stat stbuf;
@@ -1153,13 +1155,11 @@ int main(int argc, char *argv[])
        return dump_fragments( 1 );
     }
     struct fuse_args args = FUSE_ARGS_INIT( fuseargc, argv );
-    if ( fuse_parse_cmdline( &args, &mnt, &mt, &fg ) ) {
+    struct fuse_cmdline_opts opts = { 0 };
+    if ( fuse_parse_cmdline( &args, &opts ) ) {
        return 1;
     }
     fuse_opt_free_args( &args );
-    if ( ! mnt ) {
-       fprintf( stderr, "missing mountpoint parameter\n" );
-       return 1;
-    }
-    return fuse_main( fuseargc, argv, &fusefile_oper, temporary? mnt : NULL );
+    return fuse_main( fuseargc, argv, &fusefile_oper,
+                     temporary? opts.mountpoint : NULL );
 }