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/ctype.h>
13 #ifdef CONFIG_PPC_PMAC
14 #include <asm/machdep.h>
15 extern void note_bootable_part(dev_t dev
, int part
, int goodness
);
19 * Code to understand MacOS partition tables.
22 static inline void mac_fix_string(char *stg
, int len
)
26 for (i
= len
- 1; i
>= 0 && stg
[i
] == ' '; i
--)
30 int mac_partition(struct parsed_partitions
*state
)
34 int slot
, blocks_in_map
;
36 #ifdef CONFIG_PPC_PMAC
38 int found_root_goodness
= 0;
40 struct mac_partition
*part
;
41 struct mac_driver_desc
*md
;
43 /* Get 0th block and look at the first partition map entry. */
44 md
= read_part_sector(state
, 0, §
);
47 if (be16_to_cpu(md
->signature
) != MAC_DRIVER_MAGIC
) {
51 secsize
= be16_to_cpu(md
->block_size
);
53 data
= read_part_sector(state
, secsize
/512, §
);
56 part
= (struct mac_partition
*) (data
+ secsize
%512);
57 if (be16_to_cpu(part
->signature
) != MAC_PARTITION_MAGIC
) {
59 return 0; /* not a MacOS disk */
61 blocks_in_map
= be32_to_cpu(part
->map_count
);
62 if (blocks_in_map
< 0 || blocks_in_map
>= DISK_MAX_PARTS
) {
67 if (blocks_in_map
>= state
->limit
)
68 blocks_in_map
= state
->limit
- 1;
70 strlcat(state
->pp_buf
, " [mac]", PAGE_SIZE
);
71 for (slot
= 1; slot
<= blocks_in_map
; ++slot
) {
72 int pos
= slot
* secsize
;
74 data
= read_part_sector(state
, pos
/512, §
);
77 part
= (struct mac_partition
*) (data
+ pos
%512);
78 if (be16_to_cpu(part
->signature
) != MAC_PARTITION_MAGIC
)
80 put_partition(state
, slot
,
81 be32_to_cpu(part
->start_block
) * (secsize
/512),
82 be32_to_cpu(part
->block_count
) * (secsize
/512));
84 if (!strncasecmp(part
->type
, "Linux_RAID", 10))
85 state
->parts
[slot
].flags
= ADDPART_FLAG_RAID
;
86 #ifdef CONFIG_PPC_PMAC
88 * If this is the first bootable partition, tell the
89 * setup code, in case it wants to make this the root.
91 if (machine_is(powermac
)) {
94 mac_fix_string(part
->processor
, 16);
95 mac_fix_string(part
->name
, 32);
96 mac_fix_string(part
->type
, 32);
98 if ((be32_to_cpu(part
->status
) & MAC_STATUS_BOOTABLE
)
99 && strcasecmp(part
->processor
, "powerpc") == 0)
102 if (strcasecmp(part
->type
, "Apple_UNIX_SVR2") == 0
103 || (strncasecmp(part
->type
, "Linux", 5) == 0
104 && strcasecmp(part
->type
, "Linux_swap") != 0)) {
108 l
= strlen(part
->name
);
109 if (strcmp(part
->name
, "/") == 0)
111 for (i
= 0; i
<= l
- 4; ++i
) {
112 if (strncasecmp(part
->name
+ i
, "root",
118 if (strncasecmp(part
->name
, "swap", 4) == 0)
122 if (goodness
> found_root_goodness
) {
124 found_root_goodness
= goodness
;
127 #endif /* CONFIG_PPC_PMAC */
129 #ifdef CONFIG_PPC_PMAC
130 if (found_root_goodness
)
131 note_bootable_part(state
->bdev
->bd_dev
, found_root
,
132 found_root_goodness
);
135 put_dev_sector(sect
);
136 strlcat(state
->pp_buf
, "\n", PAGE_SIZE
);