From 7f852512b63650170462c779bb3b4d44d59a3f26 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Fri, 23 Jun 2023 17:23:56 +0100 Subject: [PATCH] write out the backup header too Now that we actually have the real backup header, we can safely write it out without having the wrong LBA pointers and other such issues that would come from writing the primary header to the backup header (ask me how I know) --- gpt-utils.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gpt-utils.cpp b/gpt-utils.cpp index eb265fd..0af03cf 100644 --- a/gpt-utils.cpp +++ b/gpt-utils.cpp @@ -774,6 +774,21 @@ int gpt_disk_commit(struct gpt_disk *disk) __func__); goto error; } + + // Write the backup header + if (gpt_set_header(disk->hdr_bak, fd, SECONDARY_GPT) != 0) { + fprintf(stderr, "%s: Failed to update backup GPT header\n", + __func__); + goto error; + } + LOGD("%s: Writing back backup partition array\n", __func__); + // Write back the backup partition array + if (gpt_set_pentry_arr(disk->hdr_bak, fd, disk->pentry_arr_bak)) { + fprintf(stderr, + "%s: Failed to write backup GPT partition arr\n", + __func__); + goto error; + } fsync(fd); close(fd); return 0;