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/config.h>
10 #include <linux/ctype.h>
14 #ifdef CONFIG_PPC_PMAC
15 #include <asm/machdep.h>
16 extern void note_bootable_part(dev_t dev, int part, int goodness);
20 * Code to understand MacOS partition tables.
23 static inline void mac_fix_string(char *stg, int len)
27 for (i = len - 1; i >= 0 && stg[i] == ' '; i--)
31 int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
36 int blk, blocks_in_map;
38 #ifdef CONFIG_PPC_PMAC
40 int found_root_goodness = 0;
42 struct mac_partition *part;
43 struct mac_driver_desc *md;
45 /* Get 0th block and look at the first partition map entry. */
46 md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, §);
49 if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
53 secsize = be16_to_cpu(md->block_size);
55 data = read_dev_sector(bdev, secsize/512, §);
58 part = (struct mac_partition *) (data + secsize%512);
59 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
61 return 0; /* not a MacOS disk */
64 blocks_in_map = be32_to_cpu(part->map_count);
65 for (blk = 1; blk <= blocks_in_map; ++blk) {
66 int pos = blk * secsize;
68 data = read_dev_sector(bdev, pos/512, §);
71 part = (struct mac_partition *) (data + pos%512);
72 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
74 put_partition(state, slot,
75 be32_to_cpu(part->start_block) * (secsize/512),
76 be32_to_cpu(part->block_count) * (secsize/512));
78 #ifdef CONFIG_PPC_PMAC
80 * If this is the first bootable partition, tell the
81 * setup code, in case it wants to make this the root.
83 if (machine_is(powermac)) {
86 mac_fix_string(part->processor, 16);
87 mac_fix_string(part->name, 32);
88 mac_fix_string(part->type, 32);
90 if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
91 && strcasecmp(part->processor, "powerpc") == 0)
94 if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
95 || (strnicmp(part->type, "Linux", 5) == 0
96 && strcasecmp(part->type, "Linux_swap") != 0)) {
100 l = strlen(part->name);
101 if (strcmp(part->name, "/") == 0)
103 for (i = 0; i <= l - 4; ++i) {
104 if (strnicmp(part->name + i, "root",
110 if (strnicmp(part->name, "swap", 4) == 0)
114 if (goodness > found_root_goodness) {
116 found_root_goodness = goodness;
119 #endif /* CONFIG_PPC_PMAC */
123 #ifdef CONFIG_PPC_PMAC
124 if (found_root_goodness)
125 note_bootable_part(bdev->bd_dev, found_root, found_root_goodness);
128 put_dev_sector(sect);