This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 74723fdb696ac243136174a26fb7e9a2d6acc26f Author: wanggang26 <[email protected]> AuthorDate: Wed Nov 11 17:19:41 2026 +0800 fs/gpt: check the backup header at its own LBA When the primary GPT header is invalid, parse_gpt_partition() reads the backup header from the primary's alternate_lba, and then validates it against gpt->alternate_lba. gpt now points to the backup header, whose alternate_lba refers back to LBA 1, so the my_lba check always fails and a disk with a damaged primary header is reported as having no GPT. Remember the backup location before reading it and validate against it. Signed-off-by: wanggang26 <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/partition/fs_gpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/partition/fs_gpt.c b/fs/partition/fs_gpt.c index c398b2bb483..ba6cbe9bfcf 100644 --- a/fs/partition/fs_gpt.c +++ b/fs/partition/fs_gpt.c @@ -440,6 +440,7 @@ int parse_gpt_partition(FAR struct partition_state_s *state, finfo("Primary GPT is invalid, using alternate GPT.\n"); + lastlba = le64toh(gpt->alternate_lba); count = (GPT_BLOCK_SIZE + state->blocksize - 1) / state->blocksize; ret = read_partition_block(state, ptbl, GPT_LBA_TO_BLOCK(gpt->alternate_lba, @@ -450,8 +451,7 @@ int parse_gpt_partition(FAR struct partition_state_s *state, } gpt = (FAR struct gpt_header_s *)ptbl; - ret = gpt_header_is_valid(state, gpt, - le64toh(gpt->alternate_lba)); + ret = gpt_header_is_valid(state, gpt, lastlba); if (ret >= 0) { /* Verify gpt header is valid */
