blob: 5eab23fab66fdad42566b3d1a6268a1d1119de8c [file] [log] [blame]
Kelvin Zhang94f51cc2020-09-25 11:34:49 -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
17#ifndef UPDATE_ENGINE_VABC_PARTITION_WRITER_H_
18#define UPDATE_ENGINE_VABC_PARTITION_WRITER_H_
19
20#include <memory>
Kelvin Zhang7a265752020-10-29 15:51:35 -040021#include <vector>
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040022
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040023#include <libsnapshot/snapshot_writer.h>
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040024
Kelvin Zhang7a265752020-10-29 15:51:35 -040025#include "update_engine/common/cow_operation_convert.h"
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040026#include "update_engine/payload_consumer/install_plan.h"
27#include "update_engine/payload_consumer/partition_writer.h"
28
29namespace chromeos_update_engine {
30class VABCPartitionWriter final : public PartitionWriter {
31 public:
32 using PartitionWriter::PartitionWriter;
33 [[nodiscard]] bool Init(const InstallPlan* install_plan,
34 bool source_may_exist) override;
35 ~VABCPartitionWriter() override;
36
37 [[nodiscard]] std::unique_ptr<ExtentWriter> CreateBaseExtentWriter() override;
38
39 // Only ZERO and SOURCE_COPY InstallOperations are treated special by VABC
40 // Partition Writer. These operations correspond to COW_ZERO and COW_COPY. All
41 // other operations just get converted to COW_REPLACE.
42 [[nodiscard]] bool PerformZeroOrDiscardOperation(
43 const InstallOperation& operation) override;
44 [[nodiscard]] bool PerformSourceCopyOperation(
45 const InstallOperation& operation, ErrorCode* error) override;
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040046 [[nodiscard]] bool Flush() override;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040047
Kelvin Zhang7a265752020-10-29 15:51:35 -040048 static bool WriteAllCowOps(size_t block_size,
49 const std::vector<CowOperation>& converted,
50 android::snapshot::ICowWriter* cow_writer,
51 FileDescriptorPtr source_fd);
52
Kelvin Zhangec205cf2020-09-28 13:23:40 -040053 [[nodiscard]] bool FinishedInstallOps() override;
54
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040055 private:
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040056 std::unique_ptr<android::snapshot::ISnapshotWriter> cow_writer_;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040057};
58
59} // namespace chromeos_update_engine
60
61#endif