diff --git a/encfs/BlockFileIO.cpp b/encfs/BlockFileIO.cpp index adadaa3..11c46de 100644 --- a/encfs/BlockFileIO.cpp +++ b/encfs/BlockFileIO.cpp @@ -101,7 +101,7 @@ int BlockFileIO::cacheWriteOneBlock(const IORequest &req) { _cache.offset = req.offset; _cache.dataLen = req.dataLen; int res = writeOneBlock(req); - if (res) clearCache(_cache, _blockSize); + if (res < 0) clearCache(_cache, _blockSize); return res; } @@ -201,7 +201,7 @@ int BlockFileIO::write(const IORequest &req) { // extend file first to fill hole with 0's.. const bool forceWrite = false; int res = padFile(fileSize, req.offset, forceWrite); - if (res) + if (res < 0) return res; } @@ -266,7 +266,7 @@ int BlockFileIO::write(const IORequest &req) { // Finally, write the damn thing! res = cacheWriteOneBlock(blockReq); - if (res) { + if (res < 0) { break; } @@ -342,7 +342,7 @@ int BlockFileIO::padFile(off_t oldSize, off_t newSize, bool forceWrite) { // 2, pad zero blocks unless holes are allowed if (!_allowHoles) { - for (; !res && (oldLastBlock != newLastBlock); ++oldLastBlock) { + for (; !(res < 0) && (oldLastBlock != newLastBlock); ++oldLastBlock) { VLOG(1) << "padding block " << oldLastBlock; req.offset = oldLastBlock * _blockSize; req.dataLen = _blockSize; @@ -352,7 +352,7 @@ int BlockFileIO::padFile(off_t oldSize, off_t newSize, bool forceWrite) { } // 3. only necessary if write is forced and block is non 0 length - if (!res && forceWrite && newBlockSize) { + if (!(res < 0) && forceWrite && newBlockSize) { req.offset = newLastBlock * _blockSize; req.dataLen = newBlockSize; memset(mb.data, 0, req.dataLen); @@ -379,7 +379,7 @@ int BlockFileIO::truncateBase(off_t size, FileIO *base) { if (base) res = base->truncate(size); const bool forceWrite = true; - if (!res) + if (!(res < 0)) res = padFile(oldSize, size, forceWrite); } else if (size == oldSize) { // the easiest case, but least likely.... diff --git a/encfs/CipherFileIO.cpp b/encfs/CipherFileIO.cpp index fae102b..6cf9282 100644 --- a/encfs/CipherFileIO.cpp +++ b/encfs/CipherFileIO.cpp @@ -222,7 +222,7 @@ int CipherFileIO::initHeader() { req.dataLen = 8; int res = base->write(req); - if (res) + if (res < 0) return res; } else { VLOG(1) << "base not writable, IV not written.."; @@ -252,7 +252,7 @@ bool CipherFileIO::writeHeader() { req.data = buf; req.dataLen = 8; - if (base->write(req)) + if (base->write(req) < 0) return false; return true; @@ -461,7 +461,7 @@ int CipherFileIO::truncate(off_t size) { // the wrong size.. res = BlockFileIO::truncateBase(size, 0); - if (res == 0) res = base->truncate(size + HEADER_SIZE); + if (!(res < 0)) res = base->truncate(size + HEADER_SIZE); } return res; } diff --git a/encfs/MACFileIO.cpp b/encfs/MACFileIO.cpp index 15bb032..9a17c7b 100644 --- a/encfs/MACFileIO.cpp +++ b/encfs/MACFileIO.cpp @@ -253,7 +253,7 @@ int MACFileIO::truncate(off_t size) { int res = BlockFileIO::truncateBase(size, 0); - if (res == 0) res = base->truncate(locWithHeader(size, bs, headerSize)); + if (!(res < 0)) res = base->truncate(locWithHeader(size, bs, headerSize)); return res; } diff --git a/encfs/RawFileIO.cpp b/encfs/RawFileIO.cpp index b2cbb26..231970d 100644 --- a/encfs/RawFileIO.cpp +++ b/encfs/RawFileIO.cpp @@ -246,7 +246,7 @@ int RawFileIO::write(const IORequest &req) { if (last > fileSize) fileSize = last; } - return 0; + return 0; //No matter how many bytes we wrote, we of course already know this. } } diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index ad0acec..64a47b0 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -616,10 +616,10 @@ int encfs_fsync(const char *path, int dataSync, struct fuse_file_info *file) { int _do_write(FileNode *fnode, unsigned char *ptr, size_t size, off_t offset) { int res = fnode->write(offset, ptr, size); - if (!res) - return size; - else + if (res < 0) return res; + else + return size; } int encfs_write(const char *path, const char *buf, size_t size, off_t offset,