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>
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>
24 extern void note_bootable_part(kdev_t dev
, int part
);
28 * Code to understand MacOS partition tables.
31 static inline void mac_fix_string(char *stg
, int len
)
35 for (i
= len
- 1; i
>= 0 && stg
[i
] == ' '; i
--)
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
;
47 int found_root_goodness
= 0;
49 struct mac_partition
*part
;
50 struct mac_driver_desc
*md
;
52 dev_bsize
= get_ptable_blocksize(dev
);
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",
60 md
= (struct mac_driver_desc
*) bh
->b_data
;
61 if (be16_to_cpu(md
->signature
) != MAC_DRIVER_MAGIC
) {
65 secsize
= be16_to_cpu(md
->block_size
);
66 if (secsize
>= dev_bsize
) {
69 if ((bh
= bread(dev
, secsize
/dev_bsize
, dev_bsize
)) == 0) {
70 printk("%s: error reading partition table\n",
75 part
= (struct mac_partition
*) (bh
->b_data
+ secsize
- dev_pos
);
76 if (be16_to_cpu(part
->signature
) != MAC_PARTITION_MAGIC
) {
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
) {
83 if (pos
>= dev_pos
+ dev_bsize
) {
86 if ((bh
= bread(dev
, pos
/dev_bsize
, dev_bsize
)) == 0) {
87 printk("%s: error reading partition table\n",
92 part
= (struct mac_partition
*) (bh
->b_data
+ pos
- dev_pos
);
93 if (be16_to_cpu(part
->signature
) != MAC_PARTITION_MAGIC
)
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));
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
) {
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)
116 if (strcasecmp(part
->type
, "Apple_UNIX_SVR2") == 0
117 || strcasecmp(part
->type
, "Linux_PPC") == 0) {
121 l
= strlen(part
->name
);
122 if (strcmp(part
->name
, "/") == 0)
124 for (i
= 0; i
<= l
- 4; ++i
) {
125 if (strnicmp(part
->name
+ i
, "root",
131 if (strnicmp(part
->name
, "swap", 4) == 0)
135 if (goodness
> found_root_goodness
) {
137 found_root_goodness
= goodness
;
140 #endif /* CONFIG_PPC */
145 if (found_root_goodness
)
146 note_bootable_part(dev
, found_root
);