Implemented basic FileBlob
This commit is contained in:
parent
9a97287a96
commit
79455cf01f
|
@ -1,3 +1,3 @@
|
|||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryConfig.cpp impl/DirBlob.cpp)
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryConfig.cpp impl/DirBlob.cpp impl/FileBlob.cpp)
|
||||
|
||||
target_link_libraries(cryfs_lib)
|
||||
|
|
|
@ -40,14 +40,26 @@ CryDevice::~CryDevice() {
|
|||
|
||||
unique_ptr<fspp::Node> CryDevice::Load(const bf::path &path) {
|
||||
printf("Loading %s\n", path.c_str());
|
||||
unique_ptr<DirBlob> currentDir = make_unique<DirBlob>(_blob_store->load(_root_key));
|
||||
assert(path.is_absolute());
|
||||
|
||||
auto current_blob = _blob_store->load(_root_key);
|
||||
|
||||
for (const bf::path &component : path.relative_path()) {
|
||||
printf("Component: %s\n", component.c_str());
|
||||
if (!DirBlob::IsDir(*current_blob)) {
|
||||
throw FuseErrnoException(ENOTDIR);
|
||||
}
|
||||
unique_ptr<DirBlob> currentDir = make_unique<DirBlob>(std::move(current_blob));
|
||||
|
||||
string childKey = currentDir->GetBlobKeyForName(component.c_str());
|
||||
currentDir = make_unique<DirBlob>(_blob_store->load(childKey));
|
||||
current_blob = _blob_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))));
|
||||
} else {
|
||||
throw FuseErrnoException(EIO);
|
||||
}
|
||||
return make_unique<CryDir>(this, std::move(currentDir));
|
||||
}
|
||||
|
||||
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
|
||||
|
|
|
@ -15,7 +15,8 @@ using std::make_unique;
|
|||
|
||||
namespace cryfs {
|
||||
|
||||
CryFile::CryFile() {
|
||||
CryFile::CryFile(unique_ptr<FileBlob> blob)
|
||||
: _blob(std::move(blob)) {
|
||||
}
|
||||
|
||||
CryFile::~CryFile() {
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
#include <fspp/fs_interface/File.h>
|
||||
#include "CryNode.h"
|
||||
|
||||
#include "impl/FileBlob.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class CryFile: public fspp::File, CryNode {
|
||||
public:
|
||||
CryFile();
|
||||
CryFile(std::unique_ptr<FileBlob> blob);
|
||||
virtual ~CryFile();
|
||||
|
||||
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
|
||||
|
@ -17,6 +19,8 @@ public:
|
|||
void unlink() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<FileBlob> _blob;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryFile);
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#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() {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#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);
|
||||
|
||||
private:
|
||||
std::unique_ptr<blobstore::Blob> _blob;
|
||||
|
||||
static const unsigned char *magicNumber(const blobstore::Blob &blob);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -3,13 +3,13 @@
|
|||
#define CRYFS_LIB_IMPL_MAGICNUMBERS_H_
|
||||
|
||||
namespace cryfs {
|
||||
namespace MagicNumbers {
|
||||
|
||||
unsigned char DIR = 0x00;
|
||||
unsigned char FILE = 0x01;
|
||||
enum MagicNumbers {
|
||||
DIR = 0x00,
|
||||
FILE = 0x01
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue