blob: 0ccfcd6be2cd8ba2360c5e36224a3f1f13a5fcad [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"
Yifan Hong13d41cb2019-09-16 13:18:22 -070030#include "update_engine/update_metadata.pb.h"
Yifan Hong012508e2019-07-22 18:30:40 -070031
Yifan Hong537802d2018-08-15 13:15:42 -070032namespace chromeos_update_engine {
33
Yifan Hong186bb682019-07-23 14:04:39 -070034struct 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; }
39
40 private:
41 Value value_;
42};
43
Yifan Hong537802d2018-08-15 13:15:42 -070044class DynamicPartitionControlInterface {
45 public:
46 virtual ~DynamicPartitionControlInterface() = default;
47
Yifan Hong186bb682019-07-23 14:04:39 -070048 // Return the feature flags of dynamic partitions on this device.
49 // Return RETROFIT iff dynamic partitions is retrofitted on this device,
50 // LAUNCH iff this device is launched with dynamic partitions,
51 // NONE iff dynamic partitions is disabled on this device.
52 virtual FeatureFlag GetDynamicPartitionsFeatureFlag() = 0;
Yifan Hong6e38b352018-11-19 14:12:37 -080053
Yifan Hong413d5722019-07-23 14:21:09 -070054 // Return the feature flags of Virtual A/B on this device.
55 virtual FeatureFlag GetVirtualAbFeatureFlag() = 0;
56
Yifan Hong537802d2018-08-15 13:15:42 -070057 // Map logical partition on device-mapper.
58 // |super_device| is the device path of the physical partition ("super").
59 // |target_partition_name| is the identifier used in metadata; for example,
60 // "vendor_a"
61 // |slot| is the selected slot to mount; for example, 0 for "_a".
62 // Returns true if mapped successfully; if so, |path| is set to the device
63 // path of the mapped logical partition.
64 virtual bool MapPartitionOnDeviceMapper(
65 const std::string& super_device,
66 const std::string& target_partition_name,
67 uint32_t slot,
Yifan Hongaf65ef12018-10-29 11:09:06 -070068 bool force_writable,
Yifan Hong537802d2018-08-15 13:15:42 -070069 std::string* path) = 0;
70
Yifan Hong537802d2018-08-15 13:15:42 -070071 // Do necessary cleanups before destroying the object.
72 virtual void Cleanup() = 0;
73
74 // Return true if a static partition exists at device path |path|.
75 virtual bool DeviceExists(const std::string& path) = 0;
76
77 // Returns the current state of the underlying device mapper device
78 // with given name.
79 // One of INVALID, SUSPENDED or ACTIVE.
80 virtual android::dm::DmDeviceState GetState(const std::string& name) = 0;
81
82 // Returns the path to the device mapper device node in '/dev' corresponding
83 // to 'name'. If the device does not exist, false is returned, and the path
84 // parameter is not set.
85 virtual bool GetDmDevicePathByName(const std::string& name,
86 std::string* path) = 0;
87
88 // Retrieve metadata from |super_device| at slot |source_slot|.
89 virtual std::unique_ptr<android::fs_mgr::MetadataBuilder> LoadMetadataBuilder(
Yifan Hong012508e2019-07-22 18:30:40 -070090 const std::string& super_device, uint32_t source_slot) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070091
Yifan Hong13d41cb2019-09-16 13:18:22 -070092 // Prepare all partitions for an update specified in |manifest|.
Yifan Hong012508e2019-07-22 18:30:40 -070093 // This is needed before calling MapPartitionOnDeviceMapper(), otherwise the
94 // device would be mapped in an inconsistent way.
95 virtual bool PreparePartitionsForUpdate(
96 uint32_t source_slot,
97 uint32_t target_slot,
Yifan Hong13d41cb2019-09-16 13:18:22 -070098 const DeltaArchiveManifest& manifest) = 0;
Yifan Hong537802d2018-08-15 13:15:42 -070099
100 // Return a possible location for devices listed by name.
101 virtual bool GetDeviceDir(std::string* path) = 0;
Yifan Hong700d7c12019-07-23 20:49:16 -0700102
103 // Return the name of the super partition (which stores super partition
104 // metadata) for a given slot.
105 virtual std::string GetSuperPartitionName(uint32_t slot) = 0;
Yifan Honga33bca42019-09-03 20:29:45 -0700106
107 virtual bool FinishUpdate() = 0;
Yifan Hong537802d2018-08-15 13:15:42 -0700108};
109
110} // namespace chromeos_update_engine
111
112#endif // UPDATE_ENGINE_DYNAMIC_PARTITION_CONTROL_INTERFACE_H_