2016-02-13 15:06:28 +01:00
|
|
|
#include "FsBlobView.h"
|
|
|
|
|
2016-06-28 05:03:44 +02:00
|
|
|
using cpputils::Data;
|
|
|
|
|
2016-02-13 15:06:28 +01:00
|
|
|
namespace cryfs {
|
|
|
|
constexpr uint16_t FsBlobView::FORMAT_VERSION_HEADER;
|
2016-06-28 03:22:13 +02:00
|
|
|
constexpr unsigned int FsBlobView::HEADER_SIZE;
|
2016-06-28 05:03:44 +02:00
|
|
|
|
|
|
|
#ifndef CRYFS_NO_COMPATIBILITY
|
|
|
|
void FsBlobView::migrate(blobstore::Blob *blob, const blockstore::Key &parentKey) {
|
|
|
|
constexpr unsigned int OLD_HEADER_SIZE = sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t);
|
|
|
|
|
|
|
|
ASSERT(FsBlobView::getFormatVersionHeader(*blob) == 0, "Block already migrated");
|
|
|
|
// Resize blob and move data back
|
|
|
|
cpputils::Data data = blob->readAll();
|
|
|
|
blob->resize(blob->size() + blockstore::Key::BINARY_LENGTH);
|
|
|
|
blob->write(data.dataOffset(OLD_HEADER_SIZE), HEADER_SIZE, data.size() - OLD_HEADER_SIZE);
|
|
|
|
// Write parent pointer
|
2017-09-17 01:10:53 +02:00
|
|
|
blob->write(parentKey.data().data(), sizeof(FORMAT_VERSION_HEADER) + sizeof(uint8_t), blockstore::Key::BINARY_LENGTH);
|
2016-06-28 05:03:44 +02:00
|
|
|
// Update format version number
|
|
|
|
blob->write(&FORMAT_VERSION_HEADER, 0, sizeof(FORMAT_VERSION_HEADER));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|