Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -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 | // |
Kelvin Zhang | b05e4e2 | 2020-09-25 16:16:19 -0400 | [diff] [blame] | 16 | |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 17 | #ifndef __COW_OPERATION_CONVERT_H |
| 18 | #define __COW_OPERATION_CONVERT_H |
| 19 | |
| 20 | #include <vector> |
| 21 | |
| 22 | #include <libsnapshot/cow_format.h> |
| 23 | |
| 24 | #include "update_engine/update_metadata.pb.h" |
| 25 | |
| 26 | namespace chromeos_update_engine { |
| 27 | struct CowOperation { |
| 28 | enum Type { |
Kelvin Zhang | c6be917 | 2023-11-28 11:17:10 -0800 | [diff] [blame] | 29 | CowCopy = static_cast<int>(android::snapshot::kCowCopyOp), |
| 30 | CowReplace = static_cast<int>(android::snapshot::kCowReplaceOp), |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 31 | }; |
Kelvin Zhang | d11e2fc | 2022-10-24 15:40:30 -0700 | [diff] [blame] | 32 | Type op{}; |
Kelvin Zhang | c14676a | 2021-10-28 16:38:20 -0700 | [diff] [blame] | 33 | uint64_t src_block{}; |
| 34 | uint64_t dst_block{}; |
| 35 | uint64_t block_count{1}; |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | // Convert SOURCE_COPY operations in `operations` list to a list of |
| 39 | // CowOperations according to the merge sequence. This function only converts |
| 40 | // SOURCE_COPY, other operations are ignored. If there's a merge conflict in |
| 41 | // SOURCE_COPY operations, some blocks may be converted to COW_REPLACE instead |
| 42 | // of COW_COPY. |
| 43 | |
| 44 | // The list returned does not necessarily preserve the order of |
| 45 | // SOURCE_COPY in `operations`. The only guarantee about ordering in the |
| 46 | // returned list is that if operations are applied in such order, there would be |
| 47 | // no merge conflicts. |
| 48 | |
| 49 | // This funnction is intended to be used by delta_performer to perform |
| 50 | // SOURCE_COPY operations on Virtual AB Compression devices. |
| 51 | std::vector<CowOperation> ConvertToCowOperations( |
| 52 | const ::google::protobuf::RepeatedPtrField< |
| 53 | ::chromeos_update_engine::InstallOperation>& operations, |
| 54 | const ::google::protobuf::RepeatedPtrField<CowMergeOperation>& |
| 55 | merge_operations); |
Kelvin Zhang | d11e2fc | 2022-10-24 15:40:30 -0700 | [diff] [blame] | 56 | |
| 57 | constexpr bool IsConsecutive(const CowOperation& op1, const CowOperation& op2) { |
| 58 | return op1.op == op2.op && op1.dst_block + op1.block_count == op2.dst_block && |
| 59 | op1.src_block + op1.block_count == op2.src_block; |
| 60 | } |
| 61 | |
| 62 | void push_back(std::vector<CowOperation>* converted, const CowOperation& op); |
| 63 | |
Kelvin Zhang | 9b10dba | 2020-09-25 17:09:11 -0400 | [diff] [blame] | 64 | } // namespace chromeos_update_engine |
| 65 | #endif |