Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2018 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_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_ |
| 18 | #define UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <memory> |
| 23 | #include <string> |
| 24 | |
| 25 | #include <base/files/file_util.h> |
| 26 | #include <libdm/dm.h> |
| 27 | #include <liblp/builder.h> |
| 28 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 29 | #include "update_engine/common/boot_control_interface.h" |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 30 | #include "update_engine/update_metadata.pb.h" |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 31 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 32 | namespace chromeos_update_engine { |
| 33 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 34 | struct FeatureFlag { |
| 35 | enum class Value { NONE = 0, RETROFIT, LAUNCH }; |
| 36 | constexpr explicit FeatureFlag(Value value) : value_(value) {} |
| 37 | constexpr bool IsEnabled() const { return value_ != Value::NONE; } |
| 38 | constexpr bool IsRetrofit() const { return value_ == Value::RETROFIT; } |
Yifan Hong | 6e0d0ef | 2019-10-17 14:34:22 -0700 | [diff] [blame] | 39 | constexpr bool IsLaunch() const { return value_ == Value::LAUNCH; } |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | Value value_; |
| 43 | }; |
| 44 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 45 | class DynamicPartitionControlInterface { |
| 46 | public: |
| 47 | virtual ~DynamicPartitionControlInterface() = default; |
| 48 | |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 49 | // Return the feature flags of dynamic partitions on this device. |
| 50 | // Return RETROFIT iff dynamic partitions is retrofitted on this device, |
| 51 | // LAUNCH iff this device is launched with dynamic partitions, |
| 52 | // NONE iff dynamic partitions is disabled on this device. |
| 53 | virtual FeatureFlag GetDynamicPartitionsFeatureFlag() = 0; |
Yifan Hong | 6e38b35 | 2018-11-19 14:12:37 -0800 | [diff] [blame] | 54 | |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 55 | // Return the feature flags of Virtual A/B on this device. |
| 56 | virtual FeatureFlag GetVirtualAbFeatureFlag() = 0; |
| 57 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 58 | // Map logical partition on device-mapper. |
| 59 | // |super_device| is the device path of the physical partition ("super"). |
| 60 | // |target_partition_name| is the identifier used in metadata; for example, |
| 61 | // "vendor_a" |
| 62 | // |slot| is the selected slot to mount; for example, 0 for "_a". |
| 63 | // Returns true if mapped successfully; if so, |path| is set to the device |
| 64 | // path of the mapped logical partition. |
| 65 | virtual bool MapPartitionOnDeviceMapper( |
| 66 | const std::string& super_device, |
| 67 | const std::string& target_partition_name, |
| 68 | uint32_t slot, |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 69 | bool force_writable, |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 70 | std::string* path) = 0; |
| 71 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 72 | // Do necessary cleanups before destroying the object. |
| 73 | virtual void Cleanup() = 0; |
| 74 | |
| 75 | // Return true if a static partition exists at device path |path|. |
| 76 | virtual bool DeviceExists(const std::string& path) = 0; |
| 77 | |
| 78 | // Returns the current state of the underlying device mapper device |
| 79 | // with given name. |
| 80 | // One of INVALID, SUSPENDED or ACTIVE. |
| 81 | virtual android::dm::DmDeviceState GetState(const std::string& name) = 0; |
| 82 | |
| 83 | // Returns the path to the device mapper device node in '/dev' corresponding |
| 84 | // to 'name'. If the device does not exist, false is returned, and the path |
| 85 | // parameter is not set. |
| 86 | virtual bool GetDmDevicePathByName(const std::string& name, |
| 87 | std::string* path) = 0; |
| 88 | |
| 89 | // Retrieve metadata from |super_device| at slot |source_slot|. |
| 90 | virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder( |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 91 | const std::string& super_device, uint32_t source_slot) = 0; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 92 | |
Yifan Hong | 13d41cb | 2019-09-16 13:18:22 -0700 | [diff] [blame] | 93 | // Prepare all partitions for an update specified in |manifest|. |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 94 | // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the |
| 95 | // device would be mapped in an inconsistent way. |
Yifan Hong | f0f4a91 | 2019-09-26 17:51:33 -0700 | [diff] [blame] | 96 | // If |update| is set, create snapshots and writes super partition metadata. |
| 97 | virtual bool PreparePartitionsForUpdate(uint32_t source_slot, |
| 98 | uint32_t target_slot, |
| 99 | const DeltaArchiveManifest& manifest, |
| 100 | bool update) = 0; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 101 | |
| 102 | // Return a possible location for devices listed by name. |
| 103 | virtual bool GetDeviceDir(std::string* path) = 0; |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 104 | |
| 105 | // Return the name of the super partition (which stores super partition |
| 106 | // metadata) for a given slot. |
| 107 | virtual std::string GetSuperPartitionName(uint32_t slot) = 0; |
Yifan Hong | a33bca4 | 2019-09-03 20:29:45 -0700 | [diff] [blame] | 108 | |
| 109 | virtual bool FinishUpdate() = 0; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace chromeos_update_engine |
| 113 | |
| 114 | #endif // UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_ |