1 // Copyright (C) 2019 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <stdint.h> 18 19 #include <optional> 20 #include <string> 21 #include <vector> 22 23 #include <liblp/builder.h> 24 #include <update_engine/update_metadata.pb.h> 25 26 #include <android/snapshot/snapshot.pb.h> 27 28 namespace android { 29 namespace snapshot { 30 31 // Helper class that creates COW for a partition. 32 struct PartitionCowCreator { 33 using Extent = android::fs_mgr::Extent; 34 using ChromeOSExtent = chromeos_update_engine::Extent; 35 using Interval = android::fs_mgr::Interval; 36 using MetadataBuilder = android::fs_mgr::MetadataBuilder; 37 using Partition = android::fs_mgr::Partition; 38 using InstallOperation = chromeos_update_engine::InstallOperation; 39 template <typename T> 40 using RepeatedPtrField = google::protobuf::RepeatedPtrField<T>; 41 42 // The metadata that will be written to target metadata slot. 43 MetadataBuilder* target_metadata = nullptr; 44 // The suffix of the target slot. 45 std::string target_suffix; 46 // The partition in target_metadata that needs to be snapshotted. 47 Partition* target_partition = nullptr; 48 // The metadata at the current slot (that would be used if the device boots 49 // normally). This is used to determine which extents are being used. 50 MetadataBuilder* current_metadata = nullptr; 51 // The suffix of the current slot. 52 std::string current_suffix; 53 // List of operations to be applied on the partition. 54 const RepeatedPtrField<InstallOperation>* operations = nullptr; 55 // Extra extents that are going to be invalidated during the update 56 // process. 57 std::vector<ChromeOSExtent> extra_extents = {}; 58 59 struct Return { 60 SnapshotStatus snapshot_status; 61 std::vector<Interval> cow_partition_usable_regions; 62 }; 63 64 std::optional<Return> Run(); 65 66 private: 67 bool HasExtent(Partition* p, Extent* e); 68 uint64_t GetCowSize(); 69 }; 70 71 } // namespace snapshot 72 } // namespace android 73