[parted-devel] [PATCH] avoid partition type corruption on mac label

Olaf Hering olh at suse.de
Tue Jul 18 08:51:32 UTC 2006


This set of commands corrupts the partition type:


	+ blockdev --rereadpt /dev/sda
	+ dd if=/dev/zero bs=42M count=42 of=/dev/sda
	42+0 records in
	42+0 records out
	+ blockdev --rereadpt /dev/sda
	+ parted -s /dev/sda mklabel mac
	+ parted -s /dev/sda unit cyl mkpart primary hfs 1 6
	+ pdisk -l /dev/sda

	Partition map (with 512 byte blocks) on '/dev/sda'
	 #:                type name         length   base      ( size )
	 1: Apple_partition_map 'Apple  '        63 @ 1        
	 2:           Apple_HFS 'primary'     96327 @ 64        ( 47.0M)
	 3:          Apple_Free 'Extra  ' 156205097 @ 96391     ( 74.5G)

	Device block size=512, Number of Blocks=156301488 (74.5G)
	DeviceType=0x0, DeviceId=0x0

	+ parted -s /dev/sda set 2 lvm off
	+ pdisk -l /dev/sda

	Partition map (with 512 byte blocks) on '/dev/sda'
	 #:                type name         length   base      ( size )
	 1: Apple_partition_map 'Apple  '        63 @ 1        
	 2:     Apple_UNIX_SVR2 'primary'     96327 @ 64        ( 47.0M)
	 3:          Apple_Free 'Extra  ' 156205097 @ 96391     ( 74.5G)

	Device block size=512, Number of Blocks=156301488 (74.5G)
	DeviceType=0x0, DeviceId=0x0


The type will change from Apple_HFS or Apple_Boot to Apple_UNIX_SRV2.
Neither MacOS nor the firmware will try to access the partition now,
despite the fact that the partition content has not changed at all.

---
 libparted/labels/mac.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Index: parted-1.7.1/libparted/labels/mac.c
===================================================================
--- parted-1.7.1.orig/libparted/labels/mac.c
+++ parted-1.7.1/libparted/labels/mac.c
@@ -1249,19 +1249,23 @@ mac_partition_set_flag (PedPartition* pa
 		return 1;
 
 	case PED_PARTITION_LVM:
-		mac_data->is_lvm = state;
-		if (state)
+		if (state) {
 			strcpy (mac_data->system_name, "Linux_LVM");
-		else
-			mac_partition_set_system (part, part->fs_type);
+			mac_data->is_lvm = state;
+		} else {
+			if (mac_data->is_lvm)
+				mac_partition_set_system (part, part->fs_type);
+		}
 		return 1;
 
 	case PED_PARTITION_RAID:
-		mac_data->is_raid = state;
-		if (state)
+		if (state) {
 			strcpy (mac_data->system_name, "Linux_RAID");
-		else
-			mac_partition_set_system (part, part->fs_type);
+			mac_data->is_raid = state;
+		} else {
+			if (mac_data->is_raid)
+				mac_partition_set_system (part, part->fs_type);
+		}
 		return 1;
 
 	default:



More information about the parted-devel mailing list