From e0e7e2aaffafd7969718f4e3d27c0bfb8c95faad Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Wed, 21 Jun 2023 00:06:57 +1000 Subject: [PATCH] Added -dump function for dumping an overlay table. --- fusefile.8 | 12 ++++++++++++ fusefile.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/fusefile.8 b/fusefile.8 index 3954389..2b116a9 100644 --- a/fusefile.8 +++ b/fusefile.8 @@ -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. +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 @@ -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. +.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. diff --git a/fusefile.c b/fusefile.c index eeb0e72..d8729b9 100644 --- a/fusefile.c +++ b/fusefile.c @@ -1,8 +1,8 @@ /*** 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 @@ -775,8 +775,53 @@ void *fusefile_init(struct fuse_conn_info *fci) { 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, + // NYI .fgetattr = fusefile_fgetattr, .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, + // NYI .access = fusefile_access, .flush = fusefile_flush, .release = fusefile_release, .fsync = fusefile_fsync, + // NYI .ftruncate = fusefile_ftruncate, .truncate = fusefile_truncate, //.truncate = fusefile_truncate, //.release = fusefile_release, @@ -903,6 +950,9 @@ int main(int argc, char *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; -- 2.39.2