Add XorExtentWriter
This class is built on top of BlockExtentWriter(block aligned writer)
and ExtentMap. It will look at the extent map, convert blocks in the
extent map to XOR type, and convert everythign else to COW_REPLACE.
Test: th
Bug: 177104308
Change-Id: I6f9df83ed09f1c5a6aae9f266412132b002acd29
diff --git a/payload_generator/extent_utils.cc b/payload_generator/extent_utils.cc
index f4a9ff0..612fd67 100644
--- a/payload_generator/extent_utils.cc
+++ b/payload_generator/extent_utils.cc
@@ -26,6 +26,7 @@
#include <base/macros.h>
#include <base/strings/stringprintf.h>
+#include "update_engine/common/utils.h"
#include "update_engine/payload_consumer/payload_constants.h"
#include "update_engine/payload_generator/annotated_operation.h"
#include "update_engine/payload_generator/extent_ranges.h"
@@ -161,14 +162,44 @@
return result;
}
-bool operator==(const Extent& a, const Extent& b) {
+bool operator==(const Extent& a, const Extent& b) noexcept {
return a.start_block() == b.start_block() && a.num_blocks() == b.num_blocks();
}
+bool operator!=(const Extent& a, const Extent& b) noexcept {
+ return !(a == b);
+}
+
std::ostream& operator<<(std::ostream& out, const Extent& extent) {
out << "[" << extent.start_block() << " - "
<< extent.start_block() + extent.num_blocks() - 1 << "]";
return out;
}
+template <typename T>
+std::ostream& PrintExtents(std::ostream& out, const T& extents) {
+ if (extents.begin() == extents.end()) {
+ out << "{}";
+ return out;
+ }
+ out << "{";
+ auto begin = extents.begin();
+ out << *begin;
+ for (const auto& ext : Range{++begin, extents.end()}) {
+ out << ", " << ext;
+ }
+ out << "}";
+ return out;
+}
+
+std::ostream& operator<<(std::ostream& out,
+ const std::vector<Extent>& extents) {
+ return PrintExtents(out, extents);
+}
+std::ostream& operator<<(
+ std::ostream& out,
+ const google::protobuf::RepeatedPtrField<Extent>& extents) {
+ return PrintExtents(out, extents);
+}
+
} // namespace chromeos_update_engine
diff --git a/payload_generator/extent_utils.h b/payload_generator/extent_utils.h
index 2bd6626..f5bb39c 100644
--- a/payload_generator/extent_utils.h
+++ b/payload_generator/extent_utils.h
@@ -86,7 +86,9 @@
uint64_t block_offset,
uint64_t block_count);
-bool operator==(const Extent& a, const Extent& b);
+bool operator==(const Extent& a, const Extent& b) noexcept;
+
+bool operator!=(const Extent& a, const Extent& b) noexcept;
// TODO(zhangkelvin) This is ugly. Rewrite using C++20's coroutine once
// that's available. Unfortunately with C++17 this is the best I could do.
@@ -126,6 +128,10 @@
};
std::ostream& operator<<(std::ostream& out, const Extent& extent);
+std::ostream& operator<<(std::ostream& out, const std::vector<Extent>& extent);
+std::ostream& operator<<(
+ std::ostream& out,
+ const google::protobuf::RepeatedPtrField<Extent>& extent);
template <typename Container>
size_t GetNthBlock(const Container& extents, const size_t n) {