liblp: Always align the first usable sector.

Align the first usable sector to the logical block size, if no other
alignment was specified. This fixes a bunch of warnings during certain
gtests (ones with unaligned metadata sizes). The warnings were coming
from MetadataBuilder::GrowPartition() which expects the first sector
to always be block-aligned.

Bug: 116802789
Test: liblp_test gtest
Change-Id: I8dcf502aa4c2ba0674c5b4dcb77a274f300ff0a3
This commit is contained in:
David Anderson 2018-10-12 09:36:06 -07:00
parent 692049259c
commit 87391664e3

View file

@ -268,8 +268,13 @@ bool MetadataBuilder::Init(const BlockDeviceInfo& device_info, uint32_t metadata
}
// Compute the first free sector, factoring in alignment.
uint64_t free_area_start =
AlignTo(total_reserved, device_info.alignment, device_info.alignment_offset);
uint64_t free_area_start = total_reserved;
if (device_info.alignment || device_info.alignment_offset) {
free_area_start =
AlignTo(free_area_start, device_info.alignment, device_info.alignment_offset);
} else {
free_area_start = AlignTo(free_area_start, device_info.logical_block_size);
}
uint64_t first_sector = free_area_start / LP_SECTOR_SIZE;
// There must be one logical block of free space remaining (enough for one partition).