#include "check.h"
#define SGI_LABEL_MAGIC 0x0be5a941
enum {
LINUX_RAID_PARTITION = 0xfd,
};
struct sgi_disklabel {
__be32 magic_mushroom;
__be16 root_part_num;
__be16 swap_part_num;
s8 boot_file[16];
u8 _unused0[48];
struct sgi_volume {
s8 name[8];
__be32 block_num;
__be32 num_bytes;
} volume[15];
struct sgi_partition {
__be32 num_blocks;
__be32 first_block;
__be32 type;
} partitions[16];
__be32 csum;
__be32 _unused1;
};
int sgi_partition(struct parsed_partitions *state)
{
int i, csum;
__be32 magic;
int slot = 1;
unsigned int start, blocks;
__be32 *ui, cs;
Sector sect;
struct sgi_disklabel *label;
struct sgi_partition *p;
label = read_part_sector(state, 0, §);
if (!label)
return -1;
p = &label->partitions[0];
magic = label->magic_mushroom;
if(be32_to_cpu(magic) != SGI_LABEL_MAGIC) {
put_dev_sector(sect);
return 0;
}
ui = ((__be32 *) (label + 1)) - 1;
for(csum = 0; ui >= ((__be32 *) label);) {
cs = *ui--;
csum += be32_to_cpu(cs);
}
if(csum) {
printk(KERN_WARNING "Dev %s SGI disklabel: csum bad, label corrupted\n",
state->disk->disk_name);
put_dev_sector(sect);
return 0;
}
for(i = 0; i < 16; i++, p++) {
blocks = be32_to_cpu(p->num_blocks);
start = be32_to_cpu(p->first_block);
if (blocks) {
put_partition(state, slot, start, blocks);
if (be32_to_cpu(p->type) == LINUX_RAID_PARTITION)
state->parts[slot].flags = ADDPART_FLAG_RAID;
}
slot++;
}
strlcat(state->pp_buf, "\n", PAGE_SIZE);
put_dev_sector(sect);
return 1;
}