Fix file size handling

This commit is contained in:
Sebastian Messmer 2015-03-11 00:34:25 +01:00
parent 75b9a29ae4
commit 28056ed43f
4 changed files with 13 additions and 5 deletions

View File

@ -33,12 +33,14 @@ unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
void CryFile::stat(struct ::stat *result) const { void CryFile::stat(struct ::stat *result) const {
result->st_mode = S_IFREG | S_IRUSR | S_IXUSR | S_IWUSR; 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; return;
throw FuseErrnoException(ENOTSUP); throw FuseErrnoException(ENOTSUP);
} }
void CryFile::truncate(off_t size) const { void CryFile::truncate(off_t size) const {
throw FuseErrnoException(ENOTSUP); FileBlob(_device->LoadBlob(_key)).resize(size);
} }
void CryFile::unlink() { void CryFile::unlink() {

View File

@ -27,11 +27,12 @@ CryOpenFile::~CryOpenFile() {
} }
void CryOpenFile::flush() { void CryOpenFile::flush() {
throw FuseErrnoException(ENOTSUP); //throw FuseErrnoException(ENOTSUP);
} }
void CryOpenFile::stat(struct ::stat *result) const { void CryOpenFile::stat(struct ::stat *result) const {
result->st_mode = S_IFREG | S_IRUSR | S_IXUSR | S_IWUSR; result->st_mode = S_IFREG | S_IRUSR | S_IXUSR | S_IWUSR;
result->st_size = _fileBlob->size();
return; return;
} }
@ -50,11 +51,11 @@ void CryOpenFile::write(const void *buf, size_t count, off_t offset) {
} }
void CryOpenFile::fsync() { void CryOpenFile::fsync() {
throw FuseErrnoException(ENOTSUP); //throw FuseErrnoException(ENOTSUP);
} }
void CryOpenFile::fdatasync() { void CryOpenFile::fdatasync() {
throw FuseErrnoException(ENOTSUP); //throw FuseErrnoException(ENOTSUP);
} }
} }

View File

@ -42,7 +42,11 @@ blockstore::Key FileBlob::key() const {
} }
void FileBlob::resize(off_t size) { void FileBlob::resize(off_t size) {
_blob->resize(size); _blob->resize(size+1);
}
off_t FileBlob::size() const {
return _blob->size()-1;
} }
} }

View File

@ -18,6 +18,7 @@ public:
void write(const void *source, uint64_t offset, uint64_t count); void write(const void *source, uint64_t offset, uint64_t count);
void resize(off_t size); void resize(off_t size);
off_t size() const;
blockstore::Key key() const; blockstore::Key key() const;