Check (not entirely yet) read and write return codes

This commit is contained in:
benrubson 2017-08-10 12:18:46 +02:00
parent 5c90ad451e
commit 3cd97c3568
3 changed files with 48 additions and 4 deletions

View File

@ -2,7 +2,11 @@ dist: trusty
language: cpp language: cpp
sudo: true sudo: required
env:
global:
- SUDO_MOUNT=sudo
os: os:
- linux - linux

View File

@ -202,11 +202,13 @@ ssize_t RawFileIO::read(const IORequest &req) const {
rAssert(fd >= 0); rAssert(fd >= 0);
ssize_t readSize = pread(fd, req.data, req.dataLen, req.offset); ssize_t readSize = pread(fd, req.data, req.dataLen, req.offset);
int eno = errno;
errno = 0; //just to be sure error seen in integration tests really comes from the function rc.
if (readSize < 0) { if (readSize < 0) {
readSize = -errno;
RLOG(WARNING) << "read failed at offset " << req.offset << " for " RLOG(WARNING) << "read failed at offset " << req.offset << " for "
<< req.dataLen << " bytes: " << strerror(-readSize); << req.dataLen << " bytes: " << strerror(eno);
return -eno;
} }
return readSize; return readSize;
@ -226,6 +228,7 @@ ssize_t RawFileIO::write(const IORequest &req) {
errno = 0; errno = 0;
ssize_t writeSize = ::pwrite(fd, buf, bytes, offset); ssize_t writeSize = ::pwrite(fd, buf, bytes, offset);
eno = errno; eno = errno;
errno = 0; //just to be sure error seen in integration tests really comes from the function rc.
if (writeSize < 0) { if (writeSize < 0) {
knownSize = false; knownSize = false;

View File

@ -2,7 +2,7 @@
# Test EncFS normal and paranoid mode # Test EncFS normal and paranoid mode
use Test::More tests => 122; use Test::More tests => 132;
use File::Path; use File::Path;
use File::Copy; use File::Copy;
use File::Temp; use File::Temp;
@ -78,6 +78,8 @@ sub runTests
&grow; &grow;
&umask0777; &umask0777;
&create_unmount_remount; &create_unmount_remount;
&checkReadError;
&checkWriteError;
&configFromPipe; &configFromPipe;
&cleanup; &cleanup;
@ -430,3 +432,38 @@ sub create_unmount_remount
portable_unmount($mnt); portable_unmount($mnt);
} }
# Test that read errors are correctly thrown up to us
sub checkReadError
{
# Not sure how to implement this, so feel free !
ok(1, "read error");
}
# Test that write errors are correctly thrown up to us
sub checkWriteError
{
# Not sure how to implement this on Mac OS, so feel free !
if($^O eq "darwin") {
ok(1, "write error");
ok(1, "write error");
ok(1, "write error");
ok(1, "write error");
}
else {
my $crypt = "$workingDir/checkWriteError.crypt";
my $mnt = "$workingDir/checkWriteError.mnt";
mkdir($crypt) || BAIL_OUT($!);
mkdir($mnt) || BAIL_OUT($!);
system(($ENV{'SUDO_MOUNT'}||"")." mount -t tmpfs -o size=1m tmpfs $crypt");
ok( $? == 0, "mount command returns 0") || return;
system("./build/encfs --standard --extpass=\"echo test\" $crypt $mnt 2>&1");
ok( $? == 0, "encfs command returns 0") || return;
ok(open(OUT , "> $mnt/file"), "write content");
while(print OUT "0123456789") {}
ok ($!{ENOSPC}, "write returned $! instead of ENOSPC");
close OUT;
portable_unmount($mnt);
system(($ENV{'SUDO_MOUNT'}||"")." umount $crypt");
}
}