Import 2.3.41pre2
[davej-history.git] / fs / partitions / sun.c
blob5f31cde4bccc1068fe4f759ce21dc80043f39f3d
1 /*
2 * fs/partitions/sun.c
4 * Code extracted from drivers/block/genhd.c
6 * Copyright (C) 1991-1998 Linus Torvalds
7 * Re-organised Feb 1998 Russell King
8 */
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>
17 #include <asm/system.h>
19 #include "check.h"
20 #include "sun.h"
22 int sun_partition(struct gendisk *hd, kdev_t dev, unsigned long first_sector, int first_part_minor)
24 int i, csum;
25 unsigned short *ush;
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 {
41 __u32 start_cylinder;
42 __u32 num_sectors;
43 } partitions[8];
44 unsigned short magic; /* Magic number */
45 unsigned short csum; /* Label xor'd checksum */
46 } * label;
47 struct sun_partition *p;
48 unsigned long spc;
50 if(!(bh = bread(dev, 0, get_ptable_blocksize(dev)))) {
51 printk(KERN_WARNING "Dev %s: unable to read partition table\n",
52 kdevname(dev));
53 return -1;
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)); */
60 brelse(bh);
61 return 0;
63 /* Look at the checksum */
64 ush = ((unsigned short *) (label+1)) - 1;
65 for(csum = 0; ush >= ((unsigned short *) label);)
66 csum ^= *ush--;
67 if(csum) {
68 printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",
69 kdevname(dev));
70 brelse(bh);
71 return 0;
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;
77 int num_sectors;
79 st_sector = first_sector + be32_to_cpu(p->start_cylinder) * spc;
80 num_sectors = be32_to_cpu(p->num_sectors);
81 if (num_sectors)
82 add_gd_partition(hd, first_part_minor, st_sector, num_sectors);
83 first_part_minor++;
85 printk("\n");
86 brelse(bh);
87 return 1;