4 * Code extracted from drivers/block/genhd.c
5 * Copyright (C) 1991-1998 Linus Torvalds
6 * Re-organised Feb 1998 Russell King
9 #include <linux/ctype.h>
13 #ifdef CONFIG_PPC_PMAC
14 #include <asm/machdep.h>
15 extern void note_bootable_part(dev_t dev, int part, int goodness);
19 * Code to understand MacOS partition tables.
22 static inline void mac_fix_string(char *stg, int len)
26 for (i = len - 1; i >= 0 && stg[i] == ' '; i--)
30 int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
35 int blk, blocks_in_map;
37 #ifdef CONFIG_PPC_PMAC
39 int found_root_goodness = 0;
41 struct mac_partition *part;
42 struct mac_driver_desc *md;
44 /* Get 0th block and look at the first partition map entry. */
45 md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, §);
48 if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
52 secsize = be16_to_cpu(md->block_size);
54 data = read_dev_sector(bdev, secsize/512, §);
57 part = (struct mac_partition *) (data + secsize%512);
58 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
60 return 0; /* not a MacOS disk */
63 blocks_in_map = be32_to_cpu(part->map_count);
64 for (blk = 1; blk <= blocks_in_map; ++blk) {
65 int pos = blk * secsize;
67 data = read_dev_sector(bdev, pos/512, §);
70 part = (struct mac_partition *) (data + pos%512);
71 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
73 put_partition(state, slot,
74 be32_to_cpu(part->start_block) * (secsize/512),
75 be32_to_cpu(part->block_count) * (secsize/512));
77 #ifdef CONFIG_PPC_PMAC
79 * If this is the first bootable partition, tell the
80 * setup code, in case it wants to make this the root.
82 if (machine_is(powermac)) {
85 mac_fix_string(part->processor, 16);
86 mac_fix_string(part->name, 32);
87 mac_fix_string(part->type, 32);
89 if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
90 && strcasecmp(part->processor, "powerpc") == 0)
93 if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
94 || (strnicmp(part->type, "Linux", 5) == 0
95 && strcasecmp(part->type, "Linux_swap") != 0)) {
99 l = strlen(part->name);
100 if (strcmp(part->name, "/") == 0)
102 for (i = 0; i <= l - 4; ++i) {
103 if (strnicmp(part->name + i, "root",
109 if (strnicmp(part->name, "swap", 4) == 0)
113 if (goodness > found_root_goodness) {
115 found_root_goodness = goodness;
118 #endif /* CONFIG_PPC_PMAC */
122 #ifdef CONFIG_PPC_PMAC
123 if (found_root_goodness)
124 note_bootable_part(bdev->bd_dev, found_root, found_root_goodness);
127 put_dev_sector(sect);