Work with new fspp
This commit is contained in:
parent
de8c697dfc
commit
0b2bf1d7b3
@ -26,7 +26,7 @@ using blockstore::Key;
|
|||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
CryDir::CryDir(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
|
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() {
|
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) {
|
unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode) {
|
||||||
auto blob = LoadBlob();
|
auto blob = LoadBlob();
|
||||||
auto child = _device->CreateBlob();
|
auto child = device()->CreateBlob();
|
||||||
Key childkey = child->key();
|
Key childkey = child->key();
|
||||||
blob->AddChildFile(name, childkey);
|
blob->AddChildFile(name, childkey);
|
||||||
//TODO Do we need a return value in createDir for fspp? If not, change fspp Dir interface!
|
//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) {
|
void CryDir::createDir(const string &name, mode_t mode) {
|
||||||
auto blob = LoadBlob();
|
auto blob = LoadBlob();
|
||||||
auto child = _device->CreateBlob();
|
auto child = device()->CreateBlob();
|
||||||
Key childkey = child->key();
|
Key childkey = child->key();
|
||||||
blob->AddChildDir(name, childkey);
|
blob->AddChildDir(name, childkey);
|
||||||
DirBlob::InitializeEmptyDir(std::move(child));
|
DirBlob::InitializeEmptyDir(std::move(child));
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<DirBlob> CryDir::LoadBlob() const {
|
unique_ptr<DirBlob> CryDir::LoadBlob() const {
|
||||||
return make_unique<DirBlob>(_device->LoadBlob(_key));
|
return make_unique<DirBlob>(CryNode::LoadBlob());
|
||||||
}
|
|
||||||
|
|
||||||
void CryDir::rmdir() {
|
|
||||||
_parent->RemoveChild(_key);
|
|
||||||
_device->RemoveBlob(_key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
|
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
|
||||||
|
@ -17,16 +17,11 @@ public:
|
|||||||
//TODO return type variance to CryFile/CryDir?
|
//TODO return type variance to CryFile/CryDir?
|
||||||
std::unique_ptr<fspp::OpenFile> createAndOpenFile(const std::string &name, mode_t mode) override;
|
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 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)
|
//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;
|
std::unique_ptr<std::vector<fspp::Dir::Entry>> children() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CryDevice *_device;
|
|
||||||
std::unique_ptr<DirBlob> _parent;
|
|
||||||
blockstore::Key _key;
|
|
||||||
|
|
||||||
std::unique_ptr<DirBlob> LoadBlob() const;
|
std::unique_ptr<DirBlob> LoadBlob() const;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CryDir);
|
DISALLOW_COPY_AND_ASSIGN(CryDir);
|
||||||
|
@ -19,16 +19,14 @@ using blockstore::Key;
|
|||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
CryFile::CryFile(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
|
CryFile::CryFile(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
|
||||||
: _device(device),
|
: CryNode(device, std::move(parent), key) {
|
||||||
_parent(std::move(parent)),
|
|
||||||
_key(key) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CryFile::~CryFile() {
|
CryFile::~CryFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
|
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
|
||||||
auto blob = _device->LoadBlob(_key);
|
auto blob = LoadBlob();
|
||||||
assert(blob.get() != nullptr);
|
assert(blob.get() != nullptr);
|
||||||
return make_unique<CryOpenFile>(make_unique<FileBlob>(std::move(blob)));
|
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 {
|
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.
|
//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;
|
return;
|
||||||
throw FuseErrnoException(ENOTSUP);
|
throw FuseErrnoException(ENOTSUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryFile::truncate(off_t size) const {
|
void CryFile::truncate(off_t size) const {
|
||||||
FileBlob(_device->LoadBlob(_key)).resize(size);
|
FileBlob(LoadBlob()).resize(size);
|
||||||
}
|
|
||||||
|
|
||||||
void CryFile::unlink() {
|
|
||||||
_parent->RemoveChild(_key);
|
|
||||||
_device->RemoveBlob(_key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,8 @@ public:
|
|||||||
void stat(struct ::stat *result) const override;
|
void stat(struct ::stat *result) const override;
|
||||||
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
|
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
|
||||||
void truncate(off_t size) const override;
|
void truncate(off_t size) const override;
|
||||||
void unlink() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CryDevice *_device;
|
|
||||||
std::unique_ptr<DirBlob> _parent;
|
|
||||||
blockstore::Key _key;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CryFile);
|
DISALLOW_COPY_AND_ASSIGN(CryFile);
|
||||||
};
|
};
|
||||||
|
@ -9,13 +9,20 @@
|
|||||||
|
|
||||||
namespace bf = boost::filesystem;
|
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
|
//TODO Get rid of this in favor of an exception hierarchy
|
||||||
using fspp::fuse::CHECK_RETVAL;
|
using fspp::fuse::CHECK_RETVAL;
|
||||||
using fspp::fuse::FuseErrnoException;
|
using fspp::fuse::FuseErrnoException;
|
||||||
|
|
||||||
namespace cryfs {
|
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() {
|
CryNode::~CryNode() {
|
||||||
@ -34,4 +41,21 @@ void CryNode::utimens(const timespec times[2]) {
|
|||||||
throw FuseErrnoException(ENOTSUP);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -11,15 +11,24 @@ namespace cryfs {
|
|||||||
|
|
||||||
class CryNode: public virtual fspp::Node {
|
class CryNode: public virtual fspp::Node {
|
||||||
public:
|
public:
|
||||||
|
CryNode(CryDevice *device, std::unique_ptr<DirBlob> parent, const blockstore::Key &key);
|
||||||
void access(int mask) const override;
|
void access(int mask) const override;
|
||||||
void rename(const boost::filesystem::path &to) override;
|
void rename(const boost::filesystem::path &to) override;
|
||||||
void utimens(const timespec times[2]) override;
|
void utimens(const timespec times[2]) override;
|
||||||
|
void remove() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CryNode();
|
CryNode();
|
||||||
virtual ~CryNode();
|
virtual ~CryNode();
|
||||||
|
|
||||||
|
CryDevice *device();
|
||||||
|
const CryDevice *device() const;
|
||||||
|
std::unique_ptr<blobstore::Blob> LoadBlob() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CryDevice *_device;
|
||||||
|
std::unique_ptr<DirBlob> _parent;
|
||||||
|
blockstore::Key _key;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CryNode);
|
DISALLOW_COPY_AND_ASSIGN(CryNode);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user