Add block extent writer
Add a utility class for writing block aligned data. Writes will always
happen at block boundary, and write size will always be a multiple of
block size. This is handy for upcomming XOR writers.
Test: th
Bug: 177104308
Change-Id: I11b4d9b79e20ba48f30b55243188a47c60c65552
diff --git a/payload_consumer/snapshot_extent_writer.h b/payload_consumer/snapshot_extent_writer.h
index c3a948e..c2e5446 100644
--- a/payload_consumer/snapshot_extent_writer.h
+++ b/payload_consumer/snapshot_extent_writer.h
@@ -22,36 +22,21 @@
#include <libsnapshot/cow_writer.h>
-#include "update_engine/payload_consumer/extent_writer.h"
+#include "update_engine/payload_consumer/block_extent_writer.h"
#include "update_engine/update_metadata.pb.h"
namespace chromeos_update_engine {
-class SnapshotExtentWriter : public chromeos_update_engine::ExtentWriter {
+class SnapshotExtentWriter final : public BlockExtentWriter {
public:
- explicit SnapshotExtentWriter(android::snapshot::ICowWriter* cow_writer);
- ~SnapshotExtentWriter();
- // Returns true on success.
- bool Init(const google::protobuf::RepeatedPtrField<Extent>& extents,
- uint32_t block_size) override;
- // Returns true on success.
- // This will construct a COW_REPLACE operation and forward it to CowWriter. It
- // is important that caller does not perform SOURCE_COPY operation on this
- // class, otherwise raw data will be stored. Caller should find ways to use
- // COW_COPY whenever possible.
- bool Write(const void* bytes, size_t count) override;
+ explicit SnapshotExtentWriter(android::snapshot::ICowWriter* cow_writer)
+ : cow_writer_(cow_writer) {}
+ bool WriteExtent(const void* bytes,
+ const Extent& extent,
+ size_t block_size) override;
private:
- bool next_extent();
- [[nodiscard]] size_t ConsumeWithBuffer(const uint8_t* bytes, size_t count);
- // It's a non-owning pointer, because PartitionWriter owns the CowWruter. This
- // allows us to use a single instance of CowWriter for all operations applied
- // to the same partition.
android::snapshot::ICowWriter* cow_writer_;
- google::protobuf::RepeatedPtrField<Extent> extents_;
- size_t cur_extent_idx_;
- std::vector<uint8_t> buffer_;
- size_t block_size_;
};
} // namespace chromeos_update_engine