diff options
author | David Anderson <dvander@google.com> | 2018-07-31 13:34:14 -0700 |
---|---|---|
committer | David Anderson <dvander@google.com> | 2018-08-01 17:41:29 -0700 |
commit | 2e755e38af9e73b802c229e88a3de4e48eaff805 (patch) | |
tree | f37784a345dee91b90e6aef8be5c8c86329af9b9 /fs_mgr/liblp/builder.cpp | |
parent | d5f825c78bc98027a485d8bdecd14e8563a449ba (diff) |
liblp: Add a ResizePartition helper to MetadataBuilder.
This change is to assist with implementing the fastbootd "resize-partition"
command. The GrowPartition and ShrinkPartition functions are now
private.
Bug: 78793464
Test: N/A
Change-Id: Ic66a3052359e2558663272ff6e014704206b197e
Diffstat (limited to 'fs_mgr/liblp/builder.cpp')
-rw-r--r-- | fs_mgr/liblp/builder.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp index 9d710f90b..d6eee6b32 100644 --- a/fs_mgr/liblp/builder.cpp +++ b/fs_mgr/liblp/builder.cpp @@ -82,11 +82,7 @@ void Partition::RemoveExtents() { extents_.clear(); } -void Partition::ShrinkTo(uint64_t requested_size) { - uint64_t aligned_size = AlignTo(requested_size, LP_SECTOR_SIZE); - if (size_ <= aligned_size) { - return; - } +void Partition::ShrinkTo(uint64_t aligned_size) { if (aligned_size == 0) { RemoveExtents(); return; @@ -106,7 +102,7 @@ void Partition::ShrinkTo(uint64_t requested_size) { sectors_to_remove -= extent->num_sectors(); extents_.pop_back(); } - DCHECK(size_ == requested_size); + DCHECK(size_ == aligned_size); } std::unique_ptr<MetadataBuilder> MetadataBuilder::New(const std::string& block_device, @@ -290,13 +286,7 @@ void MetadataBuilder::RemovePartition(const std::string& name) { } } -bool MetadataBuilder::GrowPartition(Partition* partition, uint64_t requested_size) { - // Align the space needed up to the nearest sector. - uint64_t aligned_size = AlignTo(requested_size, LP_SECTOR_SIZE); - if (partition->size() >= aligned_size) { - return true; - } - +bool MetadataBuilder::GrowPartition(Partition* partition, uint64_t aligned_size) { // Figure out how much we need to allocate. uint64_t space_needed = aligned_size - partition->size(); uint64_t sectors_needed = space_needed / LP_SECTOR_SIZE; @@ -394,8 +384,8 @@ bool MetadataBuilder::GrowPartition(Partition* partition, uint64_t requested_siz return true; } -void MetadataBuilder::ShrinkPartition(Partition* partition, uint64_t requested_size) { - partition->ShrinkTo(requested_size); +void MetadataBuilder::ShrinkPartition(Partition* partition, uint64_t aligned_size) { + partition->ShrinkTo(aligned_size); } std::unique_ptr<LpMetadata> MetadataBuilder::Export() { @@ -465,5 +455,18 @@ void MetadataBuilder::set_block_device_info(const BlockDeviceInfo& device_info) } } +bool MetadataBuilder::ResizePartition(Partition* partition, uint64_t requested_size) { + // Align the space needed up to the nearest sector. + uint64_t aligned_size = AlignTo(requested_size, LP_SECTOR_SIZE); + + if (aligned_size > partition->size()) { + return GrowPartition(partition, aligned_size); + } + if (aligned_size < partition->size()) { + ShrinkPartition(partition, aligned_size); + } + return true; +} + } // namespace fs_mgr } // namespace android |