2014-11-15 16:33:24 +01:00
|
|
|
#include "CryDevice.h"
|
|
|
|
|
|
|
|
#include "CryDir.h"
|
|
|
|
#include "CryFile.h"
|
|
|
|
|
2014-11-28 14:46:45 +01:00
|
|
|
#include "fspp/fuse/FuseErrnoException.h"
|
2014-12-07 10:42:16 +01:00
|
|
|
#include "impl/DirBlob.h"
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
using std::make_unique;
|
2014-12-07 10:42:16 +01:00
|
|
|
using std::string;
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
//TODO Get rid of this in favor of 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;
|
|
|
|
|
|
|
|
using blobstore::BlobStore;
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
namespace cryfs {
|
|
|
|
|
2014-12-07 22:26:16 +01:00
|
|
|
CryDevice::CryDevice(unique_ptr<CryConfig> config, unique_ptr<BlobStore> blobStore)
|
|
|
|
: _blob_store(std::move(blobStore)), _root_key(config->RootBlob()) {
|
|
|
|
if (_root_key == "") {
|
|
|
|
_root_key = CreateRootBlobAndReturnKey();
|
|
|
|
config->SetRootBlob(_root_key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string CryDevice::CreateRootBlobAndReturnKey() {
|
2014-12-07 10:42:16 +01:00
|
|
|
auto rootBlob = _blob_store->create(DIR_BLOBSIZE);
|
|
|
|
DirBlob rootDir(std::move(rootBlob.blob));
|
|
|
|
rootDir.InitializeEmptyDir();
|
2014-12-07 22:26:16 +01:00
|
|
|
return rootBlob.key;
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CryDevice::~CryDevice() {
|
|
|
|
}
|
|
|
|
|
2014-11-16 00:05:28 +01:00
|
|
|
unique_ptr<fspp::Node> CryDevice::Load(const bf::path &path) {
|
2014-12-07 10:42:16 +01:00
|
|
|
printf("Loading %s\n", path.c_str());
|
|
|
|
unique_ptr<DirBlob> currentDir = make_unique<DirBlob>(_blob_store->load(_root_key));
|
|
|
|
assert(path.is_absolute());
|
|
|
|
for (const bf::path &component : path.relative_path()) {
|
|
|
|
printf("Component: %s\n", component.c_str());
|
|
|
|
string childKey = currentDir->GetBlobKeyForName(component.c_str());
|
|
|
|
currentDir = make_unique<DirBlob>(_blob_store->load(childKey));
|
|
|
|
}
|
|
|
|
return make_unique<CryDir>(this, std::move(currentDir));
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
|
2014-12-07 08:57:23 +01:00
|
|
|
throw FuseErrnoException(ENOTSUP);
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 10:42:16 +01:00
|
|
|
blobstore::BlobWithKey CryDevice::CreateBlob(size_t size) {
|
|
|
|
return _blob_store->create(size);
|
|
|
|
}
|
|
|
|
|
2014-12-07 08:57:23 +01:00
|
|
|
}
|