4 * Code extracted from drivers/block/genhd.c
6 * Copyright (C) 1991-1998 Linus Torvalds
7 * Re-organised Feb 1998 Russell King
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>
17 #include <asm/system.h>
22 int sun_partition(struct gendisk
*hd
, kdev_t dev
, unsigned long first_sector
, int first_part_minor
)
26 struct buffer_head
*bh
;
27 struct sun_disklabel
{
28 unsigned char info
[128]; /* Informative text string */
29 unsigned char spare
[292]; /* Boot information etc. */
30 unsigned short rspeed
; /* Disk rotational speed */
31 unsigned short pcylcount
; /* Physical cylinder count */
32 unsigned short sparecyl
; /* extra sects per cylinder */
33 unsigned char spare2
[4]; /* More magic... */
34 unsigned short ilfact
; /* Interleave factor */
35 unsigned short ncyl
; /* Data cylinder count */
36 unsigned short nacyl
; /* Alt. cylinder count */
37 unsigned short ntrks
; /* Tracks per cylinder */
38 unsigned short nsect
; /* Sectors per track */
39 unsigned char spare3
[4]; /* Even more magic... */
40 struct sun_partition
{
44 unsigned short magic
; /* Magic number */
45 unsigned short csum
; /* Label xor'd checksum */
47 struct sun_partition
*p
;
50 if(!(bh
= bread(dev
, 0, get_ptable_blocksize(dev
)))) {
51 if (warn_no_part
) printk(KERN_WARNING
"Dev %s: unable to read partition table\n",
55 label
= (struct sun_disklabel
*) bh
->b_data
;
56 p
= label
->partitions
;
57 if (be16_to_cpu(label
->magic
) != SUN_LABEL_MAGIC
) {
58 /* printk(KERN_INFO "Dev %s Sun disklabel: bad magic %04x\n",
59 kdevname(dev), be16_to_cpu(label->magic)); */
63 /* Look at the checksum */
64 ush
= ((unsigned short *) (label
+1)) - 1;
65 for(csum
= 0; ush
>= ((unsigned short *) label
);)
68 printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",
73 /* All Sun disks have 8 partition entries */
74 spc
= be16_to_cpu(label
->ntrks
) * be16_to_cpu(label
->nsect
);
75 for(i
=0; i
< 8; i
++, p
++) {
76 unsigned long st_sector
;
79 st_sector
= first_sector
+ be32_to_cpu(p
->start_cylinder
) * spc
;
80 num_sectors
= be32_to_cpu(p
->num_sectors
);
82 add_gd_partition(hd
, first_part_minor
, st_sector
, num_sectors
);