libcryfs/src/cryfs/filesystem/CryOpenFile.cpp

72 lines
1.8 KiB
C++
Raw Normal View History

#include "CryOpenFile.h"
#include <sys/types.h>
#include <fcntl.h>
#include "CryDevice.h"
2016-02-11 16:39:42 +01:00
#include <fspp/fuse/FuseErrnoException.h>
namespace bf = boost::filesystem;
using std::shared_ptr;
using cpputils::unique_ref;
using cryfs::parallelaccessfsblobstore::FileBlobRef;
using cryfs::parallelaccessfsblobstore::DirBlobRef;
//TODO Get rid of this in favor of a exception hierarchy
using fspp::fuse::CHECK_RETVAL;
2014-12-07 08:57:23 +01:00
using fspp::fuse::FuseErrnoException;
namespace cryfs {
CryOpenFile::CryOpenFile(const CryDevice *device, shared_ptr<DirBlobRef> parent, unique_ref<FileBlobRef> fileBlob)
: _device(device), _parent(parent), _fileBlob(std::move(fileBlob)) {
}
CryOpenFile::~CryOpenFile() {
2014-12-07 08:57:23 +01:00
//TODO
}
2014-11-21 01:11:24 +01:00
void CryOpenFile::flush() {
_device->callFsActionCallbacks();
2015-04-09 23:42:04 +02:00
_fileBlob->flush();
_parent->flush();
2014-11-21 01:11:24 +01:00
}
void CryOpenFile::stat(struct ::stat *result) const {
_device->callFsActionCallbacks();
_parent->statChildExceptSize(_fileBlob->key(), result);
2015-03-11 00:34:25 +01:00
result->st_size = _fileBlob->size();
}
void CryOpenFile::truncate(off_t size) const {
_device->callFsActionCallbacks();
_fileBlob->resize(size);
_parent->updateModificationTimestampForChild(_fileBlob->key());
}
2015-12-07 12:14:06 +01:00
size_t CryOpenFile::read(void *buf, size_t count, off_t offset) const {
_device->callFsActionCallbacks();
_parent->updateAccessTimestampForChild(_fileBlob->key());
2015-03-11 01:05:37 +01:00
return _fileBlob->read(buf, offset, count);
}
void CryOpenFile::write(const void *buf, size_t count, off_t offset) {
_device->callFsActionCallbacks();
_parent->updateModificationTimestampForChild(_fileBlob->key());
_fileBlob->write(buf, offset, count);
}
void CryOpenFile::fsync() {
_device->callFsActionCallbacks();
_fileBlob->flush();
_parent->flush();
}
void CryOpenFile::fdatasync() {
_device->callFsActionCallbacks();
_fileBlob->flush();
}
2014-12-07 08:57:23 +01:00
}