ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / partitions / sgi.c
1 /*
2  *  fs/partitions/sgi.c
3  *
4  *  Code extracted from drivers/block/genhd.c
5  */
6
7 #include "check.h"
8 #include "sgi.h"
9
10 struct sgi_disklabel {
11         s32 magic_mushroom;             /* Big fat spliff... */
12         s16 root_part_num;              /* Root partition number */
13         s16 swap_part_num;              /* Swap partition number */
14         s8 boot_file[16];               /* Name of boot file for ARCS */
15         u8 _unused0[48];                /* Device parameter useless crapola.. */
16         struct sgi_volume {
17                 s8 name[8];             /* Name of volume */
18                 s32 block_num;          /* Logical block number */
19                 s32 num_bytes;          /* How big, in bytes */
20         } volume[15];
21         struct sgi_partition {
22                 u32 num_blocks;         /* Size in logical blocks */
23                 u32 first_block;        /* First logical block */
24                 s32 type;               /* Type of this partition */
25         } partitions[16];
26         s32 csum;                       /* Disk label checksum */
27         s32 _unused1;                   /* Padding */
28 };
29
30 int sgi_partition(struct parsed_partitions *state, struct block_device *bdev)
31 {
32         int i, csum, magic;
33         int slot = 1;
34         unsigned int *ui, start, blocks, cs;
35         Sector sect;
36         struct sgi_disklabel *label;
37         struct sgi_partition *p;
38         char b[BDEVNAME_SIZE];
39
40         label = (struct sgi_disklabel *) read_dev_sector(bdev, 0, &sect);
41         if (!label)
42                 return -1;
43         p = &label->partitions[0];
44         magic = label->magic_mushroom;
45         if(be32_to_cpu(magic) != SGI_LABEL_MAGIC) {
46                 /*printk("Dev %s SGI disklabel: bad magic %08x\n",
47                        bdevname(bdev, b), magic);*/
48                 put_dev_sector(sect);
49                 return 0;
50         }
51         ui = ((unsigned int *) (label + 1)) - 1;
52         for(csum = 0; ui >= ((unsigned int *) label);) {
53                 cs = *ui--;
54                 csum += be32_to_cpu(cs);
55         }
56         if(csum) {
57                 printk(KERN_WARNING "Dev %s SGI disklabel: csum bad, label corrupted\n",
58                        bdevname(bdev, b));
59                 put_dev_sector(sect);
60                 return 0;
61         }
62         /* All SGI disk labels have 16 partitions, disks under Linux only
63          * have 15 minor's.  Luckily there are always a few zero length
64          * partitions which we don't care about so we never overflow the
65          * current_minor.
66          */
67         for(i = 0; i < 16; i++, p++) {
68                 blocks = be32_to_cpu(p->num_blocks);
69                 start  = be32_to_cpu(p->first_block);
70                 if (blocks)
71                         put_partition(state, slot++, start, blocks);
72         }
73         printk("\n");
74         put_dev_sector(sect);
75         return 1;
76 }