#pragma once #ifndef MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_FSBLOBSTORE_H #define MESSMER_CRYFS_FILESYSTEM_FSBLOBSTORE_FSBLOBSTORE_H #include #include #include #include "FileBlob.h" #include "DirBlob.h" #include "SymlinkBlob.h" namespace cryfs { namespace fsblobstore { //TODO Test classes in fsblobstore class FsBlobStore final { public: FsBlobStore(cpputils::unique_ref baseBlobStore); cpputils::unique_ref createFileBlob(const blockstore::Key &parent); cpputils::unique_ref createDirBlob(const blockstore::Key &parent); cpputils::unique_ref createSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent); boost::optional> load(const blockstore::Key &key); void remove(cpputils::unique_ref blob); uint64_t numBlocks() const; uint64_t estimateSpaceForNumBlocksLeft() const; uint64_t virtualBlocksizeBytes() const; #ifndef CRYFS_NO_COMPATIBILITY static cpputils::unique_ref migrateIfNeeded(cpputils::unique_ref blobStore, const blockstore::Key &rootKey); #endif private: #ifndef CRYFS_NO_COMPATIBILITY void _migrate(cpputils::unique_ref node, const blockstore::Key &parentKey); #endif std::function _getLstatSize(); cpputils::unique_ref _baseBlobStore; DISALLOW_COPY_AND_ASSIGN(FsBlobStore); }; inline FsBlobStore::FsBlobStore(cpputils::unique_ref baseBlobStore) : _baseBlobStore(std::move(baseBlobStore)) { } inline cpputils::unique_ref FsBlobStore::createFileBlob(const blockstore::Key &parent) { auto blob = _baseBlobStore->create(); return FileBlob::InitializeEmptyFile(std::move(blob), parent); } inline cpputils::unique_ref FsBlobStore::createDirBlob(const blockstore::Key &parent) { auto blob = _baseBlobStore->create(); return DirBlob::InitializeEmptyDir(this, std::move(blob), parent, _getLstatSize()); } inline cpputils::unique_ref FsBlobStore::createSymlinkBlob(const boost::filesystem::path &target, const blockstore::Key &parent) { auto blob = _baseBlobStore->create(); return SymlinkBlob::InitializeSymlink(std::move(blob), target, parent); } inline uint64_t FsBlobStore::numBlocks() const { return _baseBlobStore->numBlocks(); } inline uint64_t FsBlobStore::estimateSpaceForNumBlocksLeft() const { return _baseBlobStore->estimateSpaceForNumBlocksLeft(); } inline void FsBlobStore::remove(cpputils::unique_ref blob) { _baseBlobStore->remove(blob->releaseBaseBlob()); } inline std::function FsBlobStore::_getLstatSize() { return [this] (const blockstore::Key &key) { auto blob = load(key); ASSERT(blob != boost::none, "Blob not found"); return (*blob)->lstat_size(); }; } inline uint64_t FsBlobStore::virtualBlocksizeBytes() const { return _baseBlobStore->virtualBlocksizeBytes(); } } } #endif