sgi.c 2.3 KB

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