Beautify diagnostic messages.
[linux-2.6/linux-mips.git] / fs / partitions / mac.c
blob119de17bac50b97332934f58ec23a1613059b302
1 /*
2 * fs/partitions/mac.c
4 * Code extracted from drivers/block/genhd.c
5 * Copyright (C) 1991-1998 Linus Torvalds
6 * Re-organised Feb 1998 Russell King
7 */
9 #include <linux/config.h>
10 #include <linux/fs.h>
11 #include <linux/genhd.h>
12 #include <linux/kernel.h>
13 #include <linux/major.h>
14 #include <linux/string.h>
15 #include <linux/blk.h>
16 #include <linux/ctype.h>
18 #include <asm/system.h>
20 #include "check.h"
21 #include "mac.h"
23 #ifdef CONFIG_PPC
24 extern void note_bootable_part(kdev_t dev, int part);
25 #endif
28 * Code to understand MacOS partition tables.
31 static inline void mac_fix_string(char *stg, int len)
33 int i;
35 for (i = len - 1; i >= 0 && stg[i] == ' '; i--)
36 stg[i] = 0;
39 int mac_partition(struct gendisk *hd, kdev_t dev, unsigned long fsec, int first_part_minor)
41 struct buffer_head *bh;
42 int blk, blocks_in_map;
43 int dev_bsize, dev_pos, pos;
44 unsigned secsize;
45 #ifdef CONFIG_PPC
46 int found_root = 0;
47 int found_root_goodness = 0;
48 #endif
49 struct mac_partition *part;
50 struct mac_driver_desc *md;
52 dev_bsize = get_ptable_blocksize(dev);
53 dev_pos = 0;
54 /* Get 0th block and look at the first partition map entry. */
55 if ((bh = bread(dev, 0, dev_bsize)) == 0) {
56 printk("%s: error reading partition table\n",
57 kdevname(dev));
58 return -1;
60 md = (struct mac_driver_desc *) bh->b_data;
61 if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
62 brelse(bh);
63 return 0;
65 secsize = be16_to_cpu(md->block_size);
66 if (secsize >= dev_bsize) {
67 brelse(bh);
68 dev_pos = secsize;
69 if ((bh = bread(dev, secsize/dev_bsize, dev_bsize)) == 0) {
70 printk("%s: error reading partition table\n",
71 kdevname(dev));
72 return -1;
75 part = (struct mac_partition *) (bh->b_data + secsize - dev_pos);
76 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
77 brelse(bh);
78 return 0; /* not a MacOS disk */
80 blocks_in_map = be32_to_cpu(part->map_count);
81 for (blk = 1; blk <= blocks_in_map; ++blk) {
82 pos = blk * secsize;
83 if (pos >= dev_pos + dev_bsize) {
84 brelse(bh);
85 dev_pos = pos;
86 if ((bh = bread(dev, pos/dev_bsize, dev_bsize)) == 0) {
87 printk("%s: error reading partition table\n",
88 kdevname(dev));
89 return -1;
92 part = (struct mac_partition *) (bh->b_data + pos - dev_pos);
93 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
94 break;
95 blocks_in_map = be32_to_cpu(part->map_count);
96 add_gd_partition(hd, first_part_minor,
97 fsec + be32_to_cpu(part->start_block) * (secsize/512),
98 be32_to_cpu(part->block_count) * (secsize/512));
100 #ifdef CONFIG_PPC
102 * If this is the first bootable partition, tell the
103 * setup code, in case it wants to make this the root.
105 if (_machine == _MACH_Pmac) {
106 int goodness = 0;
108 mac_fix_string(part->processor, 16);
109 mac_fix_string(part->name, 32);
110 mac_fix_string(part->type, 32);
112 if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
113 && strcasecmp(part->processor, "powerpc") == 0)
114 goodness++;
116 if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
117 || strcasecmp(part->type, "Linux_PPC") == 0) {
118 int i, l;
120 goodness++;
121 l = strlen(part->name);
122 if (strcmp(part->name, "/") == 0)
123 goodness++;
124 for (i = 0; i <= l - 4; ++i) {
125 if (strnicmp(part->name + i, "root",
126 4) == 0) {
127 goodness += 2;
128 break;
131 if (strnicmp(part->name, "swap", 4) == 0)
132 goodness--;
135 if (goodness > found_root_goodness) {
136 found_root = blk;
137 found_root_goodness = goodness;
140 #endif /* CONFIG_PPC */
142 ++first_part_minor;
144 #ifdef CONFIG_PPC
145 if (found_root_goodness)
146 note_bootable_part(dev, found_root);
147 #endif
148 brelse(bh);
149 printk("\n");
150 return 1;