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-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f4e5382d fs_gpt:fix alternate GPT also invalid issue 2/2
7f4e5382d is described below

commit 7f4e5382d65908454d13983d167d8a4b913bc490
Author: wanggang26 <[email protected]>
AuthorDate: Sat Dec 28 14:38:29 2024 +0800

    fs_gpt:fix alternate GPT also invalid issue 2/2
    
    mkgpt writes the secondary GPT by reusing the primary header and only
    swapping header_lba and backup_lba.  entries_lba stays at 2, so the
    backup header points at the primary partition entries instead of the
    copy written at the end of the disk (sz - 33).  A reader that falls
    back to the backup header then reads the wrong entries, and the
    alternate GPT is also reported invalid.  Set entries_lba to sz - 33
    for the secondary header.
    
    Signed-off-by: wanggang26 <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fsutils/mkgpt/mkgpt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fsutils/mkgpt/mkgpt.c b/fsutils/mkgpt/mkgpt.c
index d967c6af2..a2098a654 100644
--- a/fsutils/mkgpt/mkgpt.c
+++ b/fsutils/mkgpt/mkgpt.c
@@ -576,8 +576,9 @@ int main(int argc, FAR char **argv)
 
   /* reverse these for the secondary copy */
 
-  hdr->header_lba = sz -1;
+  hdr->header_lba = sz - 1;
   hdr->backup_lba = 1;
+  hdr->entries_lba = sz - 33;
   update_crc32(ptbl);
 
   if (write(fd, &ptbl->entry, sizeof(ptbl->entry)) !=

Reply via email to