Added -dump function for dumping an overlay table.
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Tue, 20 Jun 2023 14:06:57 +0000 (00:06 +1000)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Tue, 20 Jun 2023 14:06:57 +0000 (00:06 +1000)
fusefile.8
fusefile.c

index 395438955609bdf2843c1a7edb448f617b3fc19c..2b116a9502d90428de933c719ae3f37e9cfd7ebd 100644 (file)
@@ -35,6 +35,11 @@ any new written fused file regions followed by meta data to
 distinguish between new, written content and old content that comes
 from the fragments.
 
 distinguish between new, written content and old content that comes
 from the fragments.
 
+The option \fB-dump\fR together with an overlay fusefile setup will
+print the current overlay table to standard output rather than
+establishing a fusefile mount. The table is printed as the series of
+fusefile fragments using the argments as given.
+
 .SH FRAGMENT ARGUMENTS
 
 The fragment arguments include the filename of a source file, and
 .SH FRAGMENT ARGUMENTS
 
 The fragment arguments include the filename of a source file, and
@@ -100,6 +105,13 @@ The mount options \fI-ouid=...\fR and \fI-ogid=...\fR, where \fI...\fR
  \fBfusedisk\fR and thereby give user or group ownership for the mount
  to the nominated user or group.
 
  \fBfusedisk\fR and thereby give user or group ownership for the mount
  to the nominated user or group.
 
+.TP
+\fI-dump\fR
+
+This "mount option" triggers fusefil to, instead of setting up a mount
+point, print out the applicable fusefile fragment sequence for the
+current setup as way of presenting the overlay table.
+
 .SH EXAMPLES
 This section illustrates uses of \fBfusefile\fR.
 
 .SH EXAMPLES
 This section illustrates uses of \fBfusefile\fR.
 
index eeb0e72789f1e322b52419b2fcd04ebf3b995fc1..d8729b9930dae7e8915e32f15dfe69ad548c1f5a 100644 (file)
@@ -1,8 +1,8 @@
 /***
     fusefile - overlay a file path with a concatenation of parts of
 /***
     fusefile - overlay a file path with a concatenation of parts of
-    other files, read only.
+    other files.
 
 
-    Copyright (C) 2019  Ralph Ronnquist
+    Copyright (C) 2019-  Ralph Ronnquist
 
     This program is free software: you can redistribute it and/or
     modify it under the terms of the GNU General Public License as
 
     This program is free software: you can redistribute it and/or
     modify it under the terms of the GNU General Public License as
@@ -775,8 +775,53 @@ void *fusefile_init(struct fuse_conn_info *fci) {
     return 0;
 }
 
     return 0;
 }
 
+#define ENDSOURCE( S ) ( S.start + ( S.to - S.from ) )
+
+/**
+ * Dump the current fragmentation to stdout.
+ */
+static int dump_fragments() {
+    int oly = 0;
+    int src = 0;
+    size_t pos = 0;
+    while ( src < sources.count ) {
+       size_t x = ( oly < overlay.count )?
+           overlay.table[ oly ].beg : sources.size;
+       for ( ; src < sources.count && 
+                 ENDSOURCE( sources.array[ src ] ) <= x; src++ ) {
+           // Dump sources.array[src] in full
+           fprintf( stdout, "%s/%ld:%ld\n",
+                    sources.array[ src ].filename,
+                    pos - sources.array[ src ].start,
+                    sources.array[ src ].to );
+           pos = ENDSOURCE( sources.array[ src ] );
+       }
+       if ( sources.array[ src ].start < x ) {
+           // Dump sources.array[src] up to x;
+           fprintf( stdout, "%s/%ld:%ld\n",
+                    sources.array[ src ].filename,
+                    pos - sources.array[ src ].start,
+                    x - sources.array[ src ].start );
+           pos = ENDSOURCE( sources.array[ src ] );
+       }
+       if ( oly < overlay.count ) {
+           fprintf( stdout, "%s/%ld:%ld\n",
+                    overlay.source.filename,
+                    overlay.table[ oly ].beg,
+                    overlay.table[ oly ].end );
+           pos = overlay.table[ oly++ ].end;
+       }
+       for ( ; src < sources.count &&
+                 ENDSOURCE( sources.array[ src ] ) <= pos; src++ ) {
+           // Just skip these fragments.
+       }
+    }
+    return( 0 );
+}
+
 static struct fuse_operations fusefile_oper = {
     .getattr = fusefile_getattr,
 static struct fuse_operations fusefile_oper = {
     .getattr = fusefile_getattr,
+    // NYI .fgetattr = fusefile_fgetattr,
     .chmod = fusefile_chmod,
     .open = fusefile_open,
     .read = fusefile_read,
     .chmod = fusefile_chmod,
     .open = fusefile_open,
     .read = fusefile_read,
@@ -784,9 +829,11 @@ static struct fuse_operations fusefile_oper = {
     .write = fusefile_write,
     .write_buf = fusefile_write_buf,
     .destroy = fusefile_destroy,
     .write = fusefile_write,
     .write_buf = fusefile_write_buf,
     .destroy = fusefile_destroy,
+    // NYI .access = fusefile_access,
     .flush = fusefile_flush,
     .release = fusefile_release,
     .fsync = fusefile_fsync,
     .flush = fusefile_flush,
     .release = fusefile_release,
     .fsync = fusefile_fsync,
+    // NYI .ftruncate = fusefile_ftruncate,
     .truncate = fusefile_truncate,
     //.truncate = fusefile_truncate,
     //.release = fusefile_release,
     .truncate = fusefile_truncate,
     //.truncate = fusefile_truncate,
     //.release = fusefile_release,
@@ -903,6 +950,9 @@ int main(int argc, char *argv[])
        }
     }
     fuseargc = setup_argv( fuseargc, &argv );
        }
     }
     fuseargc = setup_argv( fuseargc, &argv );
+    if ( strcmp( "-dump", argv[ 1 ] ) == 0 ) {
+       return dump_fragments();
+    }
     struct fuse_args args = FUSE_ARGS_INIT( fuseargc, argv );
     if ( fuse_parse_cmdline( &args, &mnt, &mt, &fg ) ) {
        return 1;
     struct fuse_args args = FUSE_ARGS_INIT( fuseargc, argv );
     if ( fuse_parse_cmdline( &args, &mnt, &mt, &fg ) ) {
        return 1;