Use VersionCountingBlockStore
This commit is contained in:
parent
13411c4e59
commit
a5391a854d
@ -32,6 +32,7 @@ set(SOURCES
|
||||
assert/backtrace.cpp
|
||||
assert/AssertFailed.cpp
|
||||
system/get_total_memory.cpp
|
||||
system/homedir.cpp
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${SOURCES})
|
||||
|
25
src/cpp-utils/system/homedir.cpp
Normal file
25
src/cpp-utils/system/homedir.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "homedir.h"
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
using std::string;
|
||||
|
||||
namespace cpputils {
|
||||
namespace system {
|
||||
bf::path home_directory() {
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
string homedir;
|
||||
if (pwd) {
|
||||
homedir = pwd->pw_dir;
|
||||
} else {
|
||||
// try the $HOME environment variable
|
||||
homedir = getenv("HOME");
|
||||
}
|
||||
if (homedir == "") {
|
||||
throw std::runtime_error("Couldn't determine home directory for user");
|
||||
}
|
||||
return homedir;
|
||||
}
|
||||
}
|
||||
}
|
15
src/cpp-utils/system/homedir.h
Normal file
15
src/cpp-utils/system/homedir.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#ifndef MESSMER_CPPUTILS_SYSTEM_GETTOTALMEMORY_H
|
||||
#define MESSMER_CPPUTILS_SYSTEM_GETTOTALMEMORY_H
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace cpputils {
|
||||
namespace system {
|
||||
|
||||
boost::filesystem::path home_directory();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -11,9 +11,11 @@
|
||||
#include <blobstore/implementations/onblocks/BlobStoreOnBlocks.h>
|
||||
#include <blobstore/implementations/onblocks/BlobOnBlocks.h>
|
||||
#include <blockstore/implementations/encrypted/EncryptedBlockStore.h>
|
||||
#include <blockstore/implementations/versioncounting/VersionCountingBlockStore.h>
|
||||
#include "parallelaccessfsblobstore/ParallelAccessFsBlobStore.h"
|
||||
#include "cachingfsblobstore/CachingFsBlobStore.h"
|
||||
#include "../config/CryCipher.h"
|
||||
#include <cpp-utils/system/homedir.h>
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -27,6 +29,7 @@ using blockstore::encrypted::EncryptedBlockStore;
|
||||
using blobstore::onblocks::BlobStoreOnBlocks;
|
||||
using blobstore::onblocks::BlobOnBlocks;
|
||||
using blockstore::caching::CachingBlockStore;
|
||||
using blockstore::versioncounting::VersionCountingBlockStore;
|
||||
using cpputils::unique_ref;
|
||||
using cpputils::make_unique_ref;
|
||||
using cpputils::dynamic_pointer_move;
|
||||
@ -52,10 +55,16 @@ CryDevice::CryDevice(CryConfigFile configFile, unique_ref<BlockStore> blockStore
|
||||
make_unique_ref<FsBlobStore>(
|
||||
make_unique_ref<BlobStoreOnBlocks>(
|
||||
make_unique_ref<CachingBlockStore>(
|
||||
CreateEncryptedBlockStore(*configFile.config(), std::move(blockStore))
|
||||
), configFile.config()->BlocksizeBytes())))
|
||||
make_unique_ref<VersionCountingBlockStore>(
|
||||
CreateEncryptedBlockStore(*configFile.config(), std::move(blockStore)),
|
||||
_integrityFilePath(configFile.config()->FilesystemId())
|
||||
)
|
||||
)
|
||||
, configFile.config()->BlocksizeBytes())
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
_rootKey(GetOrCreateRootKey(&configFile)),
|
||||
_onFsAction() {
|
||||
}
|
||||
@ -66,6 +75,22 @@ Key CryDevice::CreateRootBlobAndReturnKey() {
|
||||
return rootBlob->key();
|
||||
}
|
||||
|
||||
bf::path CryDevice::_integrityFilePath(const CryConfig::FilesystemID &filesystemId) {
|
||||
bf::path app_dir = cpputils::system::home_directory() / ".cryfs";
|
||||
_createDirIfNotExists(app_dir);
|
||||
bf::path filesystems_dir = app_dir / "filesystems";
|
||||
_createDirIfNotExists(filesystems_dir);
|
||||
bf::path this_filesystem_dir = filesystems_dir / filesystemId.ToString();
|
||||
_createDirIfNotExists(this_filesystem_dir);
|
||||
return this_filesystem_dir / "integritydata.knownblockversions";
|
||||
}
|
||||
|
||||
void CryDevice::_createDirIfNotExists(const bf::path &path) {
|
||||
if (!bf::exists(path)) {
|
||||
bf::create_directory(path);
|
||||
}
|
||||
}
|
||||
|
||||
optional<unique_ref<fspp::Node>> CryDevice::Load(const bf::path &path) {
|
||||
// TODO Split into smaller functions
|
||||
ASSERT(path.is_absolute(), "Non absolute path given");
|
||||
|
@ -47,6 +47,9 @@ private:
|
||||
blockstore::Key _rootKey;
|
||||
std::vector<std::function<void()>> _onFsAction;
|
||||
|
||||
static boost::filesystem::path _integrityFilePath(const CryConfig::FilesystemID &filesystemId);
|
||||
static void _createDirIfNotExists(const boost::filesystem::path &path);
|
||||
|
||||
blockstore::Key GetOrCreateRootKey(CryConfigFile *config);
|
||||
blockstore::Key CreateRootBlobAndReturnKey();
|
||||
static cpputils::unique_ref<blockstore::BlockStore> CreateEncryptedBlockStore(const CryConfig &config, cpputils::unique_ref<blockstore::BlockStore> baseBlockStore);
|
||||
|
Loading…
Reference in New Issue
Block a user