From d2ad53cf81651ca53be4e8e8ab279ccb38ad1d69 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Thu, 31 Aug 2023 10:42:54 -0700 Subject: [PATCH] Add CowOperationV2 this is going to replace the current version of CowOperation and will work with writer v2 and parser v2. This will be the on disk format of the cow, while CowOperation will be updated to be the in memory format of 15 bytes (implicitly will be the v3 version). Test: m libsnapshot Test: m libsnapshot Change-Id: Ibd00ef014a9fc11cdf2bad97c52462db8eef9502 --- .../include/libsnapshot/cow_format.h | 36 +++++++++++++++++++ .../include/libsnapshot/cow_reader.h | 1 - 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h index c9a4dee3a..aac71de9c 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h @@ -143,6 +143,42 @@ struct CowOperation { uint64_t source; } __attribute__((packed)); +// The on disk format of cow (currently == CowOperation) +struct CowOperationV2 { + // The operation code (see the constants and structures below). + uint8_t type; + + // If this operation reads from the data section of the COW, this contains + // the compression type of that data (see constants below). + uint8_t compression; + + // If this operation reads from the data section of the COW, this contains + // the length. + uint16_t data_length; + + // The block of data in the new image that this operation modifies. + uint64_t new_block; + + // The value of |source| depends on the operation code. + // + // For copy operations, this is a block location in the source image. + // + // For replace operations, this is a byte offset within the COW's data + // sections (eg, not landing within the header or metadata). It is an + // absolute position within the image. + // + // For zero operations (replace with all zeroes), this is unused and must + // be zero. + // + // For Label operations, this is the value of the applied label. + // + // For Cluster operations, this is the length of the following data region + // + // For Xor operations, this is the byte location in the source image. + uint64_t source; +} __attribute__((packed)); + +static_assert(sizeof(CowOperationV2) == sizeof(CowOperation)); static_assert(sizeof(CowOperation) == sizeof(CowFooterOperation)); static constexpr uint8_t kCowCopyOp = 1; diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_reader.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_reader.h index f4ce52fa3..67d301d70 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/cow_reader.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_reader.h @@ -165,7 +165,6 @@ class CowReader final : public ICowReader { void UpdateMergeOpsCompleted(int num_merge_ops) { header_.num_merge_ops += num_merge_ops; } private: - bool ParseOps(std::optional label); bool PrepMergeOps(); uint64_t FindNumCopyops(); uint8_t GetCompressionType(const CowOperation* op);