Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/partitions/mac.c |
| 3 | * |
| 4 | * Code extracted from drivers/block/genhd.c |
| 5 | * Copyright (C) 1991-1998 Linus Torvalds |
| 6 | * Re-organised Feb 1998 Russell King |
| 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/ctype.h> |
| 10 | #include "check.h" |
| 11 | #include "mac.h" |
| 12 | |
| 13 | #ifdef CONFIG_PPC_PMAC |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 14 | #include <asm/machdep.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | extern void note_bootable_part(dev_t dev, int part, int goodness); |
| 16 | #endif |
| 17 | |
| 18 | /* |
| 19 | * Code to understand MacOS partition tables. |
| 20 | */ |
| 21 | |
| 22 | static inline void mac_fix_string(char *stg, int len) |
| 23 | { |
| 24 | int i; |
| 25 | |
| 26 | for (i = len - 1; i >= 0 && stg[i] == ' '; i--) |
| 27 | stg[i] = 0; |
| 28 | } |
| 29 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 30 | int mac_partition(struct parsed_partitions *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | Sector sect; |
| 33 | unsigned char *data; |
Timo Warns | fa7ea87 | 2011-02-17 22:27:40 +0100 | [diff] [blame] | 34 | int slot, blocks_in_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | unsigned secsize; |
| 36 | #ifdef CONFIG_PPC_PMAC |
| 37 | int found_root = 0; |
| 38 | int found_root_goodness = 0; |
| 39 | #endif |
| 40 | struct mac_partition *part; |
| 41 | struct mac_driver_desc *md; |
| 42 | |
| 43 | /* Get 0th block and look at the first partition map entry. */ |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 44 | md = read_part_sector(state, 0, §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | if (!md) |
| 46 | return -1; |
| 47 | if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) { |
| 48 | put_dev_sector(sect); |
| 49 | return 0; |
| 50 | } |
| 51 | secsize = be16_to_cpu(md->block_size); |
| 52 | put_dev_sector(sect); |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 53 | data = read_part_sector(state, secsize/512, §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | if (!data) |
| 55 | return -1; |
| 56 | part = (struct mac_partition *) (data + secsize%512); |
| 57 | if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) { |
| 58 | put_dev_sector(sect); |
| 59 | return 0; /* not a MacOS disk */ |
| 60 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | blocks_in_map = be32_to_cpu(part->map_count); |
Timo Warns | fa7ea87 | 2011-02-17 22:27:40 +0100 | [diff] [blame] | 62 | if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) { |
| 63 | put_dev_sector(sect); |
| 64 | return 0; |
| 65 | } |
Ming Lei | 06004e6 | 2013-02-27 17:05:18 -0800 | [diff] [blame] | 66 | |
| 67 | if (blocks_in_map >= state->limit) |
| 68 | blocks_in_map = state->limit - 1; |
| 69 | |
Timo Warns | fa7ea87 | 2011-02-17 22:27:40 +0100 | [diff] [blame] | 70 | strlcat(state->pp_buf, " [mac]", PAGE_SIZE); |
| 71 | for (slot = 1; slot <= blocks_in_map; ++slot) { |
| 72 | int pos = slot * secsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | put_dev_sector(sect); |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 74 | data = read_part_sector(state, pos/512, §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (!data) |
| 76 | return -1; |
| 77 | part = (struct mac_partition *) (data + pos%512); |
| 78 | if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) |
| 79 | break; |
| 80 | put_partition(state, slot, |
| 81 | be32_to_cpu(part->start_block) * (secsize/512), |
| 82 | be32_to_cpu(part->block_count) * (secsize/512)); |
| 83 | |
Rasmus Villemoes | 5829405 | 2014-09-16 22:51:16 +0200 | [diff] [blame] | 84 | if (!strncasecmp(part->type, "Linux_RAID", 10)) |
Cesar Eduardo Barros | cc91062 | 2010-04-17 19:28:09 -0300 | [diff] [blame] | 85 | state->parts[slot].flags = ADDPART_FLAG_RAID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #ifdef CONFIG_PPC_PMAC |
| 87 | /* |
| 88 | * If this is the first bootable partition, tell the |
| 89 | * setup code, in case it wants to make this the root. |
| 90 | */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 91 | if (machine_is(powermac)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | int goodness = 0; |
| 93 | |
| 94 | mac_fix_string(part->processor, 16); |
| 95 | mac_fix_string(part->name, 32); |
| 96 | mac_fix_string(part->type, 32); |
| 97 | |
| 98 | if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE) |
| 99 | && strcasecmp(part->processor, "powerpc") == 0) |
| 100 | goodness++; |
| 101 | |
| 102 | if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0 |
Rasmus Villemoes | 5829405 | 2014-09-16 22:51:16 +0200 | [diff] [blame] | 103 | || (strncasecmp(part->type, "Linux", 5) == 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | && strcasecmp(part->type, "Linux_swap") != 0)) { |
| 105 | int i, l; |
| 106 | |
| 107 | goodness++; |
| 108 | l = strlen(part->name); |
| 109 | if (strcmp(part->name, "/") == 0) |
| 110 | goodness++; |
| 111 | for (i = 0; i <= l - 4; ++i) { |
Rasmus Villemoes | 5829405 | 2014-09-16 22:51:16 +0200 | [diff] [blame] | 112 | if (strncasecmp(part->name + i, "root", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | 4) == 0) { |
| 114 | goodness += 2; |
| 115 | break; |
| 116 | } |
| 117 | } |
Rasmus Villemoes | 5829405 | 2014-09-16 22:51:16 +0200 | [diff] [blame] | 118 | if (strncasecmp(part->name, "swap", 4) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | goodness--; |
| 120 | } |
| 121 | |
| 122 | if (goodness > found_root_goodness) { |
Timo Warns | fa7ea87 | 2011-02-17 22:27:40 +0100 | [diff] [blame] | 123 | found_root = slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | found_root_goodness = goodness; |
| 125 | } |
| 126 | } |
| 127 | #endif /* CONFIG_PPC_PMAC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | #ifdef CONFIG_PPC_PMAC |
| 130 | if (found_root_goodness) |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 131 | note_bootable_part(state->bdev->bd_dev, found_root, |
| 132 | found_root_goodness); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #endif |
| 134 | |
| 135 | put_dev_sector(sect); |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 136 | strlcat(state->pp_buf, "\n", PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return 1; |
| 138 | } |