From 189727089edd339fb892f322981044104fc93ef7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 2 Jan 2019 14:19:07 -0800 Subject: [PATCH] liblp: Add API for adding predetermined linear extents to partitions Bug: 121210348 Test: manual test Change-Id: Ie9af456d5193e962a3bcf0cc5dcd22e794d143f6 --- fs_mgr/liblp/builder.cpp | 13 +++++++++++++ fs_mgr/liblp/include/liblp/builder.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp index 07f9d66d0..278331b37 100644 --- a/fs_mgr/liblp/builder.cpp +++ b/fs_mgr/liblp/builder.cpp @@ -983,5 +983,18 @@ bool MetadataBuilder::IsRetrofitDevice() const { return GetBlockDevicePartitionName(block_devices_[0]) != LP_METADATA_DEFAULT_PARTITION_NAME; } +bool MetadataBuilder::AddLinearExtent(Partition* partition, const std::string& block_device, + uint64_t num_sectors, uint64_t physical_sector) { + uint32_t device_index; + if (!FindBlockDeviceByName(block_device, &device_index)) { + LERROR << "Could not find backing block device for extent: " << block_device; + return false; + } + + auto extent = std::make_unique(num_sectors, device_index, physical_sector); + partition->AddExtent(std::move(extent)); + return true; +} + } // namespace fs_mgr } // namespace android diff --git a/fs_mgr/liblp/include/liblp/builder.h b/fs_mgr/liblp/include/liblp/builder.h index f477b4b1c..f16d08706 100644 --- a/fs_mgr/liblp/include/liblp/builder.h +++ b/fs_mgr/liblp/include/liblp/builder.h @@ -219,6 +219,10 @@ class MetadataBuilder { // Find a group by name. If no group is found, nullptr is returned. PartitionGroup* FindGroup(const std::string& name); + // Add a predetermined extent to a partition. + bool AddLinearExtent(Partition* partition, const std::string& block_device, + uint64_t num_sectors, uint64_t physical_sector); + // Grow or shrink a partition to the requested size. This size will be // rounded UP to the nearest block (512 bytes). //