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 | // |
| 16 | #ifndef __COW_OPERATION_CONVERT_H |
| 17 | #define __COW_OPERATION_CONVERT_H |
| 18 | |
| 19 | #include <vector> |
| 20 | |
| 21 | #include <libsnapshot/cow_format.h> |
| 22 | |
| 23 | #include "update_engine/update_metadata.pb.h" |
| 24 | |
| 25 | namespace chromeos_update_engine { |
| 26 | struct CowOperation { |
| 27 | enum Type { |
| 28 | CowCopy = android::snapshot::kCowCopyOp, |
| 29 | CowReplace = android::snapshot::kCowReplaceOp, |
| 30 | }; |
| 31 | Type op; |
| 32 | uint64_t src_block; |
| 33 | uint64_t dst_block; |
| 34 | }; |
| 35 | |
| 36 | // Convert SOURCE_COPY operations in `operations` list to a list of |
| 37 | // CowOperations according to the merge sequence. This function only converts |
| 38 | // SOURCE_COPY, other operations are ignored. If there's a merge conflict in |
| 39 | // SOURCE_COPY operations, some blocks may be converted to COW_REPLACE instead |
| 40 | // of COW_COPY. |
| 41 | |
| 42 | // The list returned does not necessarily preserve the order of |
| 43 | // SOURCE_COPY in `operations`. The only guarantee about ordering in the |
| 44 | // returned list is that if operations are applied in such order, there would be |
| 45 | // no merge conflicts. |
| 46 | |
| 47 | // This funnction is intended to be used by delta_performer to perform |
| 48 | // SOURCE_COPY operations on Virtual AB Compression devices. |
| 49 | std::vector<CowOperation> ConvertToCowOperations( |
| 50 | const ::google::protobuf::RepeatedPtrField< |
| 51 | ::chromeos_update_engine::InstallOperation>& operations, |
| 52 | const ::google::protobuf::RepeatedPtrField<CowMergeOperation>& |
| 53 | merge_operations); |
| 54 | } // namespace chromeos_update_engine |
| 55 | #endif |