From 28056ed43fbe29eae7877541fc8aeef48a0311ef Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Wed, 11 Mar 2015 00:34:25 +0100 Subject: [PATCH] Fix file size handling --- CryFile.cpp | 4 +++- CryOpenFile.cpp | 7 ++++--- impl/FileBlob.cpp | 6 +++++- impl/FileBlob.h | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CryFile.cpp b/CryFile.cpp index 36ab6d9b..8cb5b580 100644 --- a/CryFile.cpp +++ b/CryFile.cpp @@ -33,12 +33,14 @@ unique_ptr CryFile::open(int flags) const { void CryFile::stat(struct ::stat *result) const { result->st_mode = S_IFREG | S_IRUSR | S_IXUSR | S_IWUSR; + //TODO Loading the blob for only getting the size is not very performant. + result->st_size = FileBlob(_device->LoadBlob(_key)).size(); return; throw FuseErrnoException(ENOTSUP); } void CryFile::truncate(off_t size) const { - throw FuseErrnoException(ENOTSUP); + FileBlob(_device->LoadBlob(_key)).resize(size); } void CryFile::unlink() { diff --git a/CryOpenFile.cpp b/CryOpenFile.cpp index 41275ec9..34224ea9 100644 --- a/CryOpenFile.cpp +++ b/CryOpenFile.cpp @@ -27,11 +27,12 @@ CryOpenFile::~CryOpenFile() { } void CryOpenFile::flush() { - throw FuseErrnoException(ENOTSUP); + //throw FuseErrnoException(ENOTSUP); } void CryOpenFile::stat(struct ::stat *result) const { result->st_mode = S_IFREG | S_IRUSR | S_IXUSR | S_IWUSR; + result->st_size = _fileBlob->size(); return; } @@ -50,11 +51,11 @@ void CryOpenFile::write(const void *buf, size_t count, off_t offset) { } void CryOpenFile::fsync() { - throw FuseErrnoException(ENOTSUP); + //throw FuseErrnoException(ENOTSUP); } void CryOpenFile::fdatasync() { - throw FuseErrnoException(ENOTSUP); + //throw FuseErrnoException(ENOTSUP); } } diff --git a/impl/FileBlob.cpp b/impl/FileBlob.cpp index 6dd9e993..2e55a00c 100644 --- a/impl/FileBlob.cpp +++ b/impl/FileBlob.cpp @@ -42,7 +42,11 @@ blockstore::Key FileBlob::key() const { } void FileBlob::resize(off_t size) { - _blob->resize(size); + _blob->resize(size+1); +} + +off_t FileBlob::size() const { + return _blob->size()-1; } } diff --git a/impl/FileBlob.h b/impl/FileBlob.h index 7adc9526..dc055804 100644 --- a/impl/FileBlob.h +++ b/impl/FileBlob.h @@ -18,6 +18,7 @@ public: void write(const void *source, uint64_t offset, uint64_t count); void resize(off_t size); + off_t size() const; blockstore::Key key() const;