Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 1 | // |
| 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 Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 21 | #include <string> |
Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 22 | #include <vector> |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 23 | |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 24 | #include <libsnapshot/snapshot_writer.h> |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 25 | |
Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 26 | #include "update_engine/common/cow_operation_convert.h" |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 27 | #include "update_engine/payload_consumer/install_operation_executor.h" |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 28 | #include "update_engine/payload_consumer/install_plan.h" |
| 29 | #include "update_engine/payload_consumer/partition_writer.h" |
| 30 | |
| 31 | namespace chromeos_update_engine { |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 32 | class VABCPartitionWriter final : public PartitionWriterInterface { |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 33 | public: |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 34 | 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 Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 39 | [[nodiscard]] bool Init(const InstallPlan* install_plan, |
Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 40 | bool source_may_exist, |
| 41 | size_t next_op_index) override; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 42 | ~VABCPartitionWriter() override; |
| 43 | |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 44 | // 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 Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 51 | |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 52 | [[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 Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 66 | void CheckpointUpdateProgress(size_t next_op_index) override; |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 67 | |
Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 68 | 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 Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 73 | [[nodiscard]] bool FinishedInstallOps() override; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 74 | int Close() override; |
Kelvin Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 75 | |
Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 76 | private: |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 77 | std::unique_ptr<android::snapshot::ISnapshotWriter> cow_writer_; |
Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 78 | |
| 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 Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace chromeos_update_engine |
| 95 | |
| 96 | #endif |