diff options
author | Treehugger Robot | 2018-07-12 17:55:35 -0500 |
---|---|---|
committer | Gerrit Code Review | 2018-07-12 17:55:35 -0500 |
commit | b3994563038ed53ed15843a84e5d6fa2fea762f8 (patch) | |
tree | acad5600c0bc2ac00a797bfe266320184f0efbb0 | |
parent | 5dce8ce74741e96efd7b2fbe32f6c92b3ccbc860 (diff) | |
parent | 9c3c29466a44cc7b334020627c8d9de983cdd052 (diff) | |
download | platform-system-core-b3994563038ed53ed15843a84e5d6fa2fea762f8.tar.gz platform-system-core-b3994563038ed53ed15843a84e5d6fa2fea762f8.tar.xz platform-system-core-b3994563038ed53ed15843a84e5d6fa2fea762f8.zip |
Merge "liblp: Clean up public headers."
-rw-r--r-- | fs_mgr/liblp/builder.cpp | 4 | ||||
-rw-r--r-- | fs_mgr/liblp/include/liblp/builder.h | 2 | ||||
-rw-r--r-- | fs_mgr/liblp/include/liblp/liblp.h | 75 | ||||
-rw-r--r-- | fs_mgr/liblp/include/liblp/metadata_format.h | 24 | ||||
-rw-r--r-- | fs_mgr/liblp/io_test.cpp | 4 | ||||
-rw-r--r-- | fs_mgr/liblp/reader.cpp | 4 | ||||
-rw-r--r-- | fs_mgr/liblp/reader.h (renamed from fs_mgr/liblp/include/liblp/reader.h) | 8 | ||||
-rw-r--r-- | fs_mgr/liblp/utility_test.cpp | 4 | ||||
-rw-r--r-- | fs_mgr/liblp/writer.cpp | 5 | ||||
-rw-r--r-- | fs_mgr/liblp/writer.h (renamed from fs_mgr/liblp/include/liblp/writer.h) | 20 |
10 files changed, 91 insertions, 59 deletions
diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp index 720590dfa..d15fa8c17 100644 --- a/fs_mgr/liblp/builder.cpp +++ b/fs_mgr/liblp/builder.cpp | |||
@@ -27,8 +27,8 @@ | |||
27 | #include <android-base/unique_fd.h> | 27 | #include <android-base/unique_fd.h> |
28 | #include <uuid/uuid.h> | 28 | #include <uuid/uuid.h> |
29 | 29 | ||
30 | #include "liblp/metadata_format.h" | 30 | #include "liblp/liblp.h" |
31 | #include "liblp/reader.h" | 31 | #include "reader.h" |
32 | #include "utility.h" | 32 | #include "utility.h" |
33 | 33 | ||
34 | namespace android { | 34 | namespace android { |
diff --git a/fs_mgr/liblp/include/liblp/builder.h b/fs_mgr/liblp/include/liblp/builder.h index 3cd95aed7..8bde3132c 100644 --- a/fs_mgr/liblp/include/liblp/builder.h +++ b/fs_mgr/liblp/include/liblp/builder.h | |||
@@ -23,7 +23,7 @@ | |||
23 | #include <map> | 23 | #include <map> |
24 | #include <memory> | 24 | #include <memory> |
25 | 25 | ||
26 | #include "metadata_format.h" | 26 | #include "liblp.h" |
27 | 27 | ||
28 | namespace android { | 28 | namespace android { |
29 | namespace fs_mgr { | 29 | namespace fs_mgr { |
diff --git a/fs_mgr/liblp/include/liblp/liblp.h b/fs_mgr/liblp/include/liblp/liblp.h new file mode 100644 index 000000000..469ef9e59 --- /dev/null +++ b/fs_mgr/liblp/include/liblp/liblp.h | |||
@@ -0,0 +1,75 @@ | |||
1 | // | ||
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 LIBLP_LIBLP_H | ||
18 | #define LIBLP_LIBLP_H | ||
19 | |||
20 | #include <stddef.h> | ||
21 | #include <stdint.h> | ||
22 | |||
23 | #include <memory> | ||
24 | #include <string> | ||
25 | |||
26 | #include "metadata_format.h" | ||
27 | |||
28 | namespace android { | ||
29 | namespace fs_mgr { | ||
30 | |||
31 | // Helper structure for easily interpreting deserialized metadata, or | ||
32 | // re-serializing metadata. | ||
33 | struct LpMetadata { | ||
34 | LpMetadataGeometry geometry; | ||
35 | LpMetadataHeader header; | ||
36 | std::vector<LpMetadataPartition> partitions; | ||
37 | std::vector<LpMetadataExtent> extents; | ||
38 | }; | ||
39 | |||
40 | // Place an initial partition table on the device. This will overwrite the | ||
41 | // existing geometry, and should not be used for normal partition table | ||
42 | // updates. False can be returned if the geometry is incompatible with the | ||
43 | // block device or an I/O error occurs. | ||
44 | bool FlashPartitionTable(const std::string& block_device, const LpMetadata& metadata, | ||
45 | uint32_t slot_number); | ||
46 | |||
47 | // Update the partition table for a given metadata slot number. False is | ||
48 | // returned if an error occurs, which can include: | ||
49 | // - Invalid slot number. | ||
50 | // - I/O error. | ||
51 | // - Corrupt or missing metadata geometry on disk. | ||
52 | // - Incompatible geometry. | ||
53 | bool UpdatePartitionTable(const std::string& block_device, const LpMetadata& metadata, | ||
54 | uint32_t slot_number); | ||
55 | |||
56 | // Read logical partition metadata from its predetermined location on a block | ||
57 | // device. If readback fails, we also attempt to load from a backup copy. | ||
58 | std::unique_ptr<LpMetadata> ReadMetadata(const char* block_device, uint32_t slot_number); | ||
59 | |||
60 | // Read/Write logical partition metadata to an image file, for diagnostics or | ||
61 | // flashing. | ||
62 | bool WriteToImageFile(const char* file, const LpMetadata& metadata); | ||
63 | std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file); | ||
64 | |||
65 | // Helper to extract safe C++ strings from partition info. | ||
66 | std::string GetPartitionName(const LpMetadataPartition& partition); | ||
67 | std::string GetPartitionGuid(const LpMetadataPartition& partition); | ||
68 | |||
69 | // Helper to return a slot number for a slot suffix. | ||
70 | uint32_t SlotNumberForSlotSuffix(const std::string& suffix); | ||
71 | |||
72 | } // namespace fs_mgr | ||
73 | } // namespace android | ||
74 | |||
75 | #endif // LIBLP_LIBLP_H | ||
diff --git a/fs_mgr/liblp/include/liblp/metadata_format.h b/fs_mgr/liblp/include/liblp/metadata_format.h index 27602acbe..f3a0815c8 100644 --- a/fs_mgr/liblp/include/liblp/metadata_format.h +++ b/fs_mgr/liblp/include/liblp/metadata_format.h | |||
@@ -262,28 +262,4 @@ typedef struct LpMetadataExtent { | |||
262 | } /* extern "C" */ | 262 | } /* extern "C" */ |
263 | #endif | 263 | #endif |
264 | 264 | ||
265 | #ifdef __cplusplus | ||
266 | namespace android { | ||
267 | namespace fs_mgr { | ||
268 | |||
269 | // Helper structure for easily interpreting deserialized metadata, or | ||
270 | // re-serializing metadata. | ||
271 | struct LpMetadata { | ||
272 | LpMetadataGeometry geometry; | ||
273 | LpMetadataHeader header; | ||
274 | std::vector<LpMetadataPartition> partitions; | ||
275 | std::vector<LpMetadataExtent> extents; | ||
276 | }; | ||
277 | |||
278 | // Helper to extract safe C++ strings from partition info. | ||
279 | std::string GetPartitionName(const LpMetadataPartition& partition); | ||
280 | std::string GetPartitionGuid(const LpMetadataPartition& partition); | ||
281 | |||
282 | // Helper to return a slot number for a slot suffix. | ||
283 | uint32_t SlotNumberForSlotSuffix(const std::string& suffix); | ||
284 | |||
285 | } // namespace fs_mgr | ||
286 | } // namespace android | ||
287 | #endif | ||
288 | |||
289 | #endif /* LOGICAL_PARTITION_METADATA_FORMAT_H_ */ | 265 | #endif /* LOGICAL_PARTITION_METADATA_FORMAT_H_ */ |
diff --git a/fs_mgr/liblp/io_test.cpp b/fs_mgr/liblp/io_test.cpp index de10eb62f..e91cc3e0a 100644 --- a/fs_mgr/liblp/io_test.cpp +++ b/fs_mgr/liblp/io_test.cpp | |||
@@ -23,10 +23,10 @@ | |||
23 | #include <android-base/unique_fd.h> | 23 | #include <android-base/unique_fd.h> |
24 | #include <gtest/gtest.h> | 24 | #include <gtest/gtest.h> |
25 | #include <liblp/builder.h> | 25 | #include <liblp/builder.h> |
26 | #include <liblp/reader.h> | ||
27 | #include <liblp/writer.h> | ||
28 | 26 | ||
27 | #include "reader.h" | ||
29 | #include "utility.h" | 28 | #include "utility.h" |
29 | #include "writer.h" | ||
30 | 30 | ||
31 | using namespace std; | 31 | using namespace std; |
32 | using namespace android::fs_mgr; | 32 | using namespace android::fs_mgr; |
diff --git a/fs_mgr/liblp/reader.cpp b/fs_mgr/liblp/reader.cpp index d680bafa3..985cf0991 100644 --- a/fs_mgr/liblp/reader.cpp +++ b/fs_mgr/liblp/reader.cpp | |||
@@ -14,7 +14,7 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "liblp/reader.h" | 17 | #include "reader.h" |
18 | 18 | ||
19 | #include <stddef.h> | 19 | #include <stddef.h> |
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
@@ -165,8 +165,6 @@ static bool ValidateMetadataHeader(const LpMetadataHeader& header) { | |||
165 | return true; | 165 | return true; |
166 | } | 166 | } |
167 | 167 | ||
168 | using ReadMetadataFn = std::function<bool(void* buffer, size_t num_bytes)>; | ||
169 | |||
170 | // Parse and validate all metadata at the current position in the given file | 168 | // Parse and validate all metadata at the current position in the given file |
171 | // descriptor. | 169 | // descriptor. |
172 | static std::unique_ptr<LpMetadata> ParseMetadata(int fd) { | 170 | static std::unique_ptr<LpMetadata> ParseMetadata(int fd) { |
diff --git a/fs_mgr/liblp/include/liblp/reader.h b/fs_mgr/liblp/reader.h index 9f014417c..c4cac8fcb 100644 --- a/fs_mgr/liblp/include/liblp/reader.h +++ b/fs_mgr/liblp/reader.h | |||
@@ -21,14 +21,11 @@ | |||
21 | 21 | ||
22 | #include <memory> | 22 | #include <memory> |
23 | 23 | ||
24 | #include "metadata_format.h" | 24 | #include <liblp/liblp.h> |
25 | 25 | ||
26 | namespace android { | 26 | namespace android { |
27 | namespace fs_mgr { | 27 | namespace fs_mgr { |
28 | 28 | ||
29 | // Read logical partition metadata from its predetermined location on a block | ||
30 | // device. If readback fails, we also attempt to load from a backup copy. | ||
31 | std::unique_ptr<LpMetadata> ReadMetadata(const char* block_device, uint32_t slot_number); | ||
32 | std::unique_ptr<LpMetadata> ReadMetadata(int fd, uint32_t slot_number); | 29 | std::unique_ptr<LpMetadata> ReadMetadata(int fd, uint32_t slot_number); |
33 | 30 | ||
34 | // Helper functions for manually reading geometry and metadata. | 31 | // Helper functions for manually reading geometry and metadata. |
@@ -40,9 +37,6 @@ std::unique_ptr<LpMetadata> ReadPrimaryMetadata(int fd, const LpMetadataGeometry | |||
40 | std::unique_ptr<LpMetadata> ReadBackupMetadata(int fd, const LpMetadataGeometry& geometry, | 37 | std::unique_ptr<LpMetadata> ReadBackupMetadata(int fd, const LpMetadataGeometry& geometry, |
41 | uint32_t slot_number); | 38 | uint32_t slot_number); |
42 | 39 | ||
43 | // Read logical partition metadata from an image file that was created with | ||
44 | // WriteToImageFile(). | ||
45 | std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file); | ||
46 | std::unique_ptr<LpMetadata> ReadFromImageFile(int fd); | 40 | std::unique_ptr<LpMetadata> ReadFromImageFile(int fd); |
47 | 41 | ||
48 | } // namespace fs_mgr | 42 | } // namespace fs_mgr |
diff --git a/fs_mgr/liblp/utility_test.cpp b/fs_mgr/liblp/utility_test.cpp index dcc569e0e..2143e13de 100644 --- a/fs_mgr/liblp/utility_test.cpp +++ b/fs_mgr/liblp/utility_test.cpp | |||
@@ -14,8 +14,10 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "utility.h" | ||
18 | #include <gtest/gtest.h> | 17 | #include <gtest/gtest.h> |
18 | #include <liblp/liblp.h> | ||
19 | |||
20 | #include "utility.h" | ||
19 | 21 | ||
20 | using namespace android; | 22 | using namespace android; |
21 | using namespace android::fs_mgr; | 23 | using namespace android::fs_mgr; |
diff --git a/fs_mgr/liblp/writer.cpp b/fs_mgr/liblp/writer.cpp index 963974c9f..b85e4ad6c 100644 --- a/fs_mgr/liblp/writer.cpp +++ b/fs_mgr/liblp/writer.cpp | |||
@@ -14,6 +14,8 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "writer.h" | ||
18 | |||
17 | #include <inttypes.h> | 19 | #include <inttypes.h> |
18 | #include <unistd.h> | 20 | #include <unistd.h> |
19 | 21 | ||
@@ -22,8 +24,7 @@ | |||
22 | #include <android-base/file.h> | 24 | #include <android-base/file.h> |
23 | #include <android-base/unique_fd.h> | 25 | #include <android-base/unique_fd.h> |
24 | 26 | ||
25 | #include "liblp/reader.h" | 27 | #include "reader.h" |
26 | #include "liblp/writer.h" | ||
27 | #include "utility.h" | 28 | #include "utility.h" |
28 | 29 | ||
29 | namespace android { | 30 | namespace android { |
diff --git a/fs_mgr/liblp/include/liblp/writer.h b/fs_mgr/liblp/writer.h index da38a4cd4..94c1d3195 100644 --- a/fs_mgr/liblp/include/liblp/writer.h +++ b/fs_mgr/liblp/writer.h | |||
@@ -18,27 +18,13 @@ | |||
18 | #define LIBLP_WRITER_H | 18 | #define LIBLP_WRITER_H |
19 | 19 | ||
20 | #include <functional> | 20 | #include <functional> |
21 | #include "metadata_format.h" | 21 | #include <string> |
22 | |||
23 | #include <liblp/liblp.h> | ||
22 | 24 | ||
23 | namespace android { | 25 | namespace android { |
24 | namespace fs_mgr { | 26 | namespace fs_mgr { |
25 | 27 | ||
26 | // Place an initial partition table on the device. This will overwrite the | ||
27 | // existing geometry, and should not be used for normal partition table | ||
28 | // updates. False can be returned if the geometry is incompatible with the | ||
29 | // block device or an I/O error occurs. | ||
30 | bool FlashPartitionTable(const std::string& block_device, const LpMetadata& metadata, | ||
31 | uint32_t slot_number); | ||
32 | |||
33 | // Update the partition table for a given metadata slot number. False is | ||
34 | // returned if an error occurs, which can include: | ||
35 | // - Invalid slot number. | ||
36 | // - I/O error. | ||
37 | // - Corrupt or missing metadata geometry on disk. | ||
38 | // - Incompatible geometry. | ||
39 | bool UpdatePartitionTable(const std::string& block_device, const LpMetadata& metadata, | ||
40 | uint32_t slot_number); | ||
41 | |||
42 | // These variants are for testing only. The path-based functions should be used | 28 | // These variants are for testing only. The path-based functions should be used |
43 | // for actual operation, so that open() is called with the correct flags. | 29 | // for actual operation, so that open() is called with the correct flags. |
44 | bool FlashPartitionTable(int fd, const LpMetadata& metadata, uint32_t slot_number); | 30 | bool FlashPartitionTable(int fd, const LpMetadata& metadata, uint32_t slot_number); |