X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=fusefile.c;h=d8729b9930dae7e8915e32f15dfe69ad548c1f5a;hb=0c5ef73fa615090f99cee4a4fbebb01834d503dd;hp=eeb0e72789f1e322b52419b2fcd04ebf3b995fc1;hpb=36b31903885b6fac4989334f53d207ac184123d9;p=rrq%2Ffusefile.git 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;