[parted-devel] [PATCH 1/2] do not discard bootcode from extended partition

Petr Uzel petr.uzel at suse.cz
Thu Aug 20 13:27:09 UTC 2009


* libparted/labels/dos.c (write_ext_table): Do not discard
  bootcode from extended partition on msdos label when some of
  the logical partitions are changed

Signed-off-by: Petr Uzel <petr.uzel at suse.cz>
---
 libparted/labels/dos.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index 1d4c2dd..7b0c6d6 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -1027,7 +1027,8 @@ write_ext_table (const PedDisk* disk,
                  PedSector sector, const PedPartition* logical)
 {
 	PedPartition*		part;
-	PedSector		lba_offset;
+	PedSector			lba_offset;
+	void*				s;
 
 	PED_ASSERT (disk != NULL, return 0);
 	PED_ASSERT (ped_disk_extended_partition (disk) != NULL, return 0);
@@ -1035,10 +1036,11 @@ write_ext_table (const PedDisk* disk,
 
 	lba_offset = ped_disk_extended_partition (disk)->geom.start;
 
-	void *s = ped_calloc (disk->dev->sector_size);
-	if (s == NULL)
+	if (!ptt_read_sector (disk->dev, sector, &s)) 
 		return 0;
+
 	DosRawTable *table = s;
+	memset(&(table->partitions), 0, 4 * sizeof(DosRawPartition));
 	table->magic = PED_CPU_TO_LE16 (MSDOS_MAGIC);
 
 	int ok = 0;
@@ -1073,10 +1075,15 @@ static int
 write_empty_table (const PedDisk* disk, PedSector sector)
 {
 	DosRawTable		table;
+	void*			table_sector;
 
 	PED_ASSERT (disk != NULL, return 0);
 
-	memset (&table, 0, sizeof (DosRawTable));
+	if (ptt_read_sector (disk->dev, sector, &table_sector)) {
+		memcpy (&table, table_sector, sizeof(DosRawTable));
+		free(table_sector);
+	}
+	memset (&(table.partitions), 0, 4 * sizeof(DosRawPartition));
 	table.magic = PED_CPU_TO_LE16 (MSDOS_MAGIC);
 
 	return ped_device_write (disk->dev, (void*) &table, sector, 1);
-- 
1.6.3.3


-- 
Best regards / s pozdravem

Petr Uzel, openSUSE Community Multiplier Team
-----------------------------------------------------------------
SUSE LINUX, s.r.o.                          e-mail: puzel at suse.cz
Lihovarská 1060/12                          http://www.suse.cz
190 00 Prague 9, CR                             
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/parted-devel/attachments/20090820/88439c7d/attachment.pgp>


More information about the parted-devel mailing list