4 * Code extracted from drivers/block/genhd.c
6 * Copyright (C) 1991-1998 Linus Torvalds
7 * Re-organised Feb 1998 Russell King
10 #include <linux/config.h>
12 #include <linux/genhd.h>
13 #include <linux/kernel.h>
14 #include <linux/major.h>
15 #include <linux/string.h>
16 #include <linux/blk.h>
18 #include <asm/system.h>
23 #ifdef CONFIG_BLK_DEV_MD
24 extern void md_autodetect_dev(kdev_t dev);
27 int sun_partition(struct gendisk *hd, struct block_device *bdev, unsigned long first_sector, int first_part_minor)
32 kdev_t dev = to_kdev_t(bdev->bd_dev);
33 struct sun_disklabel {
34 unsigned char info[128]; /* Informative text string */
35 unsigned char spare0[14];
42 unsigned char spare[246]; /* Boot information etc. */
43 unsigned short rspeed; /* Disk rotational speed */
44 unsigned short pcylcount; /* Physical cylinder count */
45 unsigned short sparecyl; /* extra sects per cylinder */
46 unsigned char spare2[4]; /* More magic... */
47 unsigned short ilfact; /* Interleave factor */
48 unsigned short ncyl; /* Data cylinder count */
49 unsigned short nacyl; /* Alt. cylinder count */
50 unsigned short ntrks; /* Tracks per cylinder */
51 unsigned short nsect; /* Sectors per track */
52 unsigned char spare3[4]; /* Even more magic... */
53 struct sun_partition {
57 unsigned short magic; /* Magic number */
58 unsigned short csum; /* Label xor'd checksum */
60 struct sun_partition *p;
63 label = (struct sun_disklabel *)read_dev_sector(bdev, 0, §);
67 p = label->partitions;
68 if (be16_to_cpu(label->magic) != SUN_LABEL_MAGIC) {
69 /* printk(KERN_INFO "Dev %s Sun disklabel: bad magic %04x\n",
70 bdevname(dev), be16_to_cpu(label->magic)); */
74 /* Look at the checksum */
75 ush = ((unsigned short *) (label+1)) - 1;
76 for (csum = 0; ush >= ((unsigned short *) label);)
79 printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",
85 /* All Sun disks have 8 partition entries */
86 spc = be16_to_cpu(label->ntrks) * be16_to_cpu(label->nsect);
87 for (i = 0; i < 8; i++, p++) {
88 unsigned long st_sector;
89 unsigned int num_sectors;
91 st_sector = first_sector + be32_to_cpu(p->start_cylinder) * spc;
92 num_sectors = be32_to_cpu(p->num_sectors);
94 add_gd_partition(hd, first_part_minor,
95 st_sector, num_sectors);
96 #ifdef CONFIG_BLK_DEV_MD
97 if (label->infos[i].id == LINUX_RAID_PARTITION)
98 md_autodetect_dev(MKDEV(hd->major,
105 put_dev_sector(sect);