sgi.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. 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. state->disk->disk_name);
  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. }