Rename blobstore to blockstore
This commit is contained in:
parent
ebc70cff53
commit
e757da0ad3
@ -1,3 +1,3 @@
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryConfig.cpp impl/DirBlob.cpp impl/FileBlob.cpp)
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryConfig.cpp impl/DirBlock.cpp impl/FileBlock.cpp)
|
||||
|
||||
target_link_libraries(cryfs_lib)
|
||||
|
@ -11,7 +11,7 @@ using boost::property_tree::ptree;
|
||||
namespace cryfs {
|
||||
|
||||
CryConfig::CryConfig(const bf::path &configfile)
|
||||
:_configfile(configfile), _root_blob("") {
|
||||
:_configfile(configfile), _root_block("") {
|
||||
if (bf::exists(_configfile)) {
|
||||
load();
|
||||
}
|
||||
@ -21,23 +21,23 @@ void CryConfig::load() {
|
||||
ptree pt;
|
||||
read_json(_configfile.native(), pt);
|
||||
|
||||
_root_blob = pt.get("cryfs.rootblob", "");
|
||||
_root_block = pt.get("cryfs.rootblock", "");
|
||||
}
|
||||
|
||||
void CryConfig::save() const {
|
||||
ptree pt;
|
||||
|
||||
pt.put("cryfs.rootblob", _root_blob);
|
||||
pt.put("cryfs.rootblock", _root_block);
|
||||
|
||||
write_json(_configfile.native(), pt);
|
||||
}
|
||||
|
||||
const std::string &CryConfig::RootBlob() const {
|
||||
return _root_blob;
|
||||
const std::string &CryConfig::RootBlock() const {
|
||||
return _root_block;
|
||||
}
|
||||
|
||||
void CryConfig::SetRootBlob(const std::string &value) {
|
||||
_root_blob = value;
|
||||
void CryConfig::SetRootBlock(const std::string &value) {
|
||||
_root_block = value;
|
||||
}
|
||||
|
||||
CryConfig::~CryConfig() {
|
||||
|
@ -13,8 +13,8 @@ public:
|
||||
CryConfig(const boost::filesystem::path &configfile);
|
||||
virtual ~CryConfig();
|
||||
|
||||
const std::string &RootBlob() const;
|
||||
void SetRootBlob(const std::string &value);
|
||||
const std::string &RootBlock() const;
|
||||
void SetRootBlock(const std::string &value);
|
||||
|
||||
private:
|
||||
boost::filesystem::path _configfile;
|
||||
@ -22,7 +22,7 @@ private:
|
||||
void load();
|
||||
void save() const;
|
||||
|
||||
std::string _root_blob;
|
||||
std::string _root_block;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryConfig);
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "CryFile.h"
|
||||
|
||||
#include "fspp/fuse/FuseErrnoException.h"
|
||||
#include "impl/DirBlob.h"
|
||||
#include "impl/DirBlock.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
|
||||
@ -16,23 +16,23 @@ using std::string;
|
||||
using fspp::fuse::CHECK_RETVAL;
|
||||
using fspp::fuse::FuseErrnoException;
|
||||
|
||||
using blobstore::BlobStore;
|
||||
using blockstore::BlockStore;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryDevice::CryDevice(unique_ptr<CryConfig> config, unique_ptr<BlobStore> blobStore)
|
||||
: _blob_store(std::move(blobStore)), _root_key(config->RootBlob()) {
|
||||
CryDevice::CryDevice(unique_ptr<CryConfig> config, unique_ptr<BlockStore> blockStore)
|
||||
: _block_store(std::move(blockStore)), _root_key(config->RootBlock()) {
|
||||
if (_root_key == "") {
|
||||
_root_key = CreateRootBlobAndReturnKey();
|
||||
config->SetRootBlob(_root_key);
|
||||
_root_key = CreateRootBlockAndReturnKey();
|
||||
config->SetRootBlock(_root_key);
|
||||
}
|
||||
}
|
||||
|
||||
string CryDevice::CreateRootBlobAndReturnKey() {
|
||||
auto rootBlob = _blob_store->create(DIR_BLOBSIZE);
|
||||
DirBlob rootDir(std::move(rootBlob.blob));
|
||||
string CryDevice::CreateRootBlockAndReturnKey() {
|
||||
auto rootBlock = _block_store->create(DIR_BLOCKSIZE);
|
||||
DirBlock rootDir(std::move(rootBlock.block));
|
||||
rootDir.InitializeEmptyDir();
|
||||
return rootBlob.key;
|
||||
return rootBlock.key;
|
||||
}
|
||||
|
||||
CryDevice::~CryDevice() {
|
||||
@ -42,21 +42,21 @@ unique_ptr<fspp::Node> CryDevice::Load(const bf::path &path) {
|
||||
printf("Loading %s\n", path.c_str());
|
||||
assert(path.is_absolute());
|
||||
|
||||
auto current_blob = _blob_store->load(_root_key);
|
||||
auto current_block = _block_store->load(_root_key);
|
||||
|
||||
for (const bf::path &component : path.relative_path()) {
|
||||
if (!DirBlob::IsDir(*current_blob)) {
|
||||
if (!DirBlock::IsDir(*current_block)) {
|
||||
throw FuseErrnoException(ENOTDIR);
|
||||
}
|
||||
unique_ptr<DirBlob> currentDir = make_unique<DirBlob>(std::move(current_blob));
|
||||
unique_ptr<DirBlock> currentDir = make_unique<DirBlock>(std::move(current_block));
|
||||
|
||||
string childKey = currentDir->GetBlobKeyForName(component.c_str());
|
||||
current_blob = _blob_store->load(childKey);
|
||||
string childKey = currentDir->GetBlockKeyForName(component.c_str());
|
||||
current_block = _block_store->load(childKey);
|
||||
}
|
||||
if (DirBlob::IsDir(*current_blob)) {
|
||||
return make_unique<CryDir>(this, std::move(make_unique<DirBlob>(std::move(current_blob))));
|
||||
} else if (FileBlob::IsFile(*current_blob)) {
|
||||
return make_unique<CryFile>(std::move(make_unique<FileBlob>(std::move(current_blob))));
|
||||
if (DirBlock::IsDir(*current_block)) {
|
||||
return make_unique<CryDir>(this, std::move(make_unique<DirBlock>(std::move(current_block))));
|
||||
} else if (FileBlock::IsFile(*current_block)) {
|
||||
return make_unique<CryFile>(std::move(make_unique<FileBlock>(std::move(current_block))));
|
||||
} else {
|
||||
throw FuseErrnoException(EIO);
|
||||
}
|
||||
@ -66,8 +66,8 @@ void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
blobstore::BlobWithKey CryDevice::CreateBlob(size_t size) {
|
||||
return _blob_store->create(size);
|
||||
blockstore::BlockWithKey CryDevice::CreateBlock(size_t size) {
|
||||
return _block_store->create(size);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,12 @@
|
||||
#ifndef CRYFS_LIB_CRYDEVICE_H_
|
||||
#define CRYFS_LIB_CRYDEVICE_H_
|
||||
|
||||
#include <blockstore/interface/BlockStore.h>
|
||||
#include "CryConfig.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fspp/fs_interface/Device.h>
|
||||
|
||||
#include "blobstore/interface/BlobStore.h"
|
||||
|
||||
#include "fspp/utils/macros.h"
|
||||
|
||||
namespace cryfs {
|
||||
@ -17,20 +16,20 @@ namespace bf = boost::filesystem;
|
||||
|
||||
class CryDevice: public fspp::Device {
|
||||
public:
|
||||
static constexpr size_t DIR_BLOBSIZE = 4096;
|
||||
static constexpr size_t DIR_BLOCKSIZE = 4096;
|
||||
|
||||
CryDevice(std::unique_ptr<CryConfig> config, std::unique_ptr<blobstore::BlobStore> blobStore);
|
||||
CryDevice(std::unique_ptr<CryConfig> config, std::unique_ptr<blockstore::BlockStore> blockbStore);
|
||||
virtual ~CryDevice();
|
||||
|
||||
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
||||
|
||||
blobstore::BlobWithKey CreateBlob(size_t size);
|
||||
blockstore::BlockWithKey CreateBlock(size_t size);
|
||||
|
||||
private:
|
||||
std::string CreateRootBlobAndReturnKey();
|
||||
std::string CreateRootBlockAndReturnKey();
|
||||
std::unique_ptr<fspp::Node> Load(const bf::path &path) override;
|
||||
|
||||
std::unique_ptr<blobstore::BlobStore> _blob_store;
|
||||
std::unique_ptr<blockstore::BlockStore> _block_store;
|
||||
|
||||
std::string _root_key;
|
||||
|
||||
|
@ -22,29 +22,29 @@ using std::vector;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryDir::CryDir(CryDevice *device, unique_ptr<DirBlob> blob)
|
||||
: _device(device), _blob(std::move(blob)) {
|
||||
CryDir::CryDir(CryDevice *device, unique_ptr<DirBlock> block)
|
||||
: _device(device), _block(std::move(block)) {
|
||||
}
|
||||
|
||||
CryDir::~CryDir() {
|
||||
}
|
||||
|
||||
unique_ptr<fspp::File> CryDir::createFile(const string &name, mode_t mode) {
|
||||
auto child = _device->CreateBlob(0);
|
||||
_blob->AddChild(name, child.key);
|
||||
auto child = _device->CreateBlock(0);
|
||||
_block->AddChild(name, child.key);
|
||||
//TODO Di we need a return value in createDir for fspp? If not, change fspp!
|
||||
auto fileblob = make_unique<FileBlob>(std::move(child.blob));
|
||||
fileblob->InitializeEmptyFile();
|
||||
return make_unique<CryFile>(std::move(fileblob));
|
||||
auto fileblock = make_unique<FileBlock>(std::move(child.block));
|
||||
fileblock->InitializeEmptyFile();
|
||||
return make_unique<CryFile>(std::move(fileblock));
|
||||
}
|
||||
|
||||
unique_ptr<fspp::Dir> CryDir::createDir(const string &name, mode_t mode) {
|
||||
auto child = _device->CreateBlob(CryDevice::DIR_BLOBSIZE);
|
||||
_blob->AddChild(name, child.key);
|
||||
auto child = _device->CreateBlock(CryDevice::DIR_BLOCKSIZE);
|
||||
_block->AddChild(name, child.key);
|
||||
//TODO I don't think we need a return value in createDir for fspp. Change fspp!
|
||||
auto dirblob = make_unique<DirBlob>(std::move(child.blob));
|
||||
dirblob->InitializeEmptyDir();
|
||||
return make_unique<CryDir>(_device, std::move(dirblob));
|
||||
auto dirblock = make_unique<DirBlock>(std::move(child.block));
|
||||
dirblock->InitializeEmptyDir();
|
||||
return make_unique<CryDir>(_device, std::move(dirblock));
|
||||
}
|
||||
|
||||
void CryDir::rmdir() {
|
||||
@ -52,7 +52,7 @@ void CryDir::rmdir() {
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> CryDir::children() const {
|
||||
return _blob->GetChildren();
|
||||
return _block->GetChildren();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
|
||||
#include <fspp/fs_interface/Dir.h>
|
||||
#include "CryNode.h"
|
||||
#include "impl/DirBlob.h"
|
||||
#include "impl/DirBlock.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class CryDir: public fspp::Dir, CryNode {
|
||||
public:
|
||||
CryDir(CryDevice *device, std::unique_ptr<DirBlob> blob);
|
||||
CryDir(CryDevice *device, std::unique_ptr<DirBlock> block);
|
||||
virtual ~CryDir();
|
||||
|
||||
//TODO return type variance to CryFile/CryDir?
|
||||
@ -22,7 +22,7 @@ public:
|
||||
|
||||
private:
|
||||
CryDevice *_device;
|
||||
std::unique_ptr<DirBlob> _blob;
|
||||
std::unique_ptr<DirBlock> _block;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDir);
|
||||
};
|
||||
|
@ -15,8 +15,8 @@ using std::make_unique;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryFile::CryFile(unique_ptr<FileBlob> blob)
|
||||
: _blob(std::move(blob)) {
|
||||
CryFile::CryFile(unique_ptr<FileBlock> block)
|
||||
: _block(std::move(block)) {
|
||||
}
|
||||
|
||||
CryFile::~CryFile() {
|
||||
|
@ -5,13 +5,13 @@
|
||||
#include <fspp/fs_interface/File.h>
|
||||
#include "CryNode.h"
|
||||
|
||||
#include "impl/FileBlob.h"
|
||||
#include "impl/FileBlock.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class CryFile: public fspp::File, CryNode {
|
||||
public:
|
||||
CryFile(std::unique_ptr<FileBlob> blob);
|
||||
CryFile(std::unique_ptr<FileBlock> block);
|
||||
virtual ~CryFile();
|
||||
|
||||
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
|
||||
@ -19,7 +19,7 @@ public:
|
||||
void unlink() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<FileBlob> _blob;
|
||||
std::unique_ptr<FileBlock> _block;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryFile);
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <cryfs_lib/impl/DirBlob.h>
|
||||
#include "DirBlock.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@ -12,35 +12,35 @@ using std::make_unique;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
using blobstore::Blob;
|
||||
using blockstore::Block;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
DirBlob::DirBlob(unique_ptr<Blob> blob)
|
||||
: _blob(std::move(blob)) {
|
||||
DirBlock::DirBlock(unique_ptr<Block> block)
|
||||
: _block(std::move(block)) {
|
||||
}
|
||||
|
||||
DirBlob::~DirBlob() {
|
||||
DirBlock::~DirBlock() {
|
||||
}
|
||||
|
||||
void DirBlob::InitializeEmptyDir() {
|
||||
void DirBlock::InitializeEmptyDir() {
|
||||
*magicNumber() = MagicNumbers::DIR;
|
||||
*entryCounter() = 0;
|
||||
}
|
||||
|
||||
unsigned char *DirBlob::magicNumber() {
|
||||
return const_cast<unsigned char*>(magicNumber(const_cast<const Blob&>(*_blob)));
|
||||
unsigned char *DirBlock::magicNumber() {
|
||||
return const_cast<unsigned char*>(magicNumber(const_cast<const Block&>(*_block)));
|
||||
}
|
||||
|
||||
const unsigned char *DirBlob::magicNumber(const blobstore::Blob &blob) {
|
||||
return (unsigned char*)blob.data();
|
||||
const unsigned char *DirBlock::magicNumber(const blockstore::Block &block) {
|
||||
return (unsigned char*)block.data();
|
||||
}
|
||||
|
||||
bool DirBlob::IsDir(const blobstore::Blob &blob) {
|
||||
return *magicNumber(blob) == MagicNumbers::DIR;
|
||||
bool DirBlock::IsDir(const blockstore::Block &block) {
|
||||
return *magicNumber(block) == MagicNumbers::DIR;
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> DirBlob::GetChildren() const {
|
||||
unique_ptr<vector<string>> DirBlock::GetChildren() const {
|
||||
auto result = make_unique<vector<string>>();
|
||||
unsigned int entryCount = *entryCounter();
|
||||
result->reserve(entryCount);
|
||||
@ -53,7 +53,7 @@ unique_ptr<vector<string>> DirBlob::GetChildren() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
const char *DirBlob::readAndAddNextChild(const char *pos, vector<string> *result) const {
|
||||
const char *DirBlock::readAndAddNextChild(const char *pos, vector<string> *result) const {
|
||||
size_t length = strlen(pos);
|
||||
result->emplace_back(pos, length);
|
||||
const char *posAfterName = pos + length + 1;
|
||||
@ -61,21 +61,21 @@ const char *DirBlob::readAndAddNextChild(const char *pos, vector<string> *result
|
||||
return posAfterKey;
|
||||
}
|
||||
|
||||
void DirBlob::AddChild(const std::string &name, const std::string &blobKey) {
|
||||
void DirBlock::AddChild(const std::string &name, const std::string &blockKey) {
|
||||
char *insertPos = entriesEnd();
|
||||
assertEnoughSpaceLeft(insertPos, name.size() + 1 + blobKey.size() + 1);
|
||||
assertEnoughSpaceLeft(insertPos, name.size() + 1 + blockKey.size() + 1);
|
||||
|
||||
memcpy(insertPos, name.c_str(), name.size()+1);
|
||||
memcpy(insertPos + name.size()+1, blobKey.c_str(), blobKey.size()+1);
|
||||
memcpy(insertPos + name.size()+1, blockKey.c_str(), blockKey.size()+1);
|
||||
++(*entryCounter());
|
||||
}
|
||||
|
||||
void DirBlob::assertEnoughSpaceLeft(char *insertPos, size_t insertSize) const {
|
||||
size_t usedSize = insertPos - (char*)_blob->data();
|
||||
assert(usedSize + insertSize <= _blob->size());
|
||||
void DirBlock::assertEnoughSpaceLeft(char *insertPos, size_t insertSize) const {
|
||||
size_t usedSize = insertPos - (char*)_block->data();
|
||||
assert(usedSize + insertSize <= _block->size());
|
||||
}
|
||||
|
||||
string DirBlob::GetBlobKeyForName(const string &name) const {
|
||||
string DirBlock::GetBlockKeyForName(const string &name) const {
|
||||
unsigned int entryCount = *entryCounter();
|
||||
const char *pos = entriesBegin();
|
||||
for(unsigned int i = 0; i < entryCount; ++i) {
|
||||
@ -90,23 +90,23 @@ string DirBlob::GetBlobKeyForName(const string &name) const {
|
||||
throw fspp::fuse::FuseErrnoException(ENOENT);
|
||||
}
|
||||
|
||||
unsigned int *DirBlob::entryCounter() {
|
||||
return const_cast<unsigned int*>(const_cast<const DirBlob*>(this)->entryCounter());
|
||||
unsigned int *DirBlock::entryCounter() {
|
||||
return const_cast<unsigned int*>(const_cast<const DirBlock*>(this)->entryCounter());
|
||||
}
|
||||
|
||||
const unsigned int *DirBlob::entryCounter() const {
|
||||
return (unsigned int*)((char*)_blob->data() + sizeof(unsigned char));
|
||||
const unsigned int *DirBlock::entryCounter() const {
|
||||
return (unsigned int*)((char*)_block->data() + sizeof(unsigned char));
|
||||
}
|
||||
|
||||
char *DirBlob::entriesBegin() {
|
||||
return const_cast<char*>(const_cast<const DirBlob*>(this)->entriesBegin());
|
||||
char *DirBlock::entriesBegin() {
|
||||
return const_cast<char*>(const_cast<const DirBlock*>(this)->entriesBegin());
|
||||
}
|
||||
|
||||
const char *DirBlob::entriesBegin() const {
|
||||
return (char *)(_blob->data())+sizeof(unsigned char) + sizeof(unsigned int);
|
||||
const char *DirBlock::entriesBegin() const {
|
||||
return (char *)(_block->data())+sizeof(unsigned char) + sizeof(unsigned int);
|
||||
}
|
||||
|
||||
char *DirBlob::entriesEnd() {
|
||||
char *DirBlock::entriesEnd() {
|
||||
unsigned int entryCount = *entryCounter();
|
||||
char *pos = entriesBegin();
|
||||
for(unsigned int i = 0; i < entryCount; ++i) {
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_IMPL_DIRBLOB_H_
|
||||
#define CRYFS_LIB_IMPL_DIRBLOB_H_
|
||||
#ifndef CRYFS_LIB_IMPL_DIRBLOCK_H_
|
||||
#define CRYFS_LIB_IMPL_DIRBLOCK_H_
|
||||
|
||||
#include "blobstore/interface/Blob.h"
|
||||
#include <blockstore/interface/Block.h>
|
||||
#include "fspp/utils/macros.h"
|
||||
|
||||
#include <memory>
|
||||
@ -10,21 +10,21 @@
|
||||
|
||||
namespace cryfs{
|
||||
|
||||
class DirBlob {
|
||||
class DirBlock {
|
||||
public:
|
||||
DirBlob(std::unique_ptr<blobstore::Blob> blob);
|
||||
virtual ~DirBlob();
|
||||
DirBlock(std::unique_ptr<blockstore::Block> block);
|
||||
virtual ~DirBlock();
|
||||
|
||||
void InitializeEmptyDir();
|
||||
std::unique_ptr<std::vector<std::string>> GetChildren() const;
|
||||
void AddChild(const std::string &name, const std::string &blobKey);
|
||||
std::string GetBlobKeyForName(const std::string &name) const;
|
||||
void AddChild(const std::string &name, const std::string &blockKey);
|
||||
std::string GetBlockKeyForName(const std::string &name) const;
|
||||
|
||||
static bool IsDir(const blobstore::Blob &blob);
|
||||
static bool IsDir(const blockstore::Block &block);
|
||||
|
||||
private:
|
||||
unsigned char *magicNumber();
|
||||
static const unsigned char *magicNumber(const blobstore::Blob &blob);
|
||||
static const unsigned char *magicNumber(const blockstore::Block &block);
|
||||
unsigned int *entryCounter();
|
||||
const unsigned int *entryCounter() const;
|
||||
char *entriesBegin();
|
||||
@ -34,9 +34,9 @@ private:
|
||||
const char *readAndAddNextChild(const char *pos, std::vector<std::string> *result) const;
|
||||
void assertEnoughSpaceLeft(char *insertPos, size_t insertSize) const;
|
||||
|
||||
std::unique_ptr<blobstore::Blob> _blob;
|
||||
std::unique_ptr<blockstore::Block> _block;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DirBlob);
|
||||
DISALLOW_COPY_AND_ASSIGN(DirBlock);
|
||||
};
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#include <cryfs_lib/impl/FileBlob.h>
|
||||
|
||||
#include "MagicNumbers.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
using blobstore::Blob;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
FileBlob::FileBlob(unique_ptr<Blob> blob)
|
||||
: _blob(std::move(blob)) {
|
||||
}
|
||||
|
||||
FileBlob::~FileBlob() {
|
||||
}
|
||||
|
||||
void FileBlob::InitializeEmptyFile() {
|
||||
*magicNumber() = MagicNumbers::FILE;
|
||||
}
|
||||
|
||||
unsigned char *FileBlob::magicNumber() {
|
||||
return const_cast<unsigned char*>(magicNumber(const_cast<const Blob&>(*_blob)));
|
||||
}
|
||||
|
||||
const unsigned char *FileBlob::magicNumber(const blobstore::Blob &blob) {
|
||||
return (unsigned char*)blob.data();
|
||||
}
|
||||
|
||||
bool FileBlob::IsFile(const Blob &blob) {
|
||||
return *magicNumber(blob) == MagicNumbers::FILE;
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_IMPL_FILEBLOB_H_
|
||||
#define CRYFS_LIB_IMPL_FILEBLOB_H_
|
||||
|
||||
#include "blobstore/interface/Blob.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class FileBlob {
|
||||
public:
|
||||
FileBlob(std::unique_ptr<blobstore::Blob> blob);
|
||||
virtual ~FileBlob();
|
||||
|
||||
static bool IsFile(const blobstore::Blob &blob);
|
||||
|
||||
void InitializeEmptyFile();
|
||||
|
||||
private:
|
||||
std::unique_ptr<blobstore::Blob> _blob;
|
||||
|
||||
unsigned char *magicNumber();
|
||||
static const unsigned char *magicNumber(const blobstore::Blob &blob);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
33
src/cryfs_lib/impl/FileBlock.cpp
Normal file
33
src/cryfs_lib/impl/FileBlock.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "FileBlock.h"
|
||||
|
||||
#include "MagicNumbers.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
using blockstore::Block;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
FileBlock::FileBlock(unique_ptr<Block> block)
|
||||
: _block(std::move(block)) {
|
||||
}
|
||||
|
||||
FileBlock::~FileBlock() {
|
||||
}
|
||||
|
||||
void FileBlock::InitializeEmptyFile() {
|
||||
*magicNumber() = MagicNumbers::FILE;
|
||||
}
|
||||
|
||||
unsigned char *FileBlock::magicNumber() {
|
||||
return const_cast<unsigned char*>(magicNumber(const_cast<const Block&>(*_block)));
|
||||
}
|
||||
|
||||
const unsigned char *FileBlock::magicNumber(const blockstore::Block &block) {
|
||||
return (unsigned char*)block.data();
|
||||
}
|
||||
|
||||
bool FileBlock::IsFile(const Block &block) {
|
||||
return *magicNumber(block) == MagicNumbers::FILE;
|
||||
}
|
||||
|
||||
}
|
28
src/cryfs_lib/impl/FileBlock.h
Normal file
28
src/cryfs_lib/impl/FileBlock.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_IMPL_FILEBLOCK_H_
|
||||
#define CRYFS_LIB_IMPL_FILEBLOCK_H_
|
||||
|
||||
#include <blockstore/interface/Block.h>
|
||||
#include <memory>
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class FileBlock {
|
||||
public:
|
||||
FileBlock(std::unique_ptr<blockstore::Block> block);
|
||||
virtual ~FileBlock();
|
||||
|
||||
static bool IsFile(const blockstore::Block &block);
|
||||
|
||||
void InitializeEmptyFile();
|
||||
|
||||
private:
|
||||
std::unique_ptr<blockstore::Block> _block;
|
||||
|
||||
unsigned char *magicNumber();
|
||||
static const unsigned char *magicNumber(const blockstore::Block &block);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,3 +1,4 @@
|
||||
#include <blockstore/implementations/ondisk/OnDiskBlockStore.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -7,20 +8,19 @@
|
||||
#include "fspp/impl/FilesystemImpl.h"
|
||||
#include "copyfs/CopyDevice.h"
|
||||
#include "cryfs_lib/CryDevice.h"
|
||||
#include "blobstore/implementations/ondisk/OnDiskBlobStore.h"
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
using blobstore::ondisk::OnDiskBlobStore;
|
||||
using blockstore::ondisk::OnDiskBlockStore;
|
||||
|
||||
using std::make_unique;
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
|
||||
auto blobStore = make_unique<OnDiskBlobStore>(bf::path("/home/heinzi/cryfstest/root"));
|
||||
auto blockStore = make_unique<OnDiskBlockStore>(bf::path("/home/heinzi/cryfstest/root"));
|
||||
auto config = make_unique<cryfs::CryConfig>(bf::path("/home/heinzi/cryfstest/config.json"));
|
||||
cryfs::CryDevice device(std::move(config), std::move(blobStore));
|
||||
cryfs::CryDevice device(std::move(config), std::move(blockStore));
|
||||
fspp::FilesystemImpl fsimpl(&device);
|
||||
fspp::fuse::Fuse fuse(&fsimpl);
|
||||
fuse.run(argc, argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user