sgi.c 2.2 KB

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