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
diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp
index ea78e9b..80257fe 100644
--- a/fs_mgr/liblp/builder.cpp
+++ b/fs_mgr/liblp/builder.cpp
@@ -268,8 +268,13 @@
}
// 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).