[parted-devel] [PATCH 2/4] do not discard bootcode from extended partition
Joel Granados Moreno
jgranado at redhat.com
Wed Jun 10 13:37:23 UTC 2009
From: Petr Uzel <petr.uzel at suse.cz>
* 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 | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index e2f4f0b..07d580f 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -1039,6 +1039,7 @@ write_ext_table (const PedDisk* disk,
DosRawTable table;
PedPartition* part;
PedSector lba_offset;
+ void* table_sector;
PED_ASSERT (disk != NULL, return 0);
PED_ASSERT (ped_disk_extended_partition (disk) != NULL, return 0);
@@ -1046,7 +1047,11 @@ write_ext_table (const PedDisk* disk,
lba_offset = ped_disk_extended_partition (disk)->geom.start;
- 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);
if (!fill_raw_part (&table.partitions[0], logical, sector))
@@ -1077,10 +1082,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.0.6
More information about the parted-devel
mailing list