]> git.pld-linux.org Git - packages/parted.git/blob - 0067-libparted-Fix-MacOS-boot-support.patch
- rel 4; tons of patches from FC
[packages/parted.git] / 0067-libparted-Fix-MacOS-boot-support.patch
1 From 526f3ee2afbe7cd90d282915b7b580d4f356c4eb Mon Sep 17 00:00:00 2001
2 From: Laurent Vivier <laurent@vivier.eu>
3 Date: Fri, 9 Dec 2016 15:10:53 +0100
4 Subject: [PATCH 67/75] libparted: Fix MacOS boot support
5
6 boot_region_length (or BootSize in the MacOS dialect) is the length
7 of the driver code in the driver partition. This length is used
8 to compute the checksum of the driver.
9
10 libparted updates this value by setting the whole size of the partition
11 without computing the checksum of the driver using this size.
12
13 As the checksum is wrong, the driver is broken and cannot be loaded
14 by the MacOS ROM, and thus the disk is not bootable anymore.
15
16 Moreover, parted try to update the driver list and makes it disappear.
17
18 As parted is not able to insert a driver in a partition,
19 the driver is generally inserted by the Apple HD Tool,
20 this patch removes the line updating the driver size.
21
22 We also simplify the driver list scan and fix endianess use.
23
24 This has been tested... and it works, now.
25
26 I have updated a bootable disk with parted on x86_64 and
27 then been able to boot it (again) on a Mac LC III.
28
29 Signed-off-by: Laurent Vivier <laurent@vivier.eu>
30 Signed-off-by: Brian C. Lane <bcl@redhat.com>
31 ---
32  libparted/labels/mac.c | 41 ++++++++++++++++++++---------------------
33  1 file changed, 20 insertions(+), 21 deletions(-)
34
35 diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
36 index d8da941..fa4e43f 100644
37 --- a/libparted/labels/mac.c
38 +++ b/libparted/labels/mac.c
39 @@ -411,14 +411,14 @@ _rawpart_has_driver (const MacRawPartition* raw_part, MacDiskData* mac_disk_data
40  {
41         MacDeviceDriver *driverlist;
42         uint16_t i;
43 -       uint32_t driver_bs, driver_be, part_be;
44 +       uint32_t start_block, block_count;
45  
46 +       start_block = PED_BE32_TO_CPU(raw_part->start_block);
47 +       block_count = PED_BE32_TO_CPU(raw_part->block_count);
48         driverlist = &mac_disk_data->driverlist[0];
49         for (i = 0; i < mac_disk_data->driver_count; i++) {
50 -               driver_bs = driverlist->block;
51 -               driver_be = driver_bs + driverlist->size;
52 -               part_be = raw_part->start_block + raw_part->block_count;
53 -               if (driver_bs >= raw_part->start_block && driver_be <= part_be)
54 +               if (start_block == PED_BE32_TO_CPU(driverlist->block) &&
55 +                    block_count == PED_BE16_TO_CPU(driverlist->size))
56                         return 1;
57                 driverlist++;
58         }
59 @@ -751,11 +751,12 @@ mac_read (PedDisk* disk)
60         if (!ped_disk_delete_all (disk))
61                 goto error;
62  
63 -       if (raw_disk->driver_count && raw_disk->driver_count < 62) {
64 +       if (PED_BE16_TO_CPU(raw_disk->driver_count) &&
65 +            PED_BE16_TO_CPU(raw_disk->driver_count) < 62) {
66                 memcpy(&mac_disk_data->driverlist[0], &raw_disk->driverlist[0],
67                                 sizeof(mac_disk_data->driverlist));
68 -               mac_disk_data->driver_count = raw_disk->driver_count;
69 -               mac_disk_data->block_size = raw_disk->block_size;
70 +               mac_disk_data->driver_count = PED_BE16_TO_CPU(raw_disk->driver_count);
71 +               mac_disk_data->block_size = PED_BE16_TO_CPU(raw_disk->block_size);
72         }
73  
74         /* If _disk_analyse_block_size has increased the sector_size,
75 @@ -877,17 +878,16 @@ static void
76  _update_driver_count (MacRawPartition* part_map_entry,
77                       MacDiskData *mac_driverdata, const MacDiskData* mac_disk_data)
78  {
79 -       uint16_t        i, count_orig, count_cur;
80 -       uint32_t        driver_bs, driver_be, part_be;
81 -
82 -       count_cur = mac_driverdata->driver_count;
83 -       count_orig = mac_disk_data->driver_count;
84 -       for (i = 0; i < count_orig; i++) {
85 -               driver_bs = mac_disk_data->driverlist[i].block;
86 -               driver_be = driver_bs + mac_disk_data->driverlist[i].size;
87 -               part_be = part_map_entry->start_block + part_map_entry->block_count;
88 -               if (driver_bs >= part_map_entry->start_block
89 -                               && driver_be <= part_be) {
90 +       uint16_t        i;
91 +       uint32_t        start_block, block_count;
92 +
93 +       start_block = PED_BE32_TO_CPU(part_map_entry->start_block);
94 +       block_count = PED_BE32_TO_CPU(part_map_entry->block_count);
95 +
96 +       for (i = 0; i < mac_disk_data->driver_count; i++) {
97 +               if (start_block == PED_BE32_TO_CPU(mac_disk_data->driverlist[i].block) &&
98 +                   block_count == PED_BE16_TO_CPU(mac_disk_data->driverlist[i].size)) {
99 +                       uint16_t count_cur = mac_driverdata->driver_count;
100                         mac_driverdata->driverlist[count_cur].block
101                                 = mac_disk_data->driverlist[i].block;
102                         mac_driverdata->driverlist[count_cur].size
103 @@ -934,7 +934,6 @@ _generate_raw_part (PedDisk* disk, PedPartition* part,
104         strncpy (part_map_entry->type, mac_part_data->system_name, 32);
105  
106         if (mac_part_data->is_driver) {
107 -               mac_part_data->boot_region_length = part->geom.length;
108                 if (mac_part_data->has_driver)
109                         _update_driver_count(part_map_entry, mac_driverdata,
110                                         mac_disk_data);
111 @@ -1042,7 +1041,7 @@ write_block_zero (PedDisk* disk, MacDiskData* mac_driverdata)
112         raw_disk->block_size = PED_CPU_TO_BE16 (dev->sector_size);
113         raw_disk->block_count = PED_CPU_TO_BE32 (dev->length);
114  
115 -       raw_disk->driver_count = mac_driverdata->driver_count;
116 +       raw_disk->driver_count = PED_CPU_TO_BE16(mac_driverdata->driver_count);
117         memcpy(&raw_disk->driverlist[0], &mac_driverdata->driverlist[0],
118                         sizeof(raw_disk->driverlist));
119  
120 -- 
121 2.9.3
122
This page took 0.069101 seconds and 3 git commands to generate.