blob: 12e62e08ba5b67a80e9ec1163f008c57d02da63a [file] [log] [blame]
Yifan Hong537802d2018-08-15 13:15:42 -07001//
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 Hong012508e2019-07-22 18:30:40 -070029#include "update_engine/common/boot_control_interface.h"
30
Yifan Hong537802d2018-08-15 13:15:42 -070031namespace chromeos_update_engine {
32
33class DynamicPartitionControlInterface {
34 public:
35 virtual ~DynamicPartitionControlInterface() = default;
36
37 // Return true iff dynamic partitions is enabled on this device.
38 virtual bool IsDynamicPartitionsEnabled() = 0;
39
Yifan Hong6e38b352018-11-19 14:12:37 -080040 // Return true iff dynamic partitions is retrofitted on this device.
41 virtual bool IsDynamicPartitionsRetrofit() = 0;
42
Yifan Hong537802d2018-08-15 13:15:42 -070043 // Map logical partition on device-mapper.
44 // |super_device| is the device path of the physical partition ("super").
45 // |target_partition_name| is the identifier used in metadata; for example,
46 // "vendor_a"
47 // |slot| is the selected slot to mount; for example, 0 for "_a".
48 // Returns true if mapped successfully; if so, |path| is set to the device
49 // path of the mapped logical partition.
50 virtual bool MapPartitionOnDeviceMapper(
51 const std::string& super_device,
52 const std::string& target_partition_name,
53 uint32_t slot,
Yifan Hongaf65ef12018-10-29 11:09:06 -070054 bool force_writable,
Yifan Hong537802d2018-08-15 13:15:42 -070055 std::string* path) = 0;
56
Yifan Hong537802d2018-08-15 13:15:42 -070057 // Do necessary cleanups before destroying the object.
58 virtual void Cleanup() = 0;
59
60 // Return true if a static partition exists at device path |path|.
61 virtual bool DeviceExists(const std::string& path) = 0;
62
63 // Returns the current state of the underlying device mapper device
64 // with given name.
65 // One of INVALID, SUSPENDED or ACTIVE.
66 virtual android::dm::DmDeviceState GetState(const std::string& name) = 0;
67
68 // Returns the path to the device mapper device node in '/dev' corresponding
69 // to 'name'. If the device does not exist, false is returned, and the path
70 // parameter is not set.
71 virtual bool GetDmDevicePathByName(const std::string& name,
72 std::string* path) = 0;
73
74 // Retrieve metadata from |super_device| at slot |source_slot|.
75 virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder(
Yifan Hong012508e2019-07-22 18:30:40 -070076 const std::string& super_device, uint32_t source_slot) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070077
Yifan Hong012508e2019-07-22 18:30:40 -070078 // Prepare all partitions for an update specified in |partition_metadata|.
79 // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the
80 // device would be mapped in an inconsistent way.
81 virtual bool PreparePartitionsForUpdate(
82 uint32_t source_slot,
83 uint32_t target_slot,
84 const BootControlInterface::PartitionMetadata& partition_metadata) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070085
86 // Return a possible location for devices listed by name.
87 virtual bool GetDeviceDir(std::string* path) = 0;
88};
89
90} // namespace chromeos_update_engine
91
92#endif // UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_