gpt: always revalidate when recomputing checksums
This ensures all code modifying GPT data include the same sanity check that repair does. If revalidation fails the status flags are left in the appropriate state.
This commit is contained in:
parent
427fdc58e1
commit
d2f9096444
1 changed files with 18 additions and 14 deletions
|
@ -623,23 +623,9 @@ grub_gpt_repair (grub_disk_t disk, grub_gpt_t gpt)
|
||||||
else
|
else
|
||||||
return grub_error (GRUB_ERR_BUG, "No valid GPT");
|
return grub_error (GRUB_ERR_BUG, "No valid GPT");
|
||||||
|
|
||||||
/* Recompute checksums. */
|
|
||||||
if (grub_gpt_update_checksums (gpt))
|
if (grub_gpt_update_checksums (gpt))
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
|
||||||
/* Sanity check. */
|
|
||||||
if (grub_gpt_check_primary (gpt))
|
|
||||||
return grub_error (GRUB_ERR_BUG, "Generated invalid GPT primary header");
|
|
||||||
|
|
||||||
gpt->status |= (GRUB_GPT_PRIMARY_HEADER_VALID |
|
|
||||||
GRUB_GPT_PRIMARY_ENTRIES_VALID);
|
|
||||||
|
|
||||||
if (grub_gpt_check_backup (gpt))
|
|
||||||
return grub_error (GRUB_ERR_BUG, "Generated invalid GPT backup header");
|
|
||||||
|
|
||||||
gpt->status |= (GRUB_GPT_BACKUP_HEADER_VALID |
|
|
||||||
GRUB_GPT_BACKUP_ENTRIES_VALID);
|
|
||||||
|
|
||||||
grub_dprintf ("gpt", "repairing GPT for %s successful\n", disk->name);
|
grub_dprintf ("gpt", "repairing GPT for %s successful\n", disk->name);
|
||||||
|
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
|
@ -650,6 +636,12 @@ grub_gpt_update_checksums (grub_gpt_t gpt)
|
||||||
{
|
{
|
||||||
grub_uint32_t crc;
|
grub_uint32_t crc;
|
||||||
|
|
||||||
|
/* Clear status bits, require revalidation of everything. */
|
||||||
|
gpt->status &= ~(GRUB_GPT_PRIMARY_HEADER_VALID |
|
||||||
|
GRUB_GPT_PRIMARY_ENTRIES_VALID |
|
||||||
|
GRUB_GPT_BACKUP_HEADER_VALID |
|
||||||
|
GRUB_GPT_BACKUP_ENTRIES_VALID);
|
||||||
|
|
||||||
/* Writing headers larger than our header structure are unsupported. */
|
/* Writing headers larger than our header structure are unsupported. */
|
||||||
gpt->primary.headersize =
|
gpt->primary.headersize =
|
||||||
grub_cpu_to_le32_compile_time (sizeof (gpt->primary));
|
grub_cpu_to_le32_compile_time (sizeof (gpt->primary));
|
||||||
|
@ -663,6 +655,18 @@ grub_gpt_update_checksums (grub_gpt_t gpt)
|
||||||
grub_gpt_header_lecrc32 (&gpt->primary.crc32, &gpt->primary);
|
grub_gpt_header_lecrc32 (&gpt->primary.crc32, &gpt->primary);
|
||||||
grub_gpt_header_lecrc32 (&gpt->backup.crc32, &gpt->backup);
|
grub_gpt_header_lecrc32 (&gpt->backup.crc32, &gpt->backup);
|
||||||
|
|
||||||
|
if (grub_gpt_check_primary (gpt))
|
||||||
|
return grub_error (GRUB_ERR_BUG, "Generated invalid GPT primary header");
|
||||||
|
|
||||||
|
gpt->status |= (GRUB_GPT_PRIMARY_HEADER_VALID |
|
||||||
|
GRUB_GPT_PRIMARY_ENTRIES_VALID);
|
||||||
|
|
||||||
|
if (grub_gpt_check_backup (gpt))
|
||||||
|
return grub_error (GRUB_ERR_BUG, "Generated invalid GPT backup header");
|
||||||
|
|
||||||
|
gpt->status |= (GRUB_GPT_BACKUP_HEADER_VALID |
|
||||||
|
GRUB_GPT_BACKUP_ENTRIES_VALID);
|
||||||
|
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue