• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef __CORE_FS_MGR_DM_LINEAR_H
26 #define __CORE_FS_MGR_DM_LINEAR_H
27 
28 #include <stdint.h>
29 
30 #include <chrono>
31 #include <memory>
32 #include <string>
33 #include <vector>
34 
35 #include <libdm/dm.h>
36 #include <liblp/liblp.h>
37 
38 namespace android {
39 namespace fs_mgr {
40 
41 // Read metadata from the current slot.
42 std::unique_ptr<LpMetadata> ReadCurrentMetadata(const std::string& block_device);
43 
44 // Create block devices for all logical partitions in the given metadata. The
45 // metadata must have been read from the current slot.
46 bool CreateLogicalPartitions(const LpMetadata& metadata, const std::string& block_device);
47 
48 // Create block devices for all logical partitions. This is a convenience
49 // method for ReadMetadata and CreateLogicalPartitions.
50 bool CreateLogicalPartitions(const std::string& block_device);
51 
52 // Create a block device for a single logical partition, given metadata and
53 // the partition name. On success, a path to the partition's block device is
54 // returned. If |force_writable| is true, the "readonly" flag will be ignored
55 // so the partition can be flashed.
56 //
57 // If |timeout_ms| is non-zero, then CreateLogicalPartition will block for the
58 // given amount of time until the path returned in |path| is available.
59 bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_slot,
60                             const std::string& partition_name, bool force_writable,
61                             const std::chrono::milliseconds& timeout_ms, std::string* path);
62 
63 // Same as above, but with a given metadata object. Care should be taken that
64 // the metadata represents a valid partition layout.
65 bool CreateLogicalPartition(const std::string& block_device, const LpMetadata& metadata,
66                             const std::string& partition_name, bool force_writable,
67                             const std::chrono::milliseconds& timeout_ms, std::string* path);
68 
69 // Destroy the block device for a logical partition, by name. If |timeout_ms|
70 // is non-zero, then this will block until the device path has been unlinked.
71 bool DestroyLogicalPartition(const std::string& name, const std::chrono::milliseconds& timeout_ms);
72 
73 }  // namespace fs_mgr
74 }  // namespace android
75 
76 #endif  // __CORE_FS_MGR_DM_LINEAR_H
77