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