diff --git a/src/CryFuse.cpp b/src/CryFuse.cpp index 65447269..7188fa16 100644 --- a/src/CryFuse.cpp +++ b/src/CryFuse.cpp @@ -206,8 +206,9 @@ int CryFuse::read(const path &path, char *buf, size_t size, off_t offset, fuse_f //printf("read(%s, _, %zu, %zu, _)\n", path.c_str(), size, offset); UNUSED(path); try { - _device->read(fileinfo->fh, buf, size, offset); - return 0; + //printf("Reading from file %d\n", fileinfo->fh); + //fflush(stdout); + return _device->read(fileinfo->fh, buf, size, offset); } catch (CryErrnoException &e) { return -e.getErrno(); } @@ -218,7 +219,7 @@ int CryFuse::write(const path &path, const char *buf, size_t size, off_t offset, UNUSED(path); try { _device->write(fileinfo->fh, buf, size, offset); - return 0; + return size; } catch (CryErrnoException &e) { return -e.getErrno(); } diff --git a/src/cryfs_lib/CryDevice.cpp b/src/cryfs_lib/CryDevice.cpp index 652d440a..dfdd7b03 100644 --- a/src/cryfs_lib/CryDevice.cpp +++ b/src/cryfs_lib/CryDevice.cpp @@ -74,8 +74,8 @@ void CryDevice::ftruncate(int descriptor, off_t size) { _open_files.get(descriptor)->truncate(size); } -void CryDevice::read(int descriptor, void *buf, size_t count, off_t offset) { - _open_files.get(descriptor)->read(buf, count, offset); +int CryDevice::read(int descriptor, void *buf, size_t count, off_t offset) { + return _open_files.get(descriptor)->read(buf, count, offset); } void CryDevice::write(int descriptor, const void *buf, size_t count, off_t offset) { diff --git a/src/cryfs_lib/CryDevice.h b/src/cryfs_lib/CryDevice.h index f5a97e9f..e667a078 100644 --- a/src/cryfs_lib/CryDevice.h +++ b/src/cryfs_lib/CryDevice.h @@ -28,7 +28,7 @@ public: void fstat(int descriptor, struct ::stat *stbuf); void truncate(const bf::path &path, off_t size); void ftruncate(int descriptor, off_t size); - void read(int descriptor, void *buf, size_t count, off_t offset); + int read(int descriptor, void *buf, size_t count, off_t offset); void write(int descriptor, const void *buf, size_t count, off_t offset); void fsync(int descriptor); void fdatasync(int descriptor); diff --git a/src/cryfs_lib/CryOpenFile.cpp b/src/cryfs_lib/CryOpenFile.cpp index 89b330a1..e85f4dc2 100644 --- a/src/cryfs_lib/CryOpenFile.cpp +++ b/src/cryfs_lib/CryOpenFile.cpp @@ -27,14 +27,21 @@ void CryOpenFile::truncate(off_t size) const { CHECK_RETVAL(retval); } -void CryOpenFile::read(void *buf, size_t count, off_t offset) { +int CryOpenFile::read(void *buf, size_t count, off_t offset) { + //printf("Reading from real descriptor %d (%d, %d)\n", _descriptor, offset, count); + //fflush(stdout); int retval = ::pread(_descriptor, buf, count, offset); CHECK_RETVAL(retval); + //printf("retval: %d, count: %d\n", retval, count); + //fflush(stdout); + assert(retval <= count); + return retval; } void CryOpenFile::write(const void *buf, size_t count, off_t offset) { int retval = ::pwrite(_descriptor, buf, count, offset); CHECK_RETVAL(retval); + assert(retval == count); } void CryOpenFile::fsync() { diff --git a/src/cryfs_lib/CryOpenFile.h b/src/cryfs_lib/CryOpenFile.h index 8bd45598..ca71123f 100644 --- a/src/cryfs_lib/CryOpenFile.h +++ b/src/cryfs_lib/CryOpenFile.h @@ -17,7 +17,7 @@ public: void stat(struct ::stat *result) const; void truncate(off_t size) const; - void read(void *buf, size_t count, off_t offset); + int read(void *buf, size_t count, off_t offset); void write(const void *buf, size_t count, off_t offset); void fsync(); void fdatasync();