@@ -153,7 +153,8 @@ static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e)
return 0;
}
-static void prepare_backup_gpt_header(gpt_header *gpt_h)
+static void prepare_backup_gpt_header(gpt_header *gpt_h,
+ const int pte_blk_cnt)
{
uint32_t calc_crc32;
uint64_t val;
@@ -162,8 +163,7 @@ static void prepare_backup_gpt_header(gpt_header *gpt_h)
val = le64_to_cpu(gpt_h->alternate_lba);
gpt_h->alternate_lba = gpt_h->my_lba;
gpt_h->my_lba = cpu_to_le64(val);
- gpt_h->partition_entry_lba =
- cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1);
+ gpt_h->partition_entry_lba = cpu_to_le64(val - pte_blk_cnt);
gpt_h->header_crc32 = 0;
calc_crc32 = efi_crc32((const unsigned char *)gpt_h,
@@ -387,7 +387,7 @@ int write_gpt_table(struct blk_desc *dev_desc,
!= pte_blk_cnt)
goto err;
- prepare_backup_gpt_header(gpt_h);
+ prepare_backup_gpt_header(gpt_h, pte_blk_cnt);
if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba)
+ 1, pte_blk_cnt, gpt_e) != pte_blk_cnt)
@@ -757,7 +757,7 @@ int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf)
return 1;
}
- prepare_backup_gpt_header(gpt_h);
+ prepare_backup_gpt_header(gpt_h, gpt_e_blk_cnt);
/* write Backup GPT */
lba = le64_to_cpu(gpt_h->partition_entry_lba);