Added -push action, to push overlay data into source fragments. wip/push
authorRalph Ronnquist <rrq@rrq.au>
Fri, 11 Aug 2023 22:42:36 +0000 (08:42 +1000)
committerRalph Ronnquist <rrq@rrq.au>
Fri, 11 Aug 2023 22:42:36 +0000 (08:42 +1000)
fusefile.8
fusefile.c

index 6af36f49202ba1dc85f3e20690e54d8646ab0582..194f4aa83558057c4c62d859dbab9a2219445940 100644 (file)
@@ -8,6 +8,8 @@ fusefile, fusedisk \- FUSE file mount for combining file fragments
 .br
 .B fusefile \fB-dump\fR \fR[\fIfuse-opts\fR] \fBmountpoint\fR \fR[\fIoverlay\fR] \fIfilename/from-to\fR ...
 .br
 .br
 .B fusefile \fB-dump\fR \fR[\fIfuse-opts\fR] \fBmountpoint\fR \fR[\fIoverlay\fR] \fIfilename/from-to\fR ...
 .br
+.B fusefile \fB-push\fR \fR[\fIfuse-opts\fR] \fBmountpoint\fR \fR[\fIoverlay\fR] \fIfilename/from-to\fR ...
+.br
 .B fusedisk \fR[\fIfuse-opts\fR] \fBmountpoint\fR \fR[\fIoverlay\fR] \fIfilename/from-to\fR ...
 
 .SH DESCRIPTION
 .B fusedisk \fR[\fIfuse-opts\fR] \fBmountpoint\fR \fR[\fIoverlay\fR] \fIfilename/from-to\fR ...
 
 .SH DESCRIPTION
@@ -33,12 +35,18 @@ from the fragments.
 
 The option \fB-dump\fR as first argument together with a fusefile
 setup will print the setup to standard output rather than establishing
 
 The option \fB-dump\fR as first argument together with a fusefile
 setup will print the setup to standard output rather than establishing
-a fusefile mount. This is of most use with a prior overlay setup,
-where then the printout includes the portions of updates that have
-been captured in the overlay. The printout is the series of fusefile
+a fusefile mount. This is of most use with a prior overlay setup where
+then the printout includes the portions of updates that have been
+captured in the overlay. The printout is the series of fusefile
 fragment argments to give in order to intersperse the captured overlay
 portions according to the overlay table.
 
 fragment argments to give in order to intersperse the captured overlay
 portions according to the overlay table.
 
+The option \fB-push\fR as first argument together with a fusefile
+setup will push the overlay into the sources (except for
+write-protected fragments). This is only of use with a prior overlay
+setup where then the updates that have been captured in the overlay
+get pushed into the fragments.
+
 \fBfusedisk\fR is a helper script to set up a \fBfusefile\fR as a
 block device (via \fIfuseblk\fR) by using the device mapper
 (\fBdmsetup\fR) to manage an empty block device mapping where content
 \fBfusedisk\fR is a helper script to set up a \fBfusefile\fR as a
 block device (via \fIfuseblk\fR) by using the device mapper
 (\fBdmsetup\fR) to manage an empty block device mapping where content
index 9e5cb45d835b771e73548b8b443461474fcaa487..69750fad1507d9db3626b9927bac2bb642235ab2 100644 (file)
@@ -717,6 +717,40 @@ static int fusefile_write(const char *path, const char *buf, size_t size,
     return size;
 }
 
     return size;
 }
 
+#define PUSHBUF 104857600
+/**
+ * Write data from overlay to source.
+ */
+static void push_oly(off_t beg, off_t end) {
+    static char * buffer = 0;
+    // Pretend that there isn't an overlay
+    char *filename = overlay.source.filename;
+    if ( buffer == 0 ) {
+       buffer = malloc( PUSHBUF );
+       if ( buffer == 0 ) {
+           fprintf( stderr, "** OOM!!\n" );
+           exit( 1 );
+       }
+    }
+    overlay.source.filename = 0;
+    while ( beg < end ) {
+       off_t size = end - beg;
+       if ( size > PUSHBUF ) {
+           size = PUSHBUF;
+       }
+       if ( lseek( overlay.source.fd, beg, SEEK_SET ) < 0 ) {
+           fprintf( stderr, "** Cannot seek overlay at %ld\n", beg );
+           break;
+       }
+       size = read( overlay.source.fd, buffer, size );
+       if ( write_block( beg, buffer, size ) < 0 ) {
+           fprintf( stderr, "** Cannot push %ld bytes at %ld\n", size, beg );
+       }
+       beg += size;
+    }
+    overlay.source.filename = filename;
+}
+
 static void fusefile_destroy(void *data) {
     char *mnt = (char*) data; // As passed to fuse_main
 #if DEBUG
 static void fusefile_destroy(void *data) {
     char *mnt = (char*) data; // As passed to fuse_main
 #if DEBUG
@@ -804,7 +838,7 @@ void *fusefile_init(struct fuse_conn_info *fci) {
 /**
  * Dump the current fragmentation to stdout.
  */
 /**
  * Dump the current fragmentation to stdout.
  */
-static int dump_fragments() {
+static int dump_fragments(int push) {
     int oly = 0;
     int src = 0;
     size_t pos = 0;
     int oly = 0;
     int src = 0;
     size_t pos = 0;
@@ -814,25 +848,33 @@ static int dump_fragments() {
        for ( ; src < sources.count && 
                  ENDSOURCE( sources.array[ src ] ) <= x; src++ ) {
            // Dump sources.array[src] in full
        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 );
+           if ( !push ) {
+               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 ( ( src < sources.count ) && ( sources.array[ src ].start < x ) ) {
            // Dump sources.array[src] up to x;
            pos = ENDSOURCE( sources.array[ src ] );
        }
        if ( ( src < sources.count ) && ( 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 );
+           if ( !push ) {
+               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 ) {
            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 );
+           if ( !push ) {
+               fprintf( stdout, "%s/%ld:%ld\n",
+                        overlay.source.filename,
+                        overlay.table[ oly ].beg,
+                        overlay.table[ oly ].end );
+           } else {
+               push_oly( overlay.table[ oly ].beg, overlay.table[ oly ].end );
+           }
            pos = overlay.table[ oly++ ].end;
        }
        for ( ; src < sources.count &&
            pos = overlay.table[ oly++ ].end;
        }
        for ( ; src < sources.count &&
@@ -975,7 +1017,10 @@ int main(int argc, char *argv[])
     }
     fuseargc = setup_argv( fuseargc, &argv );
     if ( strcmp( "-dump", argv[ 1 ] ) == 0 ) {
     }
     fuseargc = setup_argv( fuseargc, &argv );
     if ( strcmp( "-dump", argv[ 1 ] ) == 0 ) {
-       return dump_fragments();
+       return dump_fragments( 0 );
+    }
+    if ( strcmp( "-push", argv[ 1 ] ) == 0 ) {
+       return dump_fragments( 1 );
     }
     struct fuse_args args = FUSE_ARGS_INIT( fuseargc, argv );
     if ( fuse_parse_cmdline( &args, &mnt, &mt, &fg ) ) {
     }
     struct fuse_args args = FUSE_ARGS_INIT( fuseargc, argv );
     if ( fuse_parse_cmdline( &args, &mnt, &mt, &fg ) ) {