b616963
From 325b06dae4dff1751d6c5f28506def0786a1a1c9 Mon Sep 17 00:00:00 2001
b616963
From: Peter Jones <pjones@redhat.com>
b616963
Date: Thu, 16 Dec 2010 15:37:32 -0500
b616963
Subject: [PATCH] Improve support for mac partition tables with logical sector size != 512
b616963
b616963
On mac partition tables which specify a sector size larger than the
b616963
physical sector size, we need to reallocate the buffer after we
b616963
determine the correct sector size.
b616963
b616963
This is a normal condition when CD is used with Apple partitions (for
b616963
example, the USB rescue stick for the MacBookAir3,1), and then an image
b616963
(analogous to an .iso image) is created, so also don't raise an exception in
b616963
_disk_analyse_block_size() when we find that.
b616963
b616963
Also simplify the code in _disk_analyse_block_size() a bit since there's no
b616963
reason to ever do the byteswapping more than once or convert everything to
b616963
512-byte multiples since we neither load nor store it that way.
b616963
---
b616963
 libparted/labels/mac.c |   44 ++++++++++++++++++++++++++------------------
b616963
 1 files changed, 26 insertions(+), 18 deletions(-)
b616963
b616963
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
b616963
index 49a236e..418343e 100644
b616963
--- a/libparted/labels/mac.c
b616963
+++ b/libparted/labels/mac.c
b616963
@@ -643,35 +643,22 @@ _rawpart_get_partmap_size (MacRawPartition* raw_part, PedDisk* disk)
b616963
 static int
b616963
 _disk_analyse_block_size (PedDisk* disk, MacRawDisk* raw_disk)
b616963
 {
b616963
-	PedSector	block_size;
b616963
+	PedSector	block_size = PED_BE16_TO_CPU(raw_disk->block_size);
b616963
 
b616963
-	if (PED_BE16_TO_CPU (raw_disk->block_size) % 512) {
b616963
+	if (block_size % 512) {
b616963
 #ifndef DISCOVER_ONLY
b616963
 		ped_exception_throw (
b616963
 			PED_EXCEPTION_ERROR,
b616963
 			PED_EXCEPTION_CANCEL,
b616963
 			_("Weird block size on device descriptor: %d bytes is "
b616963
 			  "not divisible by 512."),
b616963
-			(int) PED_BE16_TO_CPU (raw_disk->block_size));
b616963
+			(int) block_size);
b616963
 #endif
b616963
 		goto error;
b616963
 	}
b616963
 
b616963
-	block_size = PED_BE16_TO_CPU (raw_disk->block_size) / 512;
b616963
-	if (block_size != disk->dev->sector_size / 512) {
b616963
-#ifndef DISCOVER_ONLY
b616963
-		if (ped_exception_throw (
b616963
-			PED_EXCEPTION_WARNING,
b616963
-			PED_EXCEPTION_IGNORE_CANCEL,
b616963
-			_("The driver descriptor says the physical block size "
b616963
-			  "is %d bytes, but Linux says it is %d bytes."),
b616963
-			(int) block_size * 512,
b616963
-			(int) disk->dev->sector_size)
b616963
-				!= PED_EXCEPTION_IGNORE)
b616963
-			goto error;
b616963
-#endif
b616963
-		disk->dev->sector_size = block_size * 512;
b616963
-	}
b616963
+	if (block_size != disk->dev->sector_size)
b616963
+		disk->dev->sector_size = block_size;
b616963
 
b616963
 	return 1;
b616963
 
b616963
@@ -729,6 +716,7 @@ mac_read (PedDisk* disk)
b616963
 	PedPartition*		part;
b616963
 	int			num;
b616963
 	PedSector		ghost_size;
b616963
+	PedSector		sector_size;
b616963
 	PedConstraint*		constraint_exact;
b616963
 	int			last_part_entry_num = 0;
b616963
 
b616963
@@ -746,8 +734,28 @@ mac_read (PedDisk* disk)
b616963
 	if (!_check_signature (raw_disk))
b616963
 		goto error;
b616963
 
b616963
+	sector_size = disk->dev->sector_size;
b616963
 	if (!_disk_analyse_block_size (disk, raw_disk))
b616963
 		goto error;
b616963
+
b616963
+	/* If dev->sector_size changed when we did ptt_read_sector(),
b616963
+	   then the buffer size is wrong and we'll take a segfault
b616963
+	   down the line unless we re-allocate it here. */
b616963
+	if (disk->dev->sector_size != sector_size) {
b616963
+		free(buf);
b616963
+		buf = 0;
b616963
+		if (!ptt_read_sector(disk->dev, 0, &buf))
b616963
+			return 0;
b616963
+
b616963
+		MacRawDisk *raw_disk = (MacRawDisk *) buf;
b616963
+
b616963
+		if (!_check_signature (raw_disk))
b616963
+			goto error;
b616963
+
b616963
+		if (!_disk_analyse_block_size (disk, raw_disk))
b616963
+			goto error;
b616963
+	}
b616963
+
b616963
 	if (!_disk_analyse_ghost_size (disk))
b616963
 		goto error;
b616963
 	ghost_size = mac_disk_data->ghost_size;
b616963
-- 
b616963
1.7.3.1
b616963