Work with new fspp

This commit is contained in:
Sebastian Messmer 2015-04-10 23:29:16 +02:00
parent de8c697dfc
commit 0b2bf1d7b3
6 changed files with 43 additions and 31 deletions

View File

@ -26,7 +26,7 @@ using blockstore::Key;
namespace cryfs {
CryDir::CryDir(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
: _device(device), _parent(std::move(parent)), _key(key) {
: CryNode(device, std::move(parent), key) {
}
CryDir::~CryDir() {
@ -40,7 +40,7 @@ void CryDir::stat(struct ::stat *result) const {
unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode) {
auto blob = LoadBlob();
auto child = _device->CreateBlob();
auto child = device()->CreateBlob();
Key childkey = child->key();
blob->AddChildFile(name, childkey);
//TODO Do we need a return value in createDir for fspp? If not, change fspp Dir interface!
@ -50,19 +50,14 @@ unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t
void CryDir::createDir(const string &name, mode_t mode) {
auto blob = LoadBlob();
auto child = _device->CreateBlob();
auto child = device()->CreateBlob();
Key childkey = child->key();
blob->AddChildDir(name, childkey);
DirBlob::InitializeEmptyDir(std::move(child));
}
unique_ptr<DirBlob> CryDir::LoadBlob() const {
return make_unique<DirBlob>(_device->LoadBlob(_key));
}
void CryDir::rmdir() {
_parent->RemoveChild(_key);
_device->RemoveBlob(_key);
return make_unique<DirBlob>(CryNode::LoadBlob());
}
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {

View File

@ -17,16 +17,11 @@ public:
//TODO return type variance to CryFile/CryDir?
std::unique_ptr<fspp::OpenFile> createAndOpenFile(const std::string &name, mode_t mode) override;
void createDir(const std::string &name, mode_t mode) override;
void rmdir() override;
//TODO Make Entry a public class instead of hidden in DirBlob (which is not publicly visible)
std::unique_ptr<std::vector<fspp::Dir::Entry>> children() const override;
private:
CryDevice *_device;
std::unique_ptr<DirBlob> _parent;
blockstore::Key _key;
std::unique_ptr<DirBlob> LoadBlob() const;
DISALLOW_COPY_AND_ASSIGN(CryDir);

View File

@ -19,16 +19,14 @@ using blockstore::Key;
namespace cryfs {
CryFile::CryFile(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
: _device(device),
_parent(std::move(parent)),
_key(key) {
: CryNode(device, std::move(parent), key) {
}
CryFile::~CryFile() {
}
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
auto blob = _device->LoadBlob(_key);
auto blob = LoadBlob();
assert(blob.get() != nullptr);
return make_unique<CryOpenFile>(make_unique<FileBlob>(std::move(blob)));
}
@ -36,18 +34,13 @@ unique_ptr<fspp::OpenFile> 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();
result->st_size = FileBlob(LoadBlob()).size();
return;
throw FuseErrnoException(ENOTSUP);
}
void CryFile::truncate(off_t size) const {
FileBlob(_device->LoadBlob(_key)).resize(size);
}
void CryFile::unlink() {
_parent->RemoveChild(_key);
_device->RemoveBlob(_key);
FileBlob(LoadBlob()).resize(size);
}
}

View File

@ -17,12 +17,8 @@ public:
void stat(struct ::stat *result) const override;
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
void truncate(off_t size) const override;
void unlink() override;
private:
CryDevice *_device;
std::unique_ptr<DirBlob> _parent;
blockstore::Key _key;
DISALLOW_COPY_AND_ASSIGN(CryFile);
};

View File

@ -9,13 +9,20 @@
namespace bf = boost::filesystem;
using std::unique_ptr;
using blockstore::Key;
using blobstore::Blob;
//TODO Get rid of this in favor of an exception hierarchy
using fspp::fuse::CHECK_RETVAL;
using fspp::fuse::FuseErrnoException;
namespace cryfs {
CryNode::CryNode() {
CryNode::CryNode(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
: _device(device),
_parent(std::move(parent)),
_key(key) {
}
CryNode::~CryNode() {
@ -34,4 +41,21 @@ void CryNode::utimens(const timespec times[2]) {
throw FuseErrnoException(ENOTSUP);
}
} /* namespace cryfs */
void CryNode::remove() {
_parent->RemoveChild(_key);
_device->RemoveBlob(_key);
}
CryDevice *CryNode::device() {
return _device;
}
const CryDevice *CryNode::device() const {
return _device;
}
unique_ptr<Blob> CryNode::LoadBlob() const {
return _device->LoadBlob(_key);
}
}

View File

@ -11,15 +11,24 @@ namespace cryfs {
class CryNode: public virtual fspp::Node {
public:
CryNode(CryDevice *device, std::unique_ptr<DirBlob> parent, const blockstore::Key &key);
void access(int mask) const override;
void rename(const boost::filesystem::path &to) override;
void utimens(const timespec times[2]) override;
void remove() override;
protected:
CryNode();
virtual ~CryNode();
CryDevice *device();
const CryDevice *device() const;
std::unique_ptr<blobstore::Blob> LoadBlob() const;
private:
CryDevice *_device;
std::unique_ptr<DirBlob> _parent;
blockstore::Key _key;
DISALLOW_COPY_AND_ASSIGN(CryNode);
};