]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
9 | #include <linux/config.h> | |
10 | #include <linux/ctype.h> | |
11 | #include "check.h" | |
12 | #include "mac.h" | |
13 | ||
14 | #ifdef CONFIG_PPC_PMAC | |
e8222502 | 15 | #include <asm/machdep.h> |
1da177e4 LT |
16 | extern void note_bootable_part(dev_t dev, int part, int goodness); |
17 | #endif | |
18 | ||
19 | /* | |
20 | * Code to understand MacOS partition tables. | |
21 | */ | |
22 | ||
23 | static inline void mac_fix_string(char *stg, int len) | |
24 | { | |
25 | int i; | |
26 | ||
27 | for (i = len - 1; i >= 0 && stg[i] == ' '; i--) | |
28 | stg[i] = 0; | |
29 | } | |
30 | ||
31 | int mac_partition(struct parsed_partitions *state, struct block_device *bdev) | |
32 | { | |
33 | int slot = 1; | |
34 | Sector sect; | |
35 | unsigned char *data; | |
36 | int blk, blocks_in_map; | |
37 | unsigned secsize; | |
38 | #ifdef CONFIG_PPC_PMAC | |
39 | int found_root = 0; | |
40 | int found_root_goodness = 0; | |
41 | #endif | |
42 | struct mac_partition *part; | |
43 | struct mac_driver_desc *md; | |
44 | ||
45 | /* Get 0th block and look at the first partition map entry. */ | |
46 | md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, §); | |
47 | if (!md) | |
48 | return -1; | |
49 | if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) { | |
50 | put_dev_sector(sect); | |
51 | return 0; | |
52 | } | |
53 | secsize = be16_to_cpu(md->block_size); | |
54 | put_dev_sector(sect); | |
55 | data = read_dev_sector(bdev, secsize/512, §); | |
56 | if (!data) | |
57 | return -1; | |
58 | part = (struct mac_partition *) (data + secsize%512); | |
59 | if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) { | |
60 | put_dev_sector(sect); | |
61 | return 0; /* not a MacOS disk */ | |
62 | } | |
63 | printk(" [mac]"); | |
64 | blocks_in_map = be32_to_cpu(part->map_count); | |
65 | for (blk = 1; blk <= blocks_in_map; ++blk) { | |
66 | int pos = blk * secsize; | |
67 | put_dev_sector(sect); | |
68 | data = read_dev_sector(bdev, pos/512, §); | |
69 | if (!data) | |
70 | return -1; | |
71 | part = (struct mac_partition *) (data + pos%512); | |
72 | if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) | |
73 | break; | |
74 | put_partition(state, slot, | |
75 | be32_to_cpu(part->start_block) * (secsize/512), | |
76 | be32_to_cpu(part->block_count) * (secsize/512)); | |
77 | ||
78 | #ifdef CONFIG_PPC_PMAC | |
79 | /* | |
80 | * If this is the first bootable partition, tell the | |
81 | * setup code, in case it wants to make this the root. | |
82 | */ | |
e8222502 | 83 | if (machine_is(powermac)) { |
1da177e4 LT |
84 | int goodness = 0; |
85 | ||
86 | mac_fix_string(part->processor, 16); | |
87 | mac_fix_string(part->name, 32); | |
88 | mac_fix_string(part->type, 32); | |
89 | ||
90 | if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE) | |
91 | && strcasecmp(part->processor, "powerpc") == 0) | |
92 | goodness++; | |
93 | ||
94 | if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0 | |
95 | || (strnicmp(part->type, "Linux", 5) == 0 | |
96 | && strcasecmp(part->type, "Linux_swap") != 0)) { | |
97 | int i, l; | |
98 | ||
99 | goodness++; | |
100 | l = strlen(part->name); | |
101 | if (strcmp(part->name, "/") == 0) | |
102 | goodness++; | |
103 | for (i = 0; i <= l - 4; ++i) { | |
104 | if (strnicmp(part->name + i, "root", | |
105 | 4) == 0) { | |
106 | goodness += 2; | |
107 | break; | |
108 | } | |
109 | } | |
110 | if (strnicmp(part->name, "swap", 4) == 0) | |
111 | goodness--; | |
112 | } | |
113 | ||
114 | if (goodness > found_root_goodness) { | |
115 | found_root = blk; | |
116 | found_root_goodness = goodness; | |
117 | } | |
118 | } | |
119 | #endif /* CONFIG_PPC_PMAC */ | |
120 | ||
121 | ++slot; | |
122 | } | |
123 | #ifdef CONFIG_PPC_PMAC | |
124 | if (found_root_goodness) | |
125 | note_bootable_part(bdev->bd_dev, found_root, found_root_goodness); | |
126 | #endif | |
127 | ||
128 | put_dev_sector(sect); | |
129 | printk("\n"); | |
130 | return 1; | |
131 | } |