From 028c790ccdd95ef57a0b53404a32606d2e6a84ba Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Fri, 28 Mar 2014 17:09:40 +0000 Subject: Avoid overwriting empty or hidden partitions It changes the DOS partition rewriting code to avoid overwriting empty or hidden primary partitions so long as their entries aren't reused. This makes fatresize and similar front-ends safe to use in the presence of hidden partitions. Forwarded: http://lists.gnu.org/archive/html/bug-parted/2008-10/msg00005.html Bug-Debian: http://bugs.debian.org/491797 Last-Update: 2010-02-02 Patch-Name: preserve-hidden-parts.patch --- libparted/labels/dos.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c index e6a01059..256f365d 100644 --- a/libparted/labels/dos.c +++ b/libparted/labels/dos.c @@ -1452,13 +1452,18 @@ msdos_write (const PedDisk* disk) if (!table->mbr_signature) table->mbr_signature = generate_random_uint32 (); - memset (table->partitions, 0, sizeof (table->partitions)); - table->magic = PED_CPU_TO_LE16 (MSDOS_MAGIC); + if (table->magic != PED_CPU_TO_LE16 (MSDOS_MAGIC)) { + memset (table->partitions, 0, sizeof (table->partitions)); + table->magic = PED_CPU_TO_LE16 (MSDOS_MAGIC); + } for (i=1; i<=DOS_N_PRI_PARTITIONS; i++) { part = ped_disk_get_partition (disk, i); - if (!part) + if (!part) { + if (table->partitions [i - 1].type != PARTITION_EMPTY) + memset (&table->partitions [i - 1], 0, sizeof (DosRawPartition)); continue; + } if (!fill_raw_part (&table->partitions [i - 1], part, 0)) goto write_fail;