Package: parted / 3.2-7

preserve-hidden-parts.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From bf7feb60cd86ab423d350721b10832bdcd6074ba Mon Sep 17 00:00:00 2001
From: Ben Hutchings <ben@decadent.org.uk>
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 fa53020..4781c05 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -1294,13 +1294,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;