Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87391664 authored by David Anderson's avatar David Anderson
Browse files

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
parent 69204925
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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).