| 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 | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 21 | #include <vector> | 
| Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 22 |  | 
| Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 23 | #include <libsnapshot/snapshot_writer.h> | 
| Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 24 |  | 
| Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 25 | #include "update_engine/common/cow_operation_convert.h" | 
| Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 26 | #include "update_engine/payload_consumer/install_plan.h" | 
|  | 27 | #include "update_engine/payload_consumer/partition_writer.h" | 
|  | 28 |  | 
|  | 29 | namespace chromeos_update_engine { | 
|  | 30 | class VABCPartitionWriter final : public PartitionWriter { | 
|  | 31 | public: | 
|  | 32 | using PartitionWriter::PartitionWriter; | 
|  | 33 | [[nodiscard]] bool Init(const InstallPlan* install_plan, | 
| Kelvin Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 34 | bool source_may_exist, | 
|  | 35 | size_t next_op_index) override; | 
| Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 36 | ~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 Zhang | 52cb1d7 | 2020-10-27 13:44:25 -0400 | [diff] [blame] | 47 |  | 
|  | 48 | void CheckpointUpdateProgress(size_t next_op_index) override; | 
| Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 49 |  | 
| Kelvin Zhang | 7a26575 | 2020-10-29 15:51:35 -0400 | [diff] [blame] | 50 | 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 Zhang | ec205cf | 2020-09-28 13:23:40 -0400 | [diff] [blame] | 55 | [[nodiscard]] bool FinishedInstallOps() override; | 
|  | 56 |  | 
| Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 57 | private: | 
| Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 58 | std::unique_ptr<android::snapshot::ISnapshotWriter> cow_writer_; | 
| Kelvin Zhang | 94f51cc | 2020-09-25 11:34:49 -0400 | [diff] [blame] | 59 | }; | 
|  | 60 |  | 
|  | 61 | }  // namespace chromeos_update_engine | 
|  | 62 |  | 
|  | 63 | #endif |