From e3591b413b57949965fa3929b12bb3b202870937 Mon Sep 17 00:00:00 2001 From: Michael Scherle Date: Thu, 6 Dec 2018 07:31:51 -0800 Subject: bug in read function probably fixed, needs futher testing --- src/fuse/cow.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fuse/cow.c b/src/fuse/cow.c index c9966d1..42ca149 100644 --- a/src/fuse/cow.c +++ b/src/fuse/cow.c @@ -501,7 +501,7 @@ int cow_read(char *buf, size_t size, off_t offset) int readBigBlock(long bigBlockId, char *buf, size_t size, off_t offset) { // If block isn't local - if(filePointers[bigBlockId] == 0) { + if( filePointers[bigBlockId] == 0) { return imageReadInternal( buf, size, ( offset + ( bigBlockId * ( 4096 * 256 ) ) ) ); } int blockState[8]; @@ -509,11 +509,12 @@ int readBigBlock(long bigBlockId, char *buf, size_t size, off_t offset) int block = getSmallBlockId( offset ); int endBlock = getSmallBlockId( offset + size - 1 ); size_t readBytes = 0; - + char *curBuf = buf; while( readBytes < size ) { if( !TestBit( blockState, block ) ) { - while( !TestBit( blockState, block ) && block != endBlock ) { + // test + while( !TestBit( blockState, ( block + 1 ) ) && block != endBlock ) { block++; if( block > 255 ) { printf( "ERROR SmallBlack id > 255" ); @@ -536,7 +537,8 @@ int readBigBlock(long bigBlockId, char *buf, size_t size, off_t offset) startOffset = startOffset + ( bigBlockId * 4096 * 256 ); if( sizeToRemoteRead > 0 ) { - readBytes += imageReadInternal( (buf + readBytes), sizeToRemoteRead, startOffset ); + readBytes += imageReadInternal( (curBuf), sizeToRemoteRead, startOffset ); + curBuf += sizeToRemoteRead; } /* char str[sizeToRemoteRead]; @@ -550,7 +552,8 @@ int readBigBlock(long bigBlockId, char *buf, size_t size, off_t offset) } } } else { - while( TestBit( blockState, block ) && block != endBlock) { + //test + while( TestBit( blockState, (block + 1) ) && block != endBlock) { block++; if( block > 255 ) { printf( "ERROR SmallBlack id > 255" ); @@ -563,7 +566,7 @@ int readBigBlock(long bigBlockId, char *buf, size_t size, off_t offset) } //read Data local - size_t singleReadBytes = pread(fh, (buf + readBytes), sizeToRead, ( (off_t) filePointers[bigBlockId] + 4096 + startOffset ) ); + size_t singleReadBytes = pread(fh, (curBuf), sizeToRead, ( (off_t) filePointers[bigBlockId] + 4096 + startOffset ) ); /* @@ -574,8 +577,11 @@ int readBigBlock(long bigBlockId, char *buf, size_t size, off_t offset) if (singleReadBytes < sizeToRead) { printf("Error on reading data from COW File. File end reached?"); } + curBuf += singleReadBytes; readBytes += singleReadBytes; } + block++; + } return (int) readBytes; } -- cgit v1.2.3-55-g7522