Kelvin Zhang | e52b6cd | 2021-02-09 15:28:40 -0500 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2021 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_PARTITION_WRITER_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_PARTITION_WRITER_INTERFACE_H_ |
| 19 | |
| 20 | #include <cstdint> |
| 21 | #include <string> |
| 22 | |
| 23 | #include <brillo/secure_blob.h> |
| 24 | #include <gtest/gtest_prod.h> |
| 25 | |
| 26 | #include "update_engine/common/dynamic_partition_control_interface.h" |
| 27 | #include "update_engine/payload_consumer/extent_writer.h" |
| 28 | #include "update_engine/payload_consumer/file_descriptor.h" |
| 29 | #include "update_engine/payload_consumer/install_plan.h" |
| 30 | #include "update_engine/update_metadata.pb.h" |
| 31 | |
| 32 | namespace chromeos_update_engine { |
| 33 | class PartitionWriterInterface { |
| 34 | public: |
| 35 | virtual ~PartitionWriterInterface() = default; |
| 36 | |
| 37 | // Perform necessary initialization work before InstallOperation can be |
| 38 | // applied to this partition |
| 39 | [[nodiscard]] virtual bool Init(const InstallPlan* install_plan, |
| 40 | bool source_may_exist, |
| 41 | size_t next_op_index) = 0; |
| 42 | |
| 43 | // |CheckpointUpdateProgress| will be called after SetNextOpIndex(), but it's |
| 44 | // optional. DeltaPerformer may or may not call this everytime an operation is |
| 45 | // applied. |
| 46 | // |next_op_index| is index of next operation that should be applied. |
| 47 | // |next_op_index-1| is the last operation that is already applied. |
| 48 | virtual void CheckpointUpdateProgress(size_t next_op_index) = 0; |
| 49 | |
| 50 | // Close partition writer, when calling this function there's no guarantee |
| 51 | // that all |InstallOperations| are sent to |PartitionWriter|. This function |
| 52 | // will be called even if we are pausing/aborting the update. |
| 53 | virtual int Close() = 0; |
| 54 | |
| 55 | // These perform a specific type of operation and return true on success. |
| 56 | // |error| will be set if source hash mismatch, otherwise |error| might not be |
| 57 | // set even if it fails. |
| 58 | [[nodiscard]] virtual bool PerformReplaceOperation( |
| 59 | const InstallOperation& operation, const void* data, size_t count) = 0; |
| 60 | [[nodiscard]] virtual bool PerformZeroOrDiscardOperation( |
| 61 | const InstallOperation& operation) = 0; |
| 62 | |
| 63 | [[nodiscard]] virtual bool PerformSourceCopyOperation( |
| 64 | const InstallOperation& operation, ErrorCode* error) = 0; |
| 65 | [[nodiscard]] virtual bool PerformSourceBsdiffOperation( |
| 66 | const InstallOperation& operation, |
| 67 | ErrorCode* error, |
| 68 | const void* data, |
| 69 | size_t count) = 0; |
| 70 | [[nodiscard]] virtual bool PerformPuffDiffOperation( |
| 71 | const InstallOperation& operation, |
| 72 | ErrorCode* error, |
| 73 | const void* data, |
| 74 | size_t count) = 0; |
| 75 | |
| 76 | // |DeltaPerformer| calls this when all Install Ops are sent to partition |
| 77 | // writer. No |Perform*Operation| methods will be called in the future, and |
| 78 | // the partition writer is expected to be closed soon. |
| 79 | [[nodiscard]] virtual bool FinishedInstallOps() = 0; |
| 80 | }; |
| 81 | } // namespace chromeos_update_engine |
| 82 | |
| 83 | #endif |