Android-cuttlefish cvd tool
super_flash_helper.h
Go to the documentation of this file.
1//
2// Copyright (C) 2023 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#pragma once
18
19#include <memory>
20#include <string>
21#include <unordered_map>
22#include <unordered_set>
23
25#include <liblp/liblp.h>
26#include <liblp/super_layout_builder.h>
27
28#include "util.h"
29
30class SuperFlashHelper final {
31 public:
32 explicit SuperFlashHelper(const ImageSource& source);
33
35 bool IncludeInSuper(const std::string& partition);
36 bool AddPartition(const std::string& partition, const std::string& image_name, bool optional);
37
38 // Note: the SparsePtr if non-null should not outlive SuperFlashHelper, since
39 // it depends on open fds and data pointers.
41
42 bool WillFlash(const std::string& partition) const {
43 return will_flash_.find(partition) != will_flash_.end();
44 }
45
46 private:
48 android::fs_mgr::SuperLayoutBuilder builder_;
49 std::unique_ptr<android::fs_mgr::LpMetadata> base_metadata_;
50 std::vector<android::fs_mgr::SuperImageExtent> extents_;
51
52 // Cache open image fds. This keeps them alive while we flash the sparse
53 // file.
54 std::unordered_map<std::string, android::base::unique_fd> image_fds_;
55 std::unordered_set<std::string> will_flash_;
56};
Definition: util.h:51
Definition: super_flash_helper.h:30
std::unique_ptr< android::fs_mgr::LpMetadata > base_metadata_
Definition: super_flash_helper.h:49
SuperFlashHelper(const ImageSource &source)
Definition: super_flash_helper.cpp:27
const ImageSource & source_
Definition: super_flash_helper.h:47
bool IncludeInSuper(const std::string &partition)
Definition: super_flash_helper.cpp:39
bool WillFlash(const std::string &partition) const
Definition: super_flash_helper.h:42
SparsePtr GetSparseLayout()
Definition: super_flash_helper.cpp:73
std::unordered_set< std::string > will_flash_
Definition: super_flash_helper.h:55
std::unordered_map< std::string, android::base::unique_fd > image_fds_
Definition: super_flash_helper.h:54
bool Open(android::base::borrowed_fd fd)
Definition: super_flash_helper.cpp:29
std::vector< android::fs_mgr::SuperImageExtent > extents_
Definition: super_flash_helper.h:50
bool AddPartition(const std::string &partition, const std::string &image_name, bool optional)
Definition: super_flash_helper.cpp:43
android::fs_mgr::SuperLayoutBuilder builder_
Definition: super_flash_helper.h:48
std::unique_ptr< sparse_file, decltype(&sparse_file_destroy)> SparsePtr
Definition: util.h:30
Definition: unique_fd.h:292