dynamic_partition_control_interface.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_
  17. #define UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_
  18. #include <stdint.h>
  19. #include <memory>
  20. #include <string>
  21. #include <base/files/file_util.h>
  22. #include <libdm/dm.h>
  23. #include <liblp/builder.h>
  24. namespace chromeos_update_engine {
  25. class DynamicPartitionControlInterface {
  26. public:
  27. virtual ~DynamicPartitionControlInterface() = default;
  28. // Return true iff dynamic partitions is enabled on this device.
  29. virtual bool IsDynamicPartitionsEnabled() = 0;
  30. // Return true iff dynamic partitions is retrofitted on this device.
  31. virtual bool IsDynamicPartitionsRetrofit() = 0;
  32. // Map logical partition on device-mapper.
  33. // |super_device| is the device path of the physical partition ("super").
  34. // |target_partition_name| is the identifier used in metadata; for example,
  35. // "vendor_a"
  36. // |slot| is the selected slot to mount; for example, 0 for "_a".
  37. // Returns true if mapped successfully; if so, |path| is set to the device
  38. // path of the mapped logical partition.
  39. virtual bool MapPartitionOnDeviceMapper(
  40. const std::string& super_device,
  41. const std::string& target_partition_name,
  42. uint32_t slot,
  43. bool force_writable,
  44. std::string* path) = 0;
  45. // Unmap logical partition on device mapper. This is the reverse operation
  46. // of MapPartitionOnDeviceMapper.
  47. // If |wait| is set, wait until the device is unmapped.
  48. // Returns true if unmapped successfully.
  49. virtual bool UnmapPartitionOnDeviceMapper(
  50. const std::string& target_partition_name, bool wait) = 0;
  51. // Do necessary cleanups before destroying the object.
  52. virtual void Cleanup() = 0;
  53. // Return true if a static partition exists at device path |path|.
  54. virtual bool DeviceExists(const std::string& path) = 0;
  55. // Returns the current state of the underlying device mapper device
  56. // with given name.
  57. // One of INVALID, SUSPENDED or ACTIVE.
  58. virtual android::dm::DmDeviceState GetState(const std::string& name) = 0;
  59. // Returns the path to the device mapper device node in '/dev' corresponding
  60. // to 'name'. If the device does not exist, false is returned, and the path
  61. // parameter is not set.
  62. virtual bool GetDmDevicePathByName(const std::string& name,
  63. std::string* path) = 0;
  64. // Retrieve metadata from |super_device| at slot |source_slot|.
  65. // On retrofit devices, if |target_slot| != kInvalidSlot, the returned
  66. // metadata automatically includes block devices at |target_slot|.
  67. virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder(
  68. const std::string& super_device,
  69. uint32_t source_slot,
  70. uint32_t target_slot) = 0;
  71. // Write metadata |builder| to |super_device| at slot |target_slot|.
  72. virtual bool StoreMetadata(const std::string& super_device,
  73. android::fs_mgr::MetadataBuilder* builder,
  74. uint32_t target_slot) = 0;
  75. // Return a possible location for devices listed by name.
  76. virtual bool GetDeviceDir(std::string* path) = 0;
  77. };
  78. } // namespace chromeos_update_engine
  79. #endif // UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_