libcryfs/utils/BlockStoreUtils.cpp

32 lines
732 B
C++
Raw Normal View History

#include "../interface/BlockStore.h"
#include "BlockStoreUtils.h"
#include <messmer/cpp-utils/data/Data.h>
2015-01-24 01:24:37 +01:00
#include <memory>
2015-02-22 19:29:30 +01:00
#include <cassert>
2015-01-24 01:24:37 +01:00
using std::unique_ptr;
using cpputils::Data;
2015-01-24 01:24:37 +01:00
namespace blockstore {
namespace utils {
unique_ptr<Block> copyToNewBlock(BlockStore *blockStore, const Block &block) {
Data data(block.size());
std::memcpy(data.data(), block.data(), block.size());
return blockStore->create(data);
2015-01-24 01:24:37 +01:00
}
2015-02-22 19:29:30 +01:00
void copyTo(Block *target, const Block &source) {
assert(target->size() == source.size());
target->write(source.data(), 0, source.size());
}
void fillWithZeroes(Block *target) {
Data zeroes(target->size());
zeroes.FillWithZeroes();
target->write(zeroes.data(), 0, target->size());
2015-02-22 19:29:30 +01:00
}
2015-01-24 01:24:37 +01:00
}
}