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 | |
| 29 | namespace chromeos_update_engine { |
| 30 | |
| 31 | class DynamicPartitionControlInterface { |
| 32 | public: |
| 33 | virtual ~DynamicPartitionControlInterface() = default; |
| 34 | |
| 35 | // Return true iff dynamic partitions is enabled on this device. |
| 36 | virtual bool IsDynamicPartitionsEnabled() = 0; |
| 37 | |
Yifan Hong | 6e38b35 | 2018-11-19 14:12:37 -0800 | [diff] [blame] | 38 | // Return true iff dynamic partitions is retrofitted on this device. |
| 39 | virtual bool IsDynamicPartitionsRetrofit() = 0; |
| 40 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 41 | // Map logical partition on device-mapper. |
| 42 | // |super_device| is the device path of the physical partition ("super"). |
| 43 | // |target_partition_name| is the identifier used in metadata; for example, |
| 44 | // "vendor_a" |
| 45 | // |slot| is the selected slot to mount; for example, 0 for "_a". |
| 46 | // Returns true if mapped successfully; if so, |path| is set to the device |
| 47 | // path of the mapped logical partition. |
| 48 | virtual bool MapPartitionOnDeviceMapper( |
| 49 | const std::string& super_device, |
| 50 | const std::string& target_partition_name, |
| 51 | uint32_t slot, |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 52 | bool force_writable, |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 53 | std::string* path) = 0; |
| 54 | |
| 55 | // Unmap logical partition on device mapper. This is the reverse operation |
| 56 | // of MapPartitionOnDeviceMapper. |
| 57 | // If |wait| is set, wait until the device is unmapped. |
| 58 | // Returns true if unmapped successfully. |
| 59 | virtual bool UnmapPartitionOnDeviceMapper( |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 60 | const std::string& target_partition_name) = 0; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 61 | |
| 62 | // Do necessary cleanups before destroying the object. |
| 63 | virtual void Cleanup() = 0; |
| 64 | |
| 65 | // Return true if a static partition exists at device path |path|. |
| 66 | virtual bool DeviceExists(const std::string& path) = 0; |
| 67 | |
| 68 | // Returns the current state of the underlying device mapper device |
| 69 | // with given name. |
| 70 | // One of INVALID, SUSPENDED or ACTIVE. |
| 71 | virtual android::dm::DmDeviceState GetState(const std::string& name) = 0; |
| 72 | |
| 73 | // Returns the path to the device mapper device node in '/dev' corresponding |
| 74 | // to 'name'. If the device does not exist, false is returned, and the path |
| 75 | // parameter is not set. |
| 76 | virtual bool GetDmDevicePathByName(const std::string& name, |
| 77 | std::string* path) = 0; |
| 78 | |
| 79 | // Retrieve metadata from |super_device| at slot |source_slot|. |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 80 | // On retrofit devices, if |target_slot| != kInvalidSlot, the returned |
| 81 | // metadata automatically includes block devices at |target_slot|. |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 82 | virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder( |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 83 | const std::string& super_device, |
| 84 | uint32_t source_slot, |
| 85 | uint32_t target_slot) = 0; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 86 | |
| 87 | // Write metadata |builder| to |super_device| at slot |target_slot|. |
| 88 | virtual bool StoreMetadata(const std::string& super_device, |
| 89 | android::fs_mgr::MetadataBuilder* builder, |
| 90 | uint32_t target_slot) = 0; |
| 91 | |
| 92 | // Return a possible location for devices listed by name. |
| 93 | virtual bool GetDeviceDir(std::string* path) = 0; |
| 94 | }; |
| 95 | |
| 96 | } // namespace chromeos_update_engine |
| 97 | |
| 98 | #endif // UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_ |