[PATCH 8/8] gpt: greatly simply gpt_clobber; minor semantic change, too
Jim Meyering
meyering at redhat.com
Fri Nov 13 12:51:53 UTC 2009
* libparted/labels/gpt.c (gpt_clobber): Don't bother to read and
parse existing headers. Instead, simply clear three sectors:
the pMBR, the primary header (LBA1), and the last sector.
There is no point in clearing what the primary header says is the
AlternateLBA, since once the primary header and the last sector
are cleared, there is no risk of any tool using it by mistake.
---
libparted/labels/gpt.c | 47 +++++------------------------------------------
1 files changed, 5 insertions(+), 42 deletions(-)
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index aca555a..e6347e3 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -490,53 +490,16 @@ gpt_probe (const PedDevice *dev)
}
#ifndef DISCOVER_ONLY
-/* writes zeros to the PMBR and the primary and alternate GPTHs and PTEs */
+/* writes zeros to the PMBR and the primary GPTH, and to the final sector */
static int
gpt_clobber (PedDevice *dev)
{
- uint8_t *pth_raw = ped_malloc (pth_get_size (dev));
- GuidPartitionTableHeader_t *gpt;
-
PED_ASSERT (dev != NULL, return 0);
- /*
- * TO DISCUSS: check whether checksum is correct?
- * If not, we might get a wrong AlternateLBA field and destroy
- * one sector of random data.
- */
- if (!ped_device_read (dev, pth_raw,
- GPT_PRIMARY_HEADER_LBA, GPT_HEADER_SECTORS))
- {
- free (pth_raw);
- return 0;
- }
-
- gpt = pth_new_from_raw (dev, pth_raw);
- free (pth_raw);
-
- if (!ptt_clear_sectors (dev, GPT_PMBR_LBA, GPT_PMBR_SECTORS))
- goto error_free_with_gpt;
- if (!ptt_clear_sectors (dev, GPT_PRIMARY_HEADER_LBA, GPT_HEADER_SECTORS))
- goto error_free_with_gpt;
- if (!ptt_clear_sectors (dev, dev->length - GPT_HEADER_SECTORS,
- GPT_HEADER_SECTORS))
- goto error_free_with_gpt;
-
- if ((PedSector) PED_LE64_TO_CPU (gpt->AlternateLBA) < dev->length - 1)
- {
- if (!ped_device_write (dev, gpt,
- PED_LE64_TO_CPU (gpt->AlternateLBA),
- GPT_HEADER_SECTORS))
- return 0;
- }
-
- pth_free (gpt);
-
- return 1;
-
-error_free_with_gpt:
- pth_free (gpt);
- return 0;
+ return (ptt_clear_sectors (dev, GPT_PMBR_LBA, GPT_PMBR_SECTORS)
+ && ptt_clear_sectors (dev, GPT_PRIMARY_HEADER_LBA, GPT_HEADER_SECTORS)
+ && ptt_clear_sectors (dev, dev->length - GPT_HEADER_SECTORS,
+ GPT_HEADER_SECTORS));
}
#endif /* !DISCOVER_ONLY */
--
1.6.5.2.372.gc0502
More information about the parted-devel
mailing list