libcryfs/src/cryfs/filesystem/fsblobstore/FsBlobStore.h

98 lines
3.8 KiB
C
Raw Normal View History

2015-10-15 13:06:51 +02:00
#pragma once
#ifndef MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_FSBLOBSTORE_H
#define MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_FSBLOBSTORE_H
2015-09-30 13:21:07 +02:00
2016-02-11 16:39:42 +01:00
#include <cpp-utils/lock/LockPool.h>
#include <cpp-utils/pointer/unique_ref.h>
#include <blobstore/interface/BlobStore.h>
2015-09-30 13:21:07 +02:00
#include "FileBlob.h"
#include "DirBlob.h"
#include "SymlinkBlob.h"
namespace cryfs {
namespace fsblobstore {
//TODO Test classes in fsblobstore
class FsBlobStore final {
2015-09-30 13:21:07 +02:00
public:
FsBlobStore(cpputils::unique_ref<blobstore::BlobStore> baseBlobStore);
cpputils::unique_ref<FileBlob> createFileBlob(const blockstore::BlockId &parent);
cpputils::unique_ref<DirBlob> createDirBlob(const blockstore::BlockId &parent);
cpputils::unique_ref<SymlinkBlob> createSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent);
boost::optional<cpputils::unique_ref<FsBlob>> load(const blockstore::BlockId &blockId);
2015-09-30 13:21:07 +02:00
void remove(cpputils::unique_ref<FsBlob> blob);
void remove(const blockstore::BlockId &blockId);
uint64_t numBlocks() const;
uint64_t estimateSpaceForNumBlocksLeft() const;
2015-09-30 13:21:07 +02:00
uint64_t virtualBlocksizeBytes() const;
2016-03-08 23:47:31 +01:00
#ifndef CRYFS_NO_COMPATIBILITY
static cpputils::unique_ref<FsBlobStore> migrateIfNeeded(cpputils::unique_ref<blobstore::BlobStore> blobStore, const blockstore::BlockId &blockId);
#endif
2015-09-30 13:21:07 +02:00
private:
#ifndef CRYFS_NO_COMPATIBILITY
void _migrate(cpputils::unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId);
#endif
std::function<off_t(const blockstore::BlockId &)> _getLstatSize();
2015-09-30 13:21:07 +02:00
cpputils::unique_ref<blobstore::BlobStore> _baseBlobStore;
2015-10-05 16:58:33 +02:00
DISALLOW_COPY_AND_ASSIGN(FsBlobStore);
2015-09-30 13:21:07 +02:00
};
2016-02-15 13:22:21 +01:00
inline FsBlobStore::FsBlobStore(cpputils::unique_ref<blobstore::BlobStore> baseBlobStore)
: _baseBlobStore(std::move(baseBlobStore)) {
}
inline cpputils::unique_ref<FileBlob> FsBlobStore::createFileBlob(const blockstore::BlockId &parent) {
2016-02-15 13:22:21 +01:00
auto blob = _baseBlobStore->create();
return FileBlob::InitializeEmptyFile(std::move(blob), parent);
2016-02-15 13:22:21 +01:00
}
inline cpputils::unique_ref<DirBlob> FsBlobStore::createDirBlob(const blockstore::BlockId &parent) {
2016-02-15 13:22:21 +01:00
auto blob = _baseBlobStore->create();
return DirBlob::InitializeEmptyDir(this, std::move(blob), parent, _getLstatSize());
2016-02-15 13:22:21 +01:00
}
inline cpputils::unique_ref<SymlinkBlob> FsBlobStore::createSymlinkBlob(const boost::filesystem::path &target, const blockstore::BlockId &parent) {
2016-02-15 13:22:21 +01:00
auto blob = _baseBlobStore->create();
return SymlinkBlob::InitializeSymlink(std::move(blob), target, parent);
2016-02-15 13:22:21 +01:00
}
inline uint64_t FsBlobStore::numBlocks() const {
return _baseBlobStore->numBlocks();
}
inline uint64_t FsBlobStore::estimateSpaceForNumBlocksLeft() const {
return _baseBlobStore->estimateSpaceForNumBlocksLeft();
}
2016-02-15 13:22:21 +01:00
inline void FsBlobStore::remove(cpputils::unique_ref<FsBlob> blob) {
_baseBlobStore->remove(blob->releaseBaseBlob());
}
inline void FsBlobStore::remove(const blockstore::BlockId &blockId) {
_baseBlobStore->remove(blockId);
}
inline std::function<off_t (const blockstore::BlockId &)> FsBlobStore::_getLstatSize() {
return [this] (const blockstore::BlockId &blockId) {
auto blob = load(blockId);
2016-02-15 13:22:21 +01:00
ASSERT(blob != boost::none, "Blob not found");
return (*blob)->lstat_size();
};
}
2016-03-08 23:47:31 +01:00
inline uint64_t FsBlobStore::virtualBlocksizeBytes() const {
return _baseBlobStore->virtualBlocksizeBytes();
2016-03-08 23:47:31 +01:00
}
2015-09-30 13:21:07 +02:00
}
}
#endif