blob: 26f486b7bbf3f2ef2895d63a07148b41fb6aa3aa [file] [log] [blame]
Hridya Valsaraju31d2c262018-07-20 13:35:50 -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#pragma once
17
David Anderson12211d12018-07-24 15:21:20 -070018#include <optional>
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070019#include <string>
20
David Anderson12211d12018-07-24 15:21:20 -070021#include <android-base/unique_fd.h>
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070022#include <android/hardware/boot/1.0/IBootControl.h>
23
David Anderson12211d12018-07-24 15:21:20 -070024// Logical partitions are only mapped to a block device as needed, and
25// immediately unmapped when no longer needed. In order to enforce this we
26// require accessing partitions through a Handle abstraction, which may perform
27// additional operations after closing its file descriptor.
28class PartitionHandle {
29 public:
30 PartitionHandle() {}
31 explicit PartitionHandle(const std::string& path) : path_(path) {}
32 const std::string& path() const { return path_; }
33 int fd() const { return fd_.get(); }
34 void set_fd(android::base::unique_fd&& fd) { fd_ = std::move(fd); }
35
36 private:
37 std::string path_;
38 android::base::unique_fd fd_;
39};
40
41class FastbootDevice;
42
43std::optional<std::string> FindPhysicalPartition(const std::string& name);
44bool OpenPartition(FastbootDevice* device, const std::string& name, PartitionHandle* handle);
45
Hridya Valsaraju31d2c262018-07-20 13:35:50 -070046bool GetSlotNumber(const std::string& slot, android::hardware::boot::V1_0::Slot* number);