2014-11-15 16:33:24 +01:00
|
|
|
#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>
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
2016-03-16 16:57:46 +00:00
|
|
|
using std::shared_ptr;
|
2015-06-18 13:14:43 +02:00
|
|
|
using cpputils::unique_ref;
|
2015-10-04 17:20:14 +02:00
|
|
|
using cryfs::parallelaccessfsblobstore::FileBlobRef;
|
2016-03-16 16:57:46 +00:00
|
|
|
using cryfs::parallelaccessfsblobstore::DirBlobRef;
|
2015-03-08 03:51:19 +01:00
|
|
|
|
2014-11-15 16:33:24 +01:00
|
|
|
//TODO Get rid of this in favor of a exception hierarchy
|
2014-11-28 14:46:45 +01:00
|
|
|
using fspp::fuse::CHECK_RETVAL;
|
2014-12-07 08:57:23 +01:00
|
|
|
using fspp::fuse::FuseErrnoException;
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
namespace cryfs {
|
|
|
|
|
2016-06-07 21:25:02 -07:00
|
|
|
CryOpenFile::CryOpenFile(const CryDevice *device, shared_ptr<DirBlobRef> parent, unique_ref<FileBlobRef> fileBlob)
|
2016-03-16 16:57:46 +00:00
|
|
|
: _device(device), _parent(parent), _fileBlob(std::move(fileBlob)) {
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CryOpenFile::~CryOpenFile() {
|
2014-12-07 08:57:23 +01:00
|
|
|
//TODO
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-21 01:11:24 +01:00
|
|
|
void CryOpenFile::flush() {
|
2015-11-12 15:06:53 -08:00
|
|
|
_device->callFsActionCallbacks();
|
2015-04-09 23:42:04 +02:00
|
|
|
_fileBlob->flush();
|
2016-06-09 17:32:35 -07:00
|
|
|
_parent->flush();
|
2014-11-21 01:11:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-15 16:33:24 +01:00
|
|
|
void CryOpenFile::stat(struct ::stat *result) const {
|
2015-11-12 15:06:53 -08:00
|
|
|
_device->callFsActionCallbacks();
|
2016-03-16 16:57:46 +00:00
|
|
|
_parent->statChildExceptSize(_fileBlob->key(), result);
|
2015-03-11 00:34:25 +01:00
|
|
|
result->st_size = _fileBlob->size();
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CryOpenFile::truncate(off_t size) const {
|
2015-11-12 15:06:53 -08:00
|
|
|
_device->callFsActionCallbacks();
|
2015-03-11 00:23:52 +01:00
|
|
|
_fileBlob->resize(size);
|
2016-06-07 21:25:02 -07:00
|
|
|
_parent->updateModificationTimestampForChild(_fileBlob->key());
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2015-12-07 12:14:06 +01:00
|
|
|
size_t CryOpenFile::read(void *buf, size_t count, off_t offset) const {
|
2015-11-12 15:06:53 -08:00
|
|
|
_device->callFsActionCallbacks();
|
2016-06-07 21:25:02 -07:00
|
|
|
_parent->updateAccessTimestampForChild(_fileBlob->key());
|
2015-03-11 01:05:37 +01:00
|
|
|
return _fileBlob->read(buf, offset, count);
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CryOpenFile::write(const void *buf, size_t count, off_t offset) {
|
2015-11-12 15:06:53 -08:00
|
|
|
_device->callFsActionCallbacks();
|
2016-06-07 21:25:02 -07:00
|
|
|
_parent->updateModificationTimestampForChild(_fileBlob->key());
|
2015-03-08 03:51:19 +01:00
|
|
|
_fileBlob->write(buf, offset, count);
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CryOpenFile::fsync() {
|
2015-11-12 15:06:53 -08:00
|
|
|
_device->callFsActionCallbacks();
|
2016-06-07 18:36:59 -07:00
|
|
|
_fileBlob->flush();
|
2016-06-09 17:32:35 -07:00
|
|
|
_parent->flush();
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CryOpenFile::fdatasync() {
|
2015-11-12 15:06:53 -08:00
|
|
|
_device->callFsActionCallbacks();
|
2016-06-07 18:36:59 -07:00
|
|
|
_fileBlob->flush();
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 08:57:23 +01:00
|
|
|
}
|