parted/0067-libparted-Fix-MacOS-boot-support.patch
Brian C. Lane d75d85cc43 - Updating to upstream patches
- tests/t1701-rescue-fs wait for the device to appear. (bcl)
- Increase timeout for rmmod scsi_debug and make it a framework failure (bcl)
- libparted/dasd: add test cases for the new fdasd functions (dongdwdw)
- libparted/dasd: add an exception for changing DASD-LDL partition table (dongdwdw)
- libpartd/dasd: improve flag processing for DASD-LDL (dongdwdw)
- parted/ui: remove unneccesary information of command line (dongdwdw)
- parted: check the name of partition first when to name a partition (dongdwdw)
- Add support for RAM drives (sparschauer)
- Fix crash when localized (psusi)
- libparted: Fix typo in hfs error message (sebras)
- libparted: Fix MacOS boot support (laurent)
- mac: copy partition type and name correctly (saproj)
- libparted: Add support for atari partition tables (glaubitz)
- libparted:tests: Move get_sector_size() to common.c (glaubitz)
- tests: Update t0220 and t0280 for the swap flag. (bcl)
- libparted: set swap flag on GPT partitions (aschnell)
- libparted/dasd: add test cases for the new fdasd functions (dongdwdw)
- libparted/dasd: add new fdasd functions (dongdwdw)
- libparted/dasd: update and improve fdasd functions (dongdwdw)
- libparted/dasd: unify vtoc handling for cdl/ldl (dongdwdw)
- libparted: Don't warn if no HDIO_GET_IDENTITY ioctl (sparschauer)
- libparted: Fix starting CHS in protective MBR (petr.uzel)
- tests: Stop timing t9040 (#1172675) (bcl)
2017-05-02 09:41:50 -07:00

123 lines
4.9 KiB
Diff

From 526f3ee2afbe7cd90d282915b7b580d4f356c4eb Mon Sep 17 00:00:00 2001
From: Laurent Vivier <laurent@vivier.eu>
Date: Fri, 9 Dec 2016 15:10:53 +0100
Subject: [PATCH 67/75] libparted: Fix MacOS boot support
boot_region_length (or BootSize in the MacOS dialect) is the length
of the driver code in the driver partition. This length is used
to compute the checksum of the driver.
libparted updates this value by setting the whole size of the partition
without computing the checksum of the driver using this size.
As the checksum is wrong, the driver is broken and cannot be loaded
by the MacOS ROM, and thus the disk is not bootable anymore.
Moreover, parted try to update the driver list and makes it disappear.
As parted is not able to insert a driver in a partition,
the driver is generally inserted by the Apple HD Tool,
this patch removes the line updating the driver size.
We also simplify the driver list scan and fix endianess use.
This has been tested... and it works, now.
I have updated a bootable disk with parted on x86_64 and
then been able to boot it (again) on a Mac LC III.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
libparted/labels/mac.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
index d8da941..fa4e43f 100644
--- a/libparted/labels/mac.c
+++ b/libparted/labels/mac.c
@@ -411,14 +411,14 @@ _rawpart_has_driver (const MacRawPartition* raw_part, MacDiskData* mac_disk_data
{
MacDeviceDriver *driverlist;
uint16_t i;
- uint32_t driver_bs, driver_be, part_be;
+ uint32_t start_block, block_count;
+ start_block = PED_BE32_TO_CPU(raw_part->start_block);
+ block_count = PED_BE32_TO_CPU(raw_part->block_count);
driverlist = &mac_disk_data->driverlist[0];
for (i = 0; i < mac_disk_data->driver_count; i++) {
- driver_bs = driverlist->block;
- driver_be = driver_bs + driverlist->size;
- part_be = raw_part->start_block + raw_part->block_count;
- if (driver_bs >= raw_part->start_block && driver_be <= part_be)
+ if (start_block == PED_BE32_TO_CPU(driverlist->block) &&
+ block_count == PED_BE16_TO_CPU(driverlist->size))
return 1;
driverlist++;
}
@@ -751,11 +751,12 @@ mac_read (PedDisk* disk)
if (!ped_disk_delete_all (disk))
goto error;
- if (raw_disk->driver_count && raw_disk->driver_count < 62) {
+ if (PED_BE16_TO_CPU(raw_disk->driver_count) &&
+ PED_BE16_TO_CPU(raw_disk->driver_count) < 62) {
memcpy(&mac_disk_data->driverlist[0], &raw_disk->driverlist[0],
sizeof(mac_disk_data->driverlist));
- mac_disk_data->driver_count = raw_disk->driver_count;
- mac_disk_data->block_size = raw_disk->block_size;
+ mac_disk_data->driver_count = PED_BE16_TO_CPU(raw_disk->driver_count);
+ mac_disk_data->block_size = PED_BE16_TO_CPU(raw_disk->block_size);
}
/* If _disk_analyse_block_size has increased the sector_size,
@@ -877,17 +878,16 @@ static void
_update_driver_count (MacRawPartition* part_map_entry,
MacDiskData *mac_driverdata, const MacDiskData* mac_disk_data)
{
- uint16_t i, count_orig, count_cur;
- uint32_t driver_bs, driver_be, part_be;
-
- count_cur = mac_driverdata->driver_count;
- count_orig = mac_disk_data->driver_count;
- for (i = 0; i < count_orig; i++) {
- driver_bs = mac_disk_data->driverlist[i].block;
- driver_be = driver_bs + mac_disk_data->driverlist[i].size;
- part_be = part_map_entry->start_block + part_map_entry->block_count;
- if (driver_bs >= part_map_entry->start_block
- && driver_be <= part_be) {
+ uint16_t i;
+ uint32_t start_block, block_count;
+
+ start_block = PED_BE32_TO_CPU(part_map_entry->start_block);
+ block_count = PED_BE32_TO_CPU(part_map_entry->block_count);
+
+ for (i = 0; i < mac_disk_data->driver_count; i++) {
+ if (start_block == PED_BE32_TO_CPU(mac_disk_data->driverlist[i].block) &&
+ block_count == PED_BE16_TO_CPU(mac_disk_data->driverlist[i].size)) {
+ uint16_t count_cur = mac_driverdata->driver_count;
mac_driverdata->driverlist[count_cur].block
= mac_disk_data->driverlist[i].block;
mac_driverdata->driverlist[count_cur].size
@@ -934,7 +934,6 @@ _generate_raw_part (PedDisk* disk, PedPartition* part,
strncpy (part_map_entry->type, mac_part_data->system_name, 32);
if (mac_part_data->is_driver) {
- mac_part_data->boot_region_length = part->geom.length;
if (mac_part_data->has_driver)
_update_driver_count(part_map_entry, mac_driverdata,
mac_disk_data);
@@ -1042,7 +1041,7 @@ write_block_zero (PedDisk* disk, MacDiskData* mac_driverdata)
raw_disk->block_size = PED_CPU_TO_BE16 (dev->sector_size);
raw_disk->block_count = PED_CPU_TO_BE32 (dev->length);
- raw_disk->driver_count = mac_driverdata->driver_count;
+ raw_disk->driver_count = PED_CPU_TO_BE16(mac_driverdata->driver_count);
memcpy(&raw_disk->driverlist[0], &mac_driverdata->driverlist[0],
sizeof(raw_disk->driverlist));
--
2.9.3