Merge "liblp: Clean up public headers."
This commit is contained in:
commit
b399456303
10 changed files with 91 additions and 59 deletions
|
|
@ -27,8 +27,8 @@
|
|||
#include <android-base/unique_fd.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include "liblp/metadata_format.h"
|
||||
#include "liblp/reader.h"
|
||||
#include "liblp/liblp.h"
|
||||
#include "reader.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace android {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "metadata_format.h"
|
||||
#include "liblp.h"
|
||||
|
||||
namespace android {
|
||||
namespace fs_mgr {
|
||||
|
|
|
|||
75
fs_mgr/liblp/include/liblp/liblp.h
Normal file
75
fs_mgr/liblp/include/liblp/liblp.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef LIBLP_LIBLP_H
|
||||
#define LIBLP_LIBLP_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "metadata_format.h"
|
||||
|
||||
namespace android {
|
||||
namespace fs_mgr {
|
||||
|
||||
// Helper structure for easily interpreting deserialized metadata, or
|
||||
// re-serializing metadata.
|
||||
struct LpMetadata {
|
||||
LpMetadataGeometry geometry;
|
||||
LpMetadataHeader header;
|
||||
std::vector<LpMetadataPartition> partitions;
|
||||
std::vector<LpMetadataExtent> extents;
|
||||
};
|
||||
|
||||
// Place an initial partition table on the device. This will overwrite the
|
||||
// existing geometry, and should not be used for normal partition table
|
||||
// updates. False can be returned if the geometry is incompatible with the
|
||||
// block device or an I/O error occurs.
|
||||
bool FlashPartitionTable(const std::string& block_device, const LpMetadata& metadata,
|
||||
uint32_t slot_number);
|
||||
|
||||
// Update the partition table for a given metadata slot number. False is
|
||||
// returned if an error occurs, which can include:
|
||||
// - Invalid slot number.
|
||||
// - I/O error.
|
||||
// - Corrupt or missing metadata geometry on disk.
|
||||
// - Incompatible geometry.
|
||||
bool UpdatePartitionTable(const std::string& block_device, const LpMetadata& metadata,
|
||||
uint32_t slot_number);
|
||||
|
||||
// Read logical partition metadata from its predetermined location on a block
|
||||
// device. If readback fails, we also attempt to load from a backup copy.
|
||||
std::unique_ptr<LpMetadata> ReadMetadata(const char* block_device, uint32_t slot_number);
|
||||
|
||||
// Read/Write logical partition metadata to an image file, for diagnostics or
|
||||
// flashing.
|
||||
bool WriteToImageFile(const char* file, const LpMetadata& metadata);
|
||||
std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file);
|
||||
|
||||
// Helper to extract safe C++ strings from partition info.
|
||||
std::string GetPartitionName(const LpMetadataPartition& partition);
|
||||
std::string GetPartitionGuid(const LpMetadataPartition& partition);
|
||||
|
||||
// Helper to return a slot number for a slot suffix.
|
||||
uint32_t SlotNumberForSlotSuffix(const std::string& suffix);
|
||||
|
||||
} // namespace fs_mgr
|
||||
} // namespace android
|
||||
|
||||
#endif // LIBLP_LIBLP_H
|
||||
|
|
@ -262,28 +262,4 @@ typedef struct LpMetadataExtent {
|
|||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace android {
|
||||
namespace fs_mgr {
|
||||
|
||||
// Helper structure for easily interpreting deserialized metadata, or
|
||||
// re-serializing metadata.
|
||||
struct LpMetadata {
|
||||
LpMetadataGeometry geometry;
|
||||
LpMetadataHeader header;
|
||||
std::vector<LpMetadataPartition> partitions;
|
||||
std::vector<LpMetadataExtent> extents;
|
||||
};
|
||||
|
||||
// Helper to extract safe C++ strings from partition info.
|
||||
std::string GetPartitionName(const LpMetadataPartition& partition);
|
||||
std::string GetPartitionGuid(const LpMetadataPartition& partition);
|
||||
|
||||
// Helper to return a slot number for a slot suffix.
|
||||
uint32_t SlotNumberForSlotSuffix(const std::string& suffix);
|
||||
|
||||
} // namespace fs_mgr
|
||||
} // namespace android
|
||||
#endif
|
||||
|
||||
#endif /* LOGICAL_PARTITION_METADATA_FORMAT_H_ */
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@
|
|||
#include <android-base/unique_fd.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <liblp/builder.h>
|
||||
#include <liblp/reader.h>
|
||||
#include <liblp/writer.h>
|
||||
|
||||
#include "reader.h"
|
||||
#include "utility.h"
|
||||
#include "writer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace android::fs_mgr;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "liblp/reader.h"
|
||||
#include "reader.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -165,8 +165,6 @@ static bool ValidateMetadataHeader(const LpMetadataHeader& header) {
|
|||
return true;
|
||||
}
|
||||
|
||||
using ReadMetadataFn = std::function<bool(void* buffer, size_t num_bytes)>;
|
||||
|
||||
// Parse and validate all metadata at the current position in the given file
|
||||
// descriptor.
|
||||
static std::unique_ptr<LpMetadata> ParseMetadata(int fd) {
|
||||
|
|
|
|||
|
|
@ -21,14 +21,11 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "metadata_format.h"
|
||||
#include <liblp/liblp.h>
|
||||
|
||||
namespace android {
|
||||
namespace fs_mgr {
|
||||
|
||||
// Read logical partition metadata from its predetermined location on a block
|
||||
// device. If readback fails, we also attempt to load from a backup copy.
|
||||
std::unique_ptr<LpMetadata> ReadMetadata(const char* block_device, uint32_t slot_number);
|
||||
std::unique_ptr<LpMetadata> ReadMetadata(int fd, uint32_t slot_number);
|
||||
|
||||
// Helper functions for manually reading geometry and metadata.
|
||||
|
|
@ -40,9 +37,6 @@ std::unique_ptr<LpMetadata> ReadPrimaryMetadata(int fd, const LpMetadataGeometry
|
|||
std::unique_ptr<LpMetadata> ReadBackupMetadata(int fd, const LpMetadataGeometry& geometry,
|
||||
uint32_t slot_number);
|
||||
|
||||
// Read logical partition metadata from an image file that was created with
|
||||
// WriteToImageFile().
|
||||
std::unique_ptr<LpMetadata> ReadFromImageFile(const char* file);
|
||||
std::unique_ptr<LpMetadata> ReadFromImageFile(int fd);
|
||||
|
||||
} // namespace fs_mgr
|
||||
|
|
@ -14,8 +14,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "utility.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <liblp/liblp.h>
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
using namespace android;
|
||||
using namespace android::fs_mgr;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "writer.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -22,8 +24,7 @@
|
|||
#include <android-base/file.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
|
||||
#include "liblp/reader.h"
|
||||
#include "liblp/writer.h"
|
||||
#include "reader.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace android {
|
||||
|
|
|
|||
|
|
@ -18,27 +18,13 @@
|
|||
#define LIBLP_WRITER_H
|
||||
|
||||
#include <functional>
|
||||
#include "metadata_format.h"
|
||||
#include <string>
|
||||
|
||||
#include <liblp/liblp.h>
|
||||
|
||||
namespace android {
|
||||
namespace fs_mgr {
|
||||
|
||||
// Place an initial partition table on the device. This will overwrite the
|
||||
// existing geometry, and should not be used for normal partition table
|
||||
// updates. False can be returned if the geometry is incompatible with the
|
||||
// block device or an I/O error occurs.
|
||||
bool FlashPartitionTable(const std::string& block_device, const LpMetadata& metadata,
|
||||
uint32_t slot_number);
|
||||
|
||||
// Update the partition table for a given metadata slot number. False is
|
||||
// returned if an error occurs, which can include:
|
||||
// - Invalid slot number.
|
||||
// - I/O error.
|
||||
// - Corrupt or missing metadata geometry on disk.
|
||||
// - Incompatible geometry.
|
||||
bool UpdatePartitionTable(const std::string& block_device, const LpMetadata& metadata,
|
||||
uint32_t slot_number);
|
||||
|
||||
// These variants are for testing only. The path-based functions should be used
|
||||
// for actual operation, so that open() is called with the correct flags.
|
||||
bool FlashPartitionTable(int fd, const LpMetadata& metadata, uint32_t slot_number);
|
||||
Loading…
Add table
Reference in a new issue