The mac partitions code creates partitions for unallocated, free
space, and even the partition map itself. Fix by checking the VALID
and ALLOCATED bits. Fix checkpatch trailing whitespace error while at
it.
t2:/# parted /dev/sda print free
Disk /dev/sda: 34.4GB
Sector size (logical/physical): 512B/512B
Partition Table: mac
Disk Flags:
Number Start End Size File system Name Flags
1 512B 32.8kB 32.3kB Apple
32.8kB 99.6MB 99.6MB Free Space
2 99.6MB 1000MB 901MB linux
1000MB 34.4GB 33.4GB Free Space
before:
[ 67.108282] sda: [mac] sda1 sda2 sda3 sda4
patched:
[ 67.108110] sda: [mac] sda2
Signed-off-by: René Rebe <[email protected]>
---
block/partitions/mac.c | 9 ++++++---
block/partitions/mac.h | 2 ++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/block/partitions/mac.c b/block/partitions/mac.c
index b02530d98629..fc0ba1c8ec6e 100644
--- a/block/partitions/mac.c
+++ b/block/partitions/mac.c
@@ -96,9 +96,12 @@ int mac_partition(struct parsed_partitions *state)
part = (struct mac_partition *) (data + pos%512);
if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
break;
+ if ((be32_to_cpu(part->status) & (MAC_STATUS_VALID |
MAC_STATUS_ALLOCATED)) !=
+ (MAC_STATUS_VALID | MAC_STATUS_ALLOCATED))
+ continue;
put_partition(state, slot,
- be32_to_cpu(part->start_block) * (secsize/512),
- be32_to_cpu(part->block_count) * (secsize/512));
+ be32_to_cpu(part->start_block) * (secsize/512),
+ be32_to_cpu(part->block_count) * (secsize/512));
if (!strncasecmp(part->type, "Linux_RAID", 10))
state->parts[slot].flags = ADDPART_FLAG_RAID;
@@ -112,7 +115,7 @@ int mac_partition(struct parsed_partitions *state)
mac_fix_string(part->processor, 16);
mac_fix_string(part->name, 32);
- mac_fix_string(part->type, 32);
+ mac_fix_string(part->type, 32);
if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
&& strcasecmp(part->processor, "powerpc") == 0)
diff --git a/block/partitions/mac.h b/block/partitions/mac.h
index 0e41c9da7532..10828c5d53d2 100644
--- a/block/partitions/mac.h
+++ b/block/partitions/mac.h
@@ -30,6 +30,8 @@ struct mac_partition {
/* there is more stuff after this that we don't need */
};
+#define MAC_STATUS_VALID 1 /* partition is valid */
+#define MAC_STATUS_ALLOCATED 2 /* partition is allocated */
#define MAC_STATUS_BOOTABLE 8 /* partition is bootable */
#define MAC_DRIVER_MAGIC 0x4552
--
2.52.0
--
René Rebe, ExactCODE GmbH, Berlin, Germany
https://exactco.de • https://t2linux.com • https://patreon.com/renerebe