libcryfs/CryFile.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

#include "CryFile.h"
#include "CryDevice.h"
#include "CryOpenFile.h"
2015-02-17 01:02:15 +01:00
#include "messmer/fspp/fuse/FuseErrnoException.h"
#include "impl/DirBlob.h"
namespace bf = boost::filesystem;
//TODO Get rid of this in favor of exception hierarchy
using fspp::fuse::CHECK_RETVAL;
2014-12-07 08:57:23 +01:00
using fspp::fuse::FuseErrnoException;
using std::unique_ptr;
using std::make_unique;
using blockstore::Key;
namespace cryfs {
CryFile::CryFile(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
: _device(device),
_parent(std::move(parent)),
_key(key) {
}
CryFile::~CryFile() {
}
2014-11-16 00:05:28 +01:00
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
return make_unique<CryOpenFile>(make_unique<FileBlob>(_device->LoadBlob(_key)));
}
2015-03-08 03:25:20 +01:00
void CryFile::stat(struct ::stat *result) const {
result->st_mode = S_IFREG | S_IRUSR | S_IXUSR | S_IWUSR;
2015-03-11 00:34:25 +01:00
//TODO Loading the blob for only getting the size is not very performant.
result->st_size = FileBlob(_device->LoadBlob(_key)).size();
2015-03-08 03:25:20 +01:00
return;
throw FuseErrnoException(ENOTSUP);
}
void CryFile::truncate(off_t size) const {
2015-03-11 00:34:25 +01:00
FileBlob(_device->LoadBlob(_key)).resize(size);
}
void CryFile::unlink() {
2014-12-07 08:57:23 +01:00
throw FuseErrnoException(ENOTSUP);
}
2014-12-07 08:57:23 +01:00
}