gpt_write: use GPE LBA from header

When writing the GPT header, the tool always wrote the GPT entries
belonging to the primary header to LBA following the header. Normally
this is LBA 2 as the header is located in LBA 1. The GPT allows for
up to 128 entries that all in all cover 16 KiB of storage space.
However, on some systems, e.g. ARM-based machines, the bootloader can
be stored in this region. For this reason the GPT entries may be moved
to a different LBA.

This commit changes the tool to adhere to then given GPE LBA in header
when writing out the modified GPT data.

Fixes #4720.
This commit is contained in:
Josef Söntgen 2023-01-09 15:20:47 +01:00 committed by Christian Helmuth
parent ddeaccf728
commit 5a558a64e1

View File

@ -309,7 +309,7 @@ struct Gpt::Writer
size_t const len = hdr.gpe_num * hdr.gpe_size;
size_t const blocks = len / _block_size;
Block::sector_t const entries_lba = primary
? hdr_lba + 1
? hdr.gpe_lba
: _block_count - (blocks + 1);
Block_io entries_io(_block, _block_size, _ep, entries_lba, blocks, true,
entries, len);