mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 23:43:26 +01:00
Make some return codes easier to read / understand
This commit is contained in:
parent
062e3a5a98
commit
483fb7c6cc
@ -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....
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user