• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_READER_H_
18 #define LIBLP_READER_H_
19 
20 #include <stddef.h>
21 
22 #include <memory>
23 
24 #include <liblp/liblp.h>
25 
26 namespace android {
27 namespace fs_mgr {
28 
29 // Parse an LpMetadataGeometry from a buffer. The buffer must be at least
30 // LP_METADATA_GEOMETRY_SIZE bytes in size.
31 bool ParseGeometry(const void* buffer, LpMetadataGeometry* geometry);
32 
33 // Helper functions for manually reading geometry and metadata.
34 std::unique_ptr<LpMetadata> ParseMetadata(const LpMetadataGeometry& geometry, int fd);
35 std::unique_ptr<LpMetadata> ParseMetadata(const LpMetadataGeometry& geometry, const void* buffer,
36                                           size_t size);
37 bool ReadLogicalPartitionGeometry(int fd, LpMetadataGeometry* geometry);
38 bool ReadPrimaryGeometry(int fd, LpMetadataGeometry* geometry);
39 bool ReadBackupGeometry(int fd, LpMetadataGeometry* geometry);
40 
41 // These functions assume a valid geometry and slot number, and do not obey
42 // auto-slot-suffixing. They are used for tests and for checking whether
43 // the metadata is coherent across primary and backup copies.
44 std::unique_ptr<LpMetadata> ReadPrimaryMetadata(int fd, const LpMetadataGeometry& geometry,
45                                                 uint32_t slot_number);
46 std::unique_ptr<LpMetadata> ReadBackupMetadata(int fd, const LpMetadataGeometry& geometry,
47                                                uint32_t slot_number);
48 
49 }  // namespace fs_mgr
50 }  // namespace android
51 
52 #endif /* LIBLP_READER_H_ */
53