blob: 43a8317311084f21586a0e8f52ffd92d2ae64835 [file] [log] [blame]
Kelvin Zhang9b10dba2020-09-25 17:09:11 -04001//
2// Copyright (C) 2020 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16#include <cstdint>
17#include <vector>
18
19#include <libsnapshot/cow_writer.h>
20
21#include "update_engine/payload_consumer/extent_writer.h"
22
23namespace chromeos_update_engine {
24class SnapshotExtentWriter : public chromeos_update_engine::ExtentWriter {
25 public:
26 explicit SnapshotExtentWriter(android::snapshot::ICowWriter* cow_writer);
27 ~SnapshotExtentWriter();
28 // Returns true on success.
29 bool Init(FileDescriptorPtr fd,
30 const google::protobuf::RepeatedPtrField<Extent>& extents,
31 uint32_t block_size) override;
32 // Returns true on success.
33 // This will construct a COW_REPLACE operation and forward it to CowWriter. It
34 // is important that caller does not perform SOURCE_COPY operation on this
35 // class, otherwise raw data will be stored. Caller should find ways to use
36 // COW_COPY whenever possible.
37 bool Write(const void* bytes, size_t count) override;
38
39 private:
40 // It's a non-owning pointer, because PartitionWriter owns the CowWruter. This
41 // allows us to use a single instance of CowWriter for all operations applied
42 // to the same partition.
43 [[maybe_unused]] android::snapshot::ICowWriter* cow_writer_;
44 [[maybe_unused]] google::protobuf::RepeatedPtrField<Extent> extents_;
45 [[maybe_unused]] std::vector<uint8_t> buffer_;
46};
47} // namespace chromeos_update_engine