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 using PartitionUpdate = chromeos_update_engine::PartitionUpdate; 40 template <typename T> 41 using RepeatedPtrField = google::protobuf::RepeatedPtrField<T>; 42 43 // The metadata that will be written to target metadata slot. 44 MetadataBuilder* target_metadata = nullptr; 45 // The suffix of the target slot. 46 std::string target_suffix; 47 // The partition in target_metadata that needs to be snapshotted. 48 Partition* target_partition = nullptr; 49 // The metadata at the current slot (that would be used if the device boots 50 // normally). This is used to determine which extents are being used. 51 MetadataBuilder* current_metadata = nullptr; 52 // The suffix of the current slot. 53 std::string current_suffix; 54 // Partition information from the OTA manifest. 55 const PartitionUpdate* update = nullptr; 56 // Extra extents that are going to be invalidated during the update 57 // process. 58 std::vector<ChromeOSExtent> extra_extents = {}; 59 // True if compression is enabled. 60 bool compression_enabled = false; 61 std::string compression_algorithm; 62 63 struct Return { 64 SnapshotStatus snapshot_status; 65 std::vector<Interval> cow_partition_usable_regions; 66 }; 67 68 std::optional<Return> Run(); 69 70 private: 71 bool HasExtent(Partition* p, Extent* e); 72 std::optional<uint64_t> GetCowSize(); 73 }; 74 75 } // namespace snapshot 76 } // namespace android 77