summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Scherle2018-12-06 16:31:51 +0100
committerMichael Scherle2018-12-06 16:31:51 +0100
commite3591b413b57949965fa3929b12bb3b202870937 (patch)
tree0e6a30972cf359faad30210ff8f0485edb42988f
parentchanged standart behavior to not overwrite cow file (diff)
downloaddnbd3-e3591b413b57949965fa3929b12bb3b202870937.tar.gz
dnbd3-e3591b413b57949965fa3929b12bb3b202870937.tar.xz
dnbd3-e3591b413b57949965fa3929b12bb3b202870937.zip
bug in read function probably fixed, needs futher testing
-rw-r--r--src/fuse/cow.c18
1 files 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;
}