blob: 9c7b8d078b03fbe09307e472ed0624f90408dd4d [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
Yifan Hong186bb682019-07-23 14:04:39 -070033struct FeatureFlag {
34 enum class Value { NONE = 0, RETROFIT, LAUNCH };
35 constexpr explicit FeatureFlag(Value value) : value_(value) {}
36 constexpr bool IsEnabled() const { return value_ != Value::NONE; }
37 constexpr bool IsRetrofit() const { return value_ == Value::RETROFIT; }
38
39 private:
40 Value value_;
41};
42
Yifan Hong537802d2018-08-15 13:15:42 -070043class DynamicPartitionControlInterface {
44 public:
45 virtual ~DynamicPartitionControlInterface() = default;
46
Yifan Hong186bb682019-07-23 14:04:39 -070047 // Return the feature flags of dynamic partitions on this device.
48 // Return RETROFIT iff dynamic partitions is retrofitted on this device,
49 // LAUNCH iff this device is launched with dynamic partitions,
50 // NONE iff dynamic partitions is disabled on this device.
51 virtual FeatureFlag GetDynamicPartitionsFeatureFlag() = 0;
Yifan Hong6e38b352018-11-19 14:12:37 -080052
Yifan Hong413d5722019-07-23 14:21:09 -070053 // Return the feature flags of Virtual A/B on this device.
54 virtual FeatureFlag GetVirtualAbFeatureFlag() = 0;
55
Yifan Hong537802d2018-08-15 13:15:42 -070056 // Map logical partition on device-mapper.
57 // |super_device| is the device path of the physical partition ("super").
58 // |target_partition_name| is the identifier used in metadata; for example,
59 // "vendor_a"
60 // |slot| is the selected slot to mount; for example, 0 for "_a".
61 // Returns true if mapped successfully; if so, |path| is set to the device
62 // path of the mapped logical partition.
63 virtual bool MapPartitionOnDeviceMapper(
64 const std::string& super_device,
65 const std::string& target_partition_name,
66 uint32_t slot,
Yifan Hongaf65ef12018-10-29 11:09:06 -070067 bool force_writable,
Yifan Hong537802d2018-08-15 13:15:42 -070068 std::string* path) = 0;
69
Yifan Hong537802d2018-08-15 13:15:42 -070070 // Do necessary cleanups before destroying the object.
71 virtual void Cleanup() = 0;
72
73 // Return true if a static partition exists at device path |path|.
74 virtual bool DeviceExists(const std::string& path) = 0;
75
76 // Returns the current state of the underlying device mapper device
77 // with given name.
78 // One of INVALID, SUSPENDED or ACTIVE.
79 virtual android::dm::DmDeviceState GetState(const std::string& name) = 0;
80
81 // Returns the path to the device mapper device node in '/dev' corresponding
82 // to 'name'. If the device does not exist, false is returned, and the path
83 // parameter is not set.
84 virtual bool GetDmDevicePathByName(const std::string& name,
85 std::string* path) = 0;
86
87 // Retrieve metadata from |super_device| at slot |source_slot|.
88 virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder(
Yifan Hong012508e2019-07-22 18:30:40 -070089 const std::string& super_device, uint32_t source_slot) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070090
Yifan Hong012508e2019-07-22 18:30:40 -070091 // Prepare all partitions for an update specified in |partition_metadata|.
92 // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the
93 // device would be mapped in an inconsistent way.
94 virtual bool PreparePartitionsForUpdate(
95 uint32_t source_slot,
96 uint32_t target_slot,
97 const BootControlInterface::PartitionMetadata& partition_metadata) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070098
99 // Return a possible location for devices listed by name.
100 virtual bool GetDeviceDir(std::string* path) = 0;
Yifan Hong700d7c12019-07-23 20:49:16 -0700101
102 // Return the name of the super partition (which stores super partition
103 // metadata) for a given slot.
104 virtual std::string GetSuperPartitionName(uint32_t slot) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -0700105};
106
107} // namespace chromeos_update_engine
108
109#endif // UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_