From: Ralph Ronnquist Date: Wed, 28 Jun 2023 06:06:26 +0000 (+1000) Subject: Fix size dubbling. Handle block device fragment. X-Git-Tag: 1.0~1^2~5 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=0df8fcce46695d24edea6218bb460cce0818b0d0;hp=0b4227e95976ce9b0619c5f5faffae866f6b7d4c;p=rrq%2Ffusefile.git Fix size dubbling. Handle block device fragment. --- diff --git a/fusefile.c b/fusefile.c index f886287..5f7850b 100644 --- a/fusefile.c +++ b/fusefile.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include struct Region { off_t beg; @@ -313,6 +315,15 @@ static int setup_source(struct Source *p,char *frag) { fprintf( stderr, "** %s opened read-only\n", p->filename ); } p->from = 0; + if ( S_ISBLK( filestat.st_mode ) ) { + // Block devices report size differently: + if ( ioctl( p->fd, BLKGETSIZE64, &filestat.st_size ) < 0 ) { + perror( p->filename ); + } +#if DEBUG + fprintf( stderr, "block device size = %ld\n", filestat.st_size ); +#endif + } p->to = filestat.st_size; // Process any range variation if ( range && *(++range) ) { @@ -375,8 +386,6 @@ static int setup_sources(char **argv,int i,int n) { if ( setup_source( p, argv[i] ) ) { return 1; } - p->start = sources.size; // the fusefile position of fragment - sources.size += p->to - p->from; #if DEBUG print_source( p ); #endif