blob: 7fb2a2c69cf82b6482dbac54be41b6f3b3fcc0ee [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,
Kelvin Zhang52cb1d72020-10-27 13:44:25 -040034 bool source_may_exist,
35 size_t next_op_index) override;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040036 ~VABCPartitionWriter() override;
37
38 [[nodiscard]] std::unique_ptr<ExtentWriter> CreateBaseExtentWriter() override;
39
40 // Only ZERO and SOURCE_COPY InstallOperations are treated special by VABC
41 // Partition Writer. These operations correspond to COW_ZERO and COW_COPY. All
42 // other operations just get converted to COW_REPLACE.
43 [[nodiscard]] bool PerformZeroOrDiscardOperation(
44 const InstallOperation& operation) override;
45 [[nodiscard]] bool PerformSourceCopyOperation(
46 const InstallOperation& operation, ErrorCode* error) override;
Kelvin Zhang52cb1d72020-10-27 13:44:25 -040047
48 void CheckpointUpdateProgress(size_t next_op_index) override;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040049
Kelvin Zhang7a265752020-10-29 15:51:35 -040050 static bool WriteAllCowOps(size_t block_size,
51 const std::vector<CowOperation>& converted,
52 android::snapshot::ICowWriter* cow_writer,
53 FileDescriptorPtr source_fd);
54
Kelvin Zhangec205cf2020-09-28 13:23:40 -040055 [[nodiscard]] bool FinishedInstallOps() override;
56
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040057 private:
Kelvin Zhang9b10dba2020-09-25 17:09:11 -040058 std::unique_ptr<android::snapshot::ISnapshotWriter> cow_writer_;
Kelvin Zhang94f51cc2020-09-25 11:34:49 -040059};
60
61} // namespace chromeos_update_engine
62
63#endif