blob: e8601a99fd7394c61edd6191134cb67abcc93f87 [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 Zhange52b6cd2021-02-09 15:28:40 -050021#include <string>
Kelvin Zhang7a265752020-10-29 15:51:35 -040022#include <vector>
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040023
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040024#include <libsnapshot/snapshot_writer.h>
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040025
Kelvin Zhang7a265752020-10-29 15:51:35 -040026#include "update_engine/common/cow_operation_convert.h"
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050027#include "update_engine/payload_consumer/install_operation_executor.h"
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040028#include "update_engine/payload_consumer/install_plan.h"
29#include "update_engine/payload_consumer/partition_writer.h"
30
31namespace chromeos_update_engine {
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050032class VABCPartitionWriter final : public PartitionWriterInterface {
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040033 public:
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050034 VABCPartitionWriter(const PartitionUpdate& partition_update,
35 const InstallPlan::Partition& install_part,
36 DynamicPartitionControlInterface* dynamic_control,
37 size_t block_size,
38 bool is_interactive);
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040039 [[nodiscard]] bool Init(const InstallPlan* install_plan,
Kelvin Zhang52cb1d72020-10-27 13:44:25 -040040 bool source_may_exist,
41 size_t next_op_index) override;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040042 ~VABCPartitionWriter() override;
43
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040044 // Only ZERO and SOURCE_COPY InstallOperations are treated special by VABC
45 // Partition Writer. These operations correspond to COW_ZERO and COW_COPY. All
46 // other operations just get converted to COW_REPLACE.
47 [[nodiscard]] bool PerformZeroOrDiscardOperation(
48 const InstallOperation& operation) override;
49 [[nodiscard]] bool PerformSourceCopyOperation(
50 const InstallOperation& operation, ErrorCode* error) override;
Kelvin Zhang52cb1d72020-10-27 13:44:25 -040051
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050052 [[nodiscard]] bool PerformReplaceOperation(const InstallOperation& operation,
53 const void* data,
54 size_t count) override;
55
56 [[nodiscard]] bool PerformSourceBsdiffOperation(
57 const InstallOperation& operation,
58 ErrorCode* error,
59 const void* data,
60 size_t count) override;
61 [[nodiscard]] bool PerformPuffDiffOperation(const InstallOperation& operation,
62 ErrorCode* error,
63 const void* data,
64 size_t count) override;
65
Kelvin Zhang52cb1d72020-10-27 13:44:25 -040066 void CheckpointUpdateProgress(size_t next_op_index) override;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040067
Kelvin Zhang7a265752020-10-29 15:51:35 -040068 static bool WriteAllCowOps(size_t block_size,
69 const std::vector<CowOperation>& converted,
70 android::snapshot::ICowWriter* cow_writer,
71 FileDescriptorPtr source_fd);
72
Kelvin Zhangec205cf2020-09-28 13:23:40 -040073 [[nodiscard]] bool FinishedInstallOps() override;
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050074 int Close() override;
Kelvin Zhangec205cf2020-09-28 13:23:40 -040075
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040076 private:
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040077 std::unique_ptr<android::snapshot::ISnapshotWriter> cow_writer_;
Kelvin Zhange52b6cd2021-02-09 15:28:40 -050078
79 bool OpenCurrentECCPartition();
80 [[nodiscard]] std::unique_ptr<ExtentWriter> CreateBaseExtentWriter();
81
82 const PartitionUpdate& partition_update_;
83 const InstallPlan::Partition& install_part_;
84 DynamicPartitionControlInterface* dynamic_control_;
85 // Path to source partition
86 std::string source_path_;
87
88 const bool interactive_;
89 const size_t block_size_;
90 InstallOperationExecutor executor_;
91 VerifiedSourceFd verified_source_fd_;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040092};
93
94} // namespace chromeos_update_engine
95
96#endif