Adapt to new blobstore - having unique_ref<Blob> instead of unique_ptr<Blob>
This commit is contained in:
parent
09f89327da
commit
b2e661a328
@ -27,6 +27,8 @@ using blockstore::encrypted::AES256_CFB;
|
|||||||
using blobstore::onblocks::BlobStoreOnBlocks;
|
using blobstore::onblocks::BlobStoreOnBlocks;
|
||||||
using blobstore::onblocks::BlobOnBlocks;
|
using blobstore::onblocks::BlobOnBlocks;
|
||||||
using blockstore::caching::CachingBlockStore;
|
using blockstore::caching::CachingBlockStore;
|
||||||
|
using cpputils::unique_ref;
|
||||||
|
using boost::optional;
|
||||||
|
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
@ -87,34 +89,47 @@ unique_ptr<fspp::Node> CryDevice::Load(const bf::path &path) {
|
|||||||
|
|
||||||
unique_ptr<DirBlob> CryDevice::LoadDirBlob(const bf::path &path) {
|
unique_ptr<DirBlob> CryDevice::LoadDirBlob(const bf::path &path) {
|
||||||
auto currentBlob = _blobStore->load(_rootKey);
|
auto currentBlob = _blobStore->load(_rootKey);
|
||||||
|
if(!currentBlob) {
|
||||||
|
//TODO Return correct fuse error
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
for (const bf::path &component : path.relative_path()) {
|
for (const bf::path &component : path.relative_path()) {
|
||||||
//TODO Check whether the next path component is a dir.
|
//TODO Check whether the next path component is a dir.
|
||||||
// Right now, an assertion in DirBlob constructor will fail if it isn't.
|
// Right now, an assertion in DirBlob constructor will fail if it isn't.
|
||||||
// But fuse should rather return the correct error code.
|
// But fuse should rather return the correct error code.
|
||||||
unique_ptr<DirBlob> currentDir = make_unique<DirBlob>(std::move(currentBlob), this);
|
unique_ptr<DirBlob> currentDir = make_unique<DirBlob>(std::move(*currentBlob), this);
|
||||||
|
|
||||||
Key childKey = currentDir->GetChild(component.c_str()).key;
|
Key childKey = currentDir->GetChild(component.c_str()).key;
|
||||||
currentBlob = _blobStore->load(childKey);
|
currentBlob = _blobStore->load(childKey);
|
||||||
|
if(!currentBlob) {
|
||||||
|
//TODO Return correct fuse error
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_unique<DirBlob>(std::move(currentBlob), this);
|
return make_unique<DirBlob>(std::move(*currentBlob), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
|
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
|
||||||
throw FuseErrnoException(ENOTSUP);
|
throw FuseErrnoException(ENOTSUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<blobstore::Blob> CryDevice::CreateBlob() {
|
unique_ref<blobstore::Blob> CryDevice::CreateBlob() {
|
||||||
return _blobStore->create();
|
return _blobStore->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<blobstore::Blob> CryDevice::LoadBlob(const blockstore::Key &key) {
|
optional<unique_ref<blobstore::Blob>> CryDevice::LoadBlob(const blockstore::Key &key) {
|
||||||
return _blobStore->load(key);
|
return _blobStore->load(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryDevice::RemoveBlob(const blockstore::Key &key) {
|
void CryDevice::RemoveBlob(const blockstore::Key &key) {
|
||||||
_blobStore->remove(_blobStore->load(key));
|
auto blob = _blobStore->load(key);
|
||||||
|
if(blob) {
|
||||||
|
_blobStore->remove(std::move(*blob));
|
||||||
|
} else {
|
||||||
|
//TODO Log error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ public:
|
|||||||
|
|
||||||
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
||||||
|
|
||||||
std::unique_ptr<blobstore::Blob> CreateBlob();
|
cpputils::unique_ref<blobstore::Blob> CreateBlob();
|
||||||
std::unique_ptr<blobstore::Blob> LoadBlob(const blockstore::Key &key);
|
boost::optional<cpputils::unique_ref<blobstore::Blob>> LoadBlob(const blockstore::Key &key);
|
||||||
void RemoveBlob(const blockstore::Key &key);
|
void RemoveBlob(const blockstore::Key &key);
|
||||||
|
|
||||||
std::unique_ptr<fspp::Node> Load(const boost::filesystem::path &path) override;
|
std::unique_ptr<fspp::Node> Load(const boost::filesystem::path &path) override;
|
||||||
|
@ -23,6 +23,9 @@ using std::string;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
using blockstore::Key;
|
using blockstore::Key;
|
||||||
|
using cpputils::unique_ref;
|
||||||
|
using boost::optional;
|
||||||
|
using boost::none;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
@ -52,8 +55,12 @@ void CryDir::createDir(const string &name, mode_t mode, uid_t uid, gid_t gid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<DirBlob> CryDir::LoadBlob() const {
|
unique_ptr<DirBlob> CryDir::LoadBlob() const {
|
||||||
|
auto blob = CryNode::LoadBlob();
|
||||||
|
if(blob == none) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
//TODO Without const_cast?
|
//TODO Without const_cast?
|
||||||
return make_unique<DirBlob>(CryNode::LoadBlob(), const_cast<CryDevice*>(device()));
|
return make_unique<DirBlob>(std::move(*blob), const_cast<CryDevice*>(device()));
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
|
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
|
||||||
|
@ -15,6 +15,7 @@ using std::unique_ptr;
|
|||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
|
|
||||||
using blockstore::Key;
|
using blockstore::Key;
|
||||||
|
using boost::none;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
@ -27,12 +28,17 @@ CryFile::~CryFile() {
|
|||||||
|
|
||||||
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
|
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
|
||||||
auto blob = LoadBlob();
|
auto blob = LoadBlob();
|
||||||
assert(blob.get() != nullptr);
|
assert(blob != none);
|
||||||
return make_unique<CryOpenFile>(make_unique<FileBlob>(std::move(blob)));
|
return make_unique<CryOpenFile>(make_unique<FileBlob>(std::move(*blob)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryFile::truncate(off_t size) const {
|
void CryFile::truncate(off_t size) const {
|
||||||
FileBlob(LoadBlob()).resize(size);
|
auto blob = LoadBlob();
|
||||||
|
if (blob == none) {
|
||||||
|
//TODO Log error
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FileBlob(std::move(*blob)).resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
fspp::Dir::EntryType CryFile::getType() const {
|
fspp::Dir::EntryType CryFile::getType() const {
|
||||||
|
@ -14,6 +14,8 @@ using std::unique_ptr;
|
|||||||
using blockstore::Key;
|
using blockstore::Key;
|
||||||
using blobstore::Blob;
|
using blobstore::Blob;
|
||||||
using cpputils::dynamic_pointer_move;
|
using cpputils::dynamic_pointer_move;
|
||||||
|
using cpputils::unique_ref;
|
||||||
|
using boost::optional;
|
||||||
|
|
||||||
//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;
|
||||||
@ -67,7 +69,7 @@ const CryDevice *CryNode::device() const {
|
|||||||
return _device;
|
return _device;
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<Blob> CryNode::LoadBlob() const {
|
optional<unique_ref<Blob>> CryNode::LoadBlob() const {
|
||||||
return _device->LoadBlob(_key);
|
return _device->LoadBlob(_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ protected:
|
|||||||
|
|
||||||
CryDevice *device();
|
CryDevice *device();
|
||||||
const CryDevice *device() const;
|
const CryDevice *device() const;
|
||||||
std::unique_ptr<blobstore::Blob> LoadBlob() const;
|
boost::optional<cpputils::unique_ref<blobstore::Blob>> LoadBlob() const;
|
||||||
|
|
||||||
virtual fspp::Dir::EntryType getType() const = 0;
|
virtual fspp::Dir::EntryType getType() const = 0;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ using std::string;
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
using blockstore::Key;
|
using blockstore::Key;
|
||||||
|
using boost::none;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
@ -28,7 +29,11 @@ CrySymlink::~CrySymlink() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<SymlinkBlob> CrySymlink::LoadBlob() const {
|
unique_ptr<SymlinkBlob> CrySymlink::LoadBlob() const {
|
||||||
return make_unique<SymlinkBlob>(CryNode::LoadBlob());
|
auto blob = CryNode::LoadBlob();
|
||||||
|
if (blob == none) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return make_unique<SymlinkBlob>(std::move(*blob));
|
||||||
}
|
}
|
||||||
|
|
||||||
fspp::Dir::EntryType CrySymlink::getType() const {
|
fspp::Dir::EntryType CrySymlink::getType() const {
|
||||||
|
@ -21,11 +21,14 @@ using std::make_pair;
|
|||||||
using blobstore::Blob;
|
using blobstore::Blob;
|
||||||
using blockstore::Key;
|
using blockstore::Key;
|
||||||
using cpputils::Data;
|
using cpputils::Data;
|
||||||
|
using cpputils::unique_ref;
|
||||||
|
using boost::none;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
DirBlob::DirBlob(unique_ptr<Blob> blob, CryDevice *device) :
|
DirBlob::DirBlob(unique_ref<Blob> blob, CryDevice *device) :
|
||||||
_device(device), _blob(std::move(blob)), _entries(), _changed(false) {
|
_device(device), _blob(std::move(blob)), _entries(), _changed(false) {
|
||||||
|
//TODO generally everywhere: asserts are bad, because they crash the filesystem. Rather return a fuse error!
|
||||||
assert(magicNumber() == MagicNumbers::DIR);
|
assert(magicNumber() == MagicNumbers::DIR);
|
||||||
_readEntriesFromBlob();
|
_readEntriesFromBlob();
|
||||||
}
|
}
|
||||||
@ -39,7 +42,7 @@ void DirBlob::flush() {
|
|||||||
_blob->flush();
|
_blob->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<DirBlob> DirBlob::InitializeEmptyDir(unique_ptr<Blob> blob, CryDevice *device) {
|
unique_ptr<DirBlob> DirBlob::InitializeEmptyDir(unique_ref<Blob> blob, CryDevice *device) {
|
||||||
blob->resize(1);
|
blob->resize(1);
|
||||||
unsigned char magicNumber = MagicNumbers::DIR;
|
unsigned char magicNumber = MagicNumbers::DIR;
|
||||||
blob->write(&magicNumber, 0, 1);
|
blob->write(&magicNumber, 0, 1);
|
||||||
@ -204,13 +207,23 @@ void DirBlob::statChild(const Key &key, struct ::stat *result) const {
|
|||||||
//TODO Handle file access times
|
//TODO Handle file access times
|
||||||
result->st_mtime = result->st_ctime = result->st_atime = 0;
|
result->st_mtime = result->st_ctime = result->st_atime = 0;
|
||||||
if (child.type == fspp::Dir::EntryType::FILE) {
|
if (child.type == fspp::Dir::EntryType::FILE) {
|
||||||
result->st_size = FileBlob(_device->LoadBlob(key)).size();
|
auto blob = _device->LoadBlob(key);
|
||||||
|
if (blob == none) {
|
||||||
|
//TODO Log error
|
||||||
|
} else {
|
||||||
|
result->st_size = FileBlob(std::move(*blob)).size();
|
||||||
|
}
|
||||||
} else if (child.type == fspp::Dir::EntryType::DIR) {
|
} else if (child.type == fspp::Dir::EntryType::DIR) {
|
||||||
//TODO Why do dirs have 4096 bytes in size? Does that make sense?
|
//TODO Why do dirs have 4096 bytes in size? Does that make sense?
|
||||||
result->st_size = 4096;
|
result->st_size = 4096;
|
||||||
} else if (child.type == fspp::Dir::EntryType::SYMLINK) {
|
} else if (child.type == fspp::Dir::EntryType::SYMLINK) {
|
||||||
//TODO Necessary with fuse or does fuse set this on symlinks anyhow?
|
//TODO Necessary with fuse or does fuse set this on symlinks anyhow?
|
||||||
result->st_size = SymlinkBlob(_device->LoadBlob(key)).target().native().size();
|
auto blob = _device->LoadBlob(key);
|
||||||
|
if (blob == none) {
|
||||||
|
//TODO Log error
|
||||||
|
} else {
|
||||||
|
result->st_size = SymlinkBlob(std::move(*blob)).target().native().size();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
#include <messmer/blobstore/interface/Blob.h>
|
#include <messmer/blobstore/interface/Blob.h>
|
||||||
#include <messmer/blockstore/utils/Key.h>
|
#include <messmer/blockstore/utils/Key.h>
|
||||||
#include "messmer/cpp-utils/macros.h"
|
#include <messmer/cpp-utils/macros.h>
|
||||||
#include <messmer/fspp/fs_interface/Dir.h>
|
#include <messmer/fspp/fs_interface/Dir.h>
|
||||||
|
#include <messmer/cpp-utils/unique_ref.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -39,9 +40,9 @@ public:
|
|||||||
gid_t gid;
|
gid_t gid;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::unique_ptr<DirBlob> InitializeEmptyDir(std::unique_ptr<blobstore::Blob> blob, CryDevice *device);
|
static std::unique_ptr<DirBlob> InitializeEmptyDir(cpputils::unique_ref<blobstore::Blob> blob, CryDevice *device);
|
||||||
|
|
||||||
DirBlob(std::unique_ptr<blobstore::Blob> blob, CryDevice *device);
|
DirBlob(cpputils::unique_ref<blobstore::Blob> blob, CryDevice *device);
|
||||||
virtual ~DirBlob();
|
virtual ~DirBlob();
|
||||||
|
|
||||||
void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const;
|
void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const;
|
||||||
@ -70,7 +71,7 @@ private:
|
|||||||
std::vector<DirBlob::Entry>::iterator _findChild(const blockstore::Key &key);
|
std::vector<DirBlob::Entry>::iterator _findChild(const blockstore::Key &key);
|
||||||
|
|
||||||
CryDevice *_device;
|
CryDevice *_device;
|
||||||
std::unique_ptr<blobstore::Blob> _blob;
|
cpputils::unique_ref<blobstore::Blob> _blob;
|
||||||
std::vector<Entry> _entries;
|
std::vector<Entry> _entries;
|
||||||
bool _changed;
|
bool _changed;
|
||||||
|
|
||||||
|
@ -7,17 +7,18 @@
|
|||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
using blobstore::Blob;
|
using blobstore::Blob;
|
||||||
|
using cpputils::unique_ref;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
FileBlob::FileBlob(unique_ptr<Blob> blob)
|
FileBlob::FileBlob(unique_ref<Blob> blob)
|
||||||
: _blob(std::move(blob)) {
|
: _blob(std::move(blob)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileBlob::~FileBlob() {
|
FileBlob::~FileBlob() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<FileBlob> FileBlob::InitializeEmptyFile(unique_ptr<Blob> blob) {
|
unique_ptr<FileBlob> FileBlob::InitializeEmptyFile(unique_ref<Blob> blob) {
|
||||||
assert(blob.get() != nullptr);
|
assert(blob.get() != nullptr);
|
||||||
blob->resize(1);
|
blob->resize(1);
|
||||||
unsigned char magicNumber = MagicNumbers::FILE;
|
unsigned char magicNumber = MagicNumbers::FILE;
|
||||||
|
@ -3,15 +3,16 @@
|
|||||||
#define CRYFS_LIB_IMPL_FILEBLOB_H_
|
#define CRYFS_LIB_IMPL_FILEBLOB_H_
|
||||||
|
|
||||||
#include <messmer/blobstore/interface/Blob.h>
|
#include <messmer/blobstore/interface/Blob.h>
|
||||||
|
#include <messmer/cpp-utils/unique_ref.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
class FileBlob {
|
class FileBlob {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<FileBlob> InitializeEmptyFile(std::unique_ptr<blobstore::Blob> blob);
|
static std::unique_ptr<FileBlob> InitializeEmptyFile(cpputils::unique_ref<blobstore::Blob> blob);
|
||||||
|
|
||||||
FileBlob(std::unique_ptr<blobstore::Blob> blob);
|
FileBlob(cpputils::unique_ref<blobstore::Blob> blob);
|
||||||
virtual ~FileBlob();
|
virtual ~FileBlob();
|
||||||
|
|
||||||
ssize_t read(void *target, uint64_t offset, uint64_t count) const;
|
ssize_t read(void *target, uint64_t offset, uint64_t count) const;
|
||||||
@ -24,7 +25,7 @@ public:
|
|||||||
blockstore::Key key() const;
|
blockstore::Key key() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<blobstore::Blob> _blob;
|
cpputils::unique_ref<blobstore::Blob> _blob;
|
||||||
|
|
||||||
unsigned char magicNumber() const;
|
unsigned char magicNumber() const;
|
||||||
};
|
};
|
||||||
|
@ -8,12 +8,13 @@ using std::unique_ptr;
|
|||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
using std::string;
|
using std::string;
|
||||||
using blobstore::Blob;
|
using blobstore::Blob;
|
||||||
|
using cpputils::unique_ref;
|
||||||
|
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
SymlinkBlob::SymlinkBlob(unique_ptr<Blob> blob)
|
SymlinkBlob::SymlinkBlob(unique_ref<Blob> blob)
|
||||||
: _target(_readTargetFromBlob(*blob)) {
|
: _target(_readTargetFromBlob(*blob)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ SymlinkBlob::SymlinkBlob(const bf::path &target) :_target(target) {
|
|||||||
SymlinkBlob::~SymlinkBlob() {
|
SymlinkBlob::~SymlinkBlob() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<SymlinkBlob> SymlinkBlob::InitializeSymlink(unique_ptr<Blob> blob, const bf::path &target) {
|
unique_ptr<SymlinkBlob> SymlinkBlob::InitializeSymlink(unique_ref<Blob> blob, const bf::path &target) {
|
||||||
assert(blob.get() != nullptr);
|
assert(blob.get() != nullptr);
|
||||||
string targetStr = target.native();
|
string targetStr = target.native();
|
||||||
blob->resize(1 + targetStr.size());
|
blob->resize(1 + targetStr.size());
|
||||||
|
@ -5,14 +5,15 @@
|
|||||||
#include <messmer/blobstore/interface/Blob.h>
|
#include <messmer/blobstore/interface/Blob.h>
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <messmer/cpp-utils/unique_ref.h>
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
class SymlinkBlob {
|
class SymlinkBlob {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<SymlinkBlob> InitializeSymlink(std::unique_ptr<blobstore::Blob> blob, const boost::filesystem::path &target);
|
static std::unique_ptr<SymlinkBlob> InitializeSymlink(cpputils::unique_ref<blobstore::Blob> blob, const boost::filesystem::path &target);
|
||||||
|
|
||||||
SymlinkBlob(std::unique_ptr<blobstore::Blob> blob);
|
SymlinkBlob(cpputils::unique_ref<blobstore::Blob> blob);
|
||||||
SymlinkBlob(const boost::filesystem::path &target);
|
SymlinkBlob(const boost::filesystem::path &target);
|
||||||
virtual ~SymlinkBlob();
|
virtual ~SymlinkBlob();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user