sgi.c 2.3 KB

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