make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / fs / partitions / mac.c
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/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>
17
18 #include <asm/system.h>
19
20 #include "check.h"
21 #include "mac.h"
22
23 /*
24  * Code to understand MacOS partition tables.
25  */
26
27 int mac_partition(struct gendisk *hd, struct block_device *bdev,
28                 unsigned long fsec, int first_part_minor)
29 {
30         Sector sect;
31         unsigned char *data;
32         int blk, blocks_in_map;
33         unsigned secsize;
34         struct mac_partition *part;
35         struct mac_driver_desc *md;
36
37         /* Get 0th block and look at the first partition map entry. */
38         md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, &sect);
39         if (!md)
40                 return -1;
41         if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
42                 put_dev_sector(sect);
43                 return 0;
44         }
45         secsize = be16_to_cpu(md->block_size);
46         put_dev_sector(sect);
47         data = read_dev_sector(bdev, secsize/512, &sect);
48         if (!data)
49                 return -1;
50         part = (struct mac_partition *) (data + secsize%512);
51         if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
52                 put_dev_sector(sect);
53                 return 0;               /* not a MacOS disk */
54         }
55         printk(" [mac]");
56         blocks_in_map = be32_to_cpu(part->map_count);
57         for (blk = 1; blk <= blocks_in_map; ++blk) {
58                 int pos = blk * secsize;
59                 put_dev_sector(sect);
60                 data = read_dev_sector(bdev, pos/512, &sect);
61                 if (!data)
62                         return -1;
63                 part = (struct mac_partition *) (data + pos%512);
64                 if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
65                         break;
66                 add_gd_partition(hd, first_part_minor,
67                         fsec + be32_to_cpu(part->start_block) * (secsize/512),
68                         be32_to_cpu(part->block_count) * (secsize/512));
69
70                 ++first_part_minor;
71         }
72
73         put_dev_sector(sect);
74         printk("\n");
75         return 1;
76 }
77