libcryfs/implementations/ondisk/OnDiskBlock.h

50 lines
1.3 KiB
C
Raw Normal View History

2014-12-09 17:19:59 +01:00
#pragma once
2015-10-15 13:09:21 +02:00
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_ONDISK_ONDISKBLOCK_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_ONDISK_ONDISKBLOCK_H_
2014-12-09 17:19:59 +01:00
#include <boost/filesystem/path.hpp>
#include "../../interface/Block.h"
#include <messmer/cpp-utils/data/Data.h>
2014-12-09 17:19:59 +01:00
#include <iostream>
#include <messmer/cpp-utils/pointer/unique_ref.h>
#include <mutex>
2014-12-09 17:19:59 +01:00
namespace blockstore {
namespace ondisk {
class OnDiskBlockStore;
class OnDiskBlock: public Block {
public:
OnDiskBlock(const Key &key, const boost::filesystem::path &filepath, cpputils::Data data);
2014-12-09 17:19:59 +01:00
virtual ~OnDiskBlock();
static boost::optional<cpputils::unique_ref<OnDiskBlock>> LoadFromDisk(const boost::filesystem::path &rootdir, const Key &key);
static boost::optional<cpputils::unique_ref<OnDiskBlock>> CreateOnDisk(const boost::filesystem::path &rootdir, const Key &key, cpputils::Data data);
2015-02-22 00:29:21 +01:00
static void RemoveFromDisk(const boost::filesystem::path &rootdir, const Key &key);
2014-12-09 17:19:59 +01:00
const void *data() const override;
void write(const void *source, uint64_t offset, uint64_t size) override;
2014-12-09 17:19:59 +01:00
void flush() override;
size_t size() const override;
private:
const boost::filesystem::path _filepath;
cpputils::Data _data;
bool _dataChanged;
2014-12-09 17:19:59 +01:00
void _fillDataWithZeroes();
void _storeToDisk() const;
std::mutex _mutex;
2014-12-09 17:19:59 +01:00
DISALLOW_COPY_AND_ASSIGN(OnDiskBlock);
};
}
}
#endif