Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * fs/partitions/sgi.c |
| 4 | * |
| 5 | * Code extracted from drivers/block/genhd.c |
| 6 | */ |
| 7 | |
| 8 | #include "check.h" |
| 9 | #include "sgi.h" |
| 10 | |
| 11 | struct sgi_disklabel { |
| 12 | __be32 magic_mushroom; /* Big fat spliff... */ |
| 13 | __be16 root_part_num; /* Root partition number */ |
| 14 | __be16 swap_part_num; /* Swap partition number */ |
| 15 | s8 boot_file[16]; /* Name of boot file for ARCS */ |
| 16 | u8 _unused0[48]; /* Device parameter useless crapola.. */ |
| 17 | struct sgi_volume { |
| 18 | s8 name[8]; /* Name of volume */ |
| 19 | __be32 block_num; /* Logical block number */ |
| 20 | __be32 num_bytes; /* How big, in bytes */ |
| 21 | } volume[15]; |
| 22 | struct sgi_partition { |
| 23 | __be32 num_blocks; /* Size in logical blocks */ |
| 24 | __be32 first_block; /* First logical block */ |
| 25 | __be32 type; /* Type of this partition */ |
| 26 | } partitions[16]; |
| 27 | __be32 csum; /* Disk label checksum */ |
| 28 | __be32 _unused1; /* Padding */ |
| 29 | }; |
| 30 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 31 | int sgi_partition(struct parsed_partitions *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
| 33 | int i, csum; |
| 34 | __be32 magic; |
| 35 | int slot = 1; |
| 36 | unsigned int start, blocks; |
| 37 | __be32 *ui, cs; |
| 38 | Sector sect; |
| 39 | struct sgi_disklabel *label; |
| 40 | struct sgi_partition *p; |
| 41 | char b[BDEVNAME_SIZE]; |
| 42 | |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 43 | label = read_part_sector(state, 0, §); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | if (!label) |
| 45 | return -1; |
| 46 | p = &label->partitions[0]; |
| 47 | magic = label->magic_mushroom; |
| 48 | if(be32_to_cpu(magic) != SGI_LABEL_MAGIC) { |
| 49 | /*printk("Dev %s SGI disklabel: bad magic %08x\n", |
| 50 | bdevname(bdev, b), be32_to_cpu(magic));*/ |
| 51 | put_dev_sector(sect); |
| 52 | return 0; |
| 53 | } |
| 54 | ui = ((__be32 *) (label + 1)) - 1; |
| 55 | for(csum = 0; ui >= ((__be32 *) label);) { |
| 56 | cs = *ui--; |
| 57 | csum += be32_to_cpu(cs); |
| 58 | } |
| 59 | if(csum) { |
| 60 | printk(KERN_WARNING "Dev %s SGI disklabel: csum bad, label corrupted\n", |
Tejun Heo | 1493bf2 | 2010-05-15 20:09:30 +0200 | [diff] [blame] | 61 | bdevname(state->bdev, b)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | put_dev_sector(sect); |
| 63 | return 0; |
| 64 | } |
| 65 | /* All SGI disk labels have 16 partitions, disks under Linux only |
| 66 | * have 15 minor's. Luckily there are always a few zero length |
| 67 | * partitions which we don't care about so we never overflow the |
| 68 | * current_minor. |
| 69 | */ |
| 70 | for(i = 0; i < 16; i++, p++) { |
| 71 | blocks = be32_to_cpu(p->num_blocks); |
| 72 | start = be32_to_cpu(p->first_block); |
| 73 | if (blocks) { |
| 74 | put_partition(state, slot, start, blocks); |
| 75 | if (be32_to_cpu(p->type) == LINUX_RAID_PARTITION) |
Fabio Massimo Di Nitto | d18d768 | 2007-02-10 23:50:00 -0800 | [diff] [blame] | 76 | state->parts[slot].flags = ADDPART_FLAG_RAID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | slot++; |
| 79 | } |
Alexey Dobriyan | 9c867fb | 2010-08-10 18:03:14 -0700 | [diff] [blame] | 80 | strlcat(state->pp_buf, "\n", PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | put_dev_sector(sect); |
| 82 | return 1; |
| 83 | } |