Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  fs/partitions/sgi.c
0004  *
0005  *  Code extracted from drivers/block/genhd.c
0006  */
0007 
0008 #include "check.h"
0009 
0010 #define SGI_LABEL_MAGIC 0x0be5a941
0011 
0012 enum {
0013     LINUX_RAID_PARTITION = 0xfd,    /* autodetect RAID partition */
0014 };
0015 
0016 struct sgi_disklabel {
0017     __be32 magic_mushroom;      /* Big fat spliff... */
0018     __be16 root_part_num;       /* Root partition number */
0019     __be16 swap_part_num;       /* Swap partition number */
0020     s8 boot_file[16];       /* Name of boot file for ARCS */
0021     u8 _unused0[48];        /* Device parameter useless crapola.. */
0022     struct sgi_volume {
0023         s8 name[8];     /* Name of volume */
0024         __be32 block_num;       /* Logical block number */
0025         __be32 num_bytes;       /* How big, in bytes */
0026     } volume[15];
0027     struct sgi_partition {
0028         __be32 num_blocks;      /* Size in logical blocks */
0029         __be32 first_block; /* First logical block */
0030         __be32 type;        /* Type of this partition */
0031     } partitions[16];
0032     __be32 csum;            /* Disk label checksum */
0033     __be32 _unused1;            /* Padding */
0034 };
0035 
0036 int sgi_partition(struct parsed_partitions *state)
0037 {
0038     int i, csum;
0039     __be32 magic;
0040     int slot = 1;
0041     unsigned int start, blocks;
0042     __be32 *ui, cs;
0043     Sector sect;
0044     struct sgi_disklabel *label;
0045     struct sgi_partition *p;
0046 
0047     label = read_part_sector(state, 0, &sect);
0048     if (!label)
0049         return -1;
0050     p = &label->partitions[0];
0051     magic = label->magic_mushroom;
0052     if(be32_to_cpu(magic) != SGI_LABEL_MAGIC) {
0053         /*printk("Dev %s SGI disklabel: bad magic %08x\n",
0054                state->disk->disk_name, be32_to_cpu(magic));*/
0055         put_dev_sector(sect);
0056         return 0;
0057     }
0058     ui = ((__be32 *) (label + 1)) - 1;
0059     for(csum = 0; ui >= ((__be32 *) label);) {
0060         cs = *ui--;
0061         csum += be32_to_cpu(cs);
0062     }
0063     if(csum) {
0064         printk(KERN_WARNING "Dev %s SGI disklabel: csum bad, label corrupted\n",
0065                state->disk->disk_name);
0066         put_dev_sector(sect);
0067         return 0;
0068     }
0069     /* All SGI disk labels have 16 partitions, disks under Linux only
0070      * have 15 minor's.  Luckily there are always a few zero length
0071      * partitions which we don't care about so we never overflow the
0072      * current_minor.
0073      */
0074     for(i = 0; i < 16; i++, p++) {
0075         blocks = be32_to_cpu(p->num_blocks);
0076         start  = be32_to_cpu(p->first_block);
0077         if (blocks) {
0078             put_partition(state, slot, start, blocks);
0079             if (be32_to_cpu(p->type) == LINUX_RAID_PARTITION)
0080                 state->parts[slot].flags = ADDPART_FLAG_RAID;
0081         }
0082         slot++;
0083     }
0084     strlcat(state->pp_buf, "\n", PAGE_SIZE);
0085     put_dev_sector(sect);
0086     return 1;
0087 }