sun.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * fs/partitions/sun.c
  3. *
  4. * Code extracted from drivers/block/genhd.c
  5. *
  6. * Copyright (C) 1991-1998 Linus Torvalds
  7. * Re-organised Feb 1998 Russell King
  8. */
  9. #include "check.h"
  10. #include "sun.h"
  11. int sun_partition(struct parsed_partitions *state)
  12. {
  13. int i;
  14. __be16 csum;
  15. int slot = 1;
  16. __be16 *ush;
  17. Sector sect;
  18. struct sun_disklabel {
  19. unsigned char info[128]; /* Informative text string */
  20. struct sun_vtoc {
  21. __be32 version; /* Layout version */
  22. char volume[8]; /* Volume name */
  23. __be16 nparts; /* Number of partitions */
  24. struct sun_info { /* Partition hdrs, sec 2 */
  25. __be16 id;
  26. __be16 flags;
  27. } infos[8];
  28. __be16 padding; /* Alignment padding */
  29. __be32 bootinfo[3]; /* Info needed by mboot */
  30. __be32 sanity; /* To verify vtoc sanity */
  31. __be32 reserved[10]; /* Free space */
  32. __be32 timestamp[8]; /* Partition timestamp */
  33. } vtoc;
  34. __be32 write_reinstruct; /* sectors to skip, writes */
  35. __be32 read_reinstruct; /* sectors to skip, reads */
  36. unsigned char spare[148]; /* Padding */
  37. __be16 rspeed; /* Disk rotational speed */
  38. __be16 pcylcount; /* Physical cylinder count */
  39. __be16 sparecyl; /* extra sects per cylinder */
  40. __be16 obs1; /* gap1 */
  41. __be16 obs2; /* gap2 */
  42. __be16 ilfact; /* Interleave factor */
  43. __be16 ncyl; /* Data cylinder count */
  44. __be16 nacyl; /* Alt. cylinder count */
  45. __be16 ntrks; /* Tracks per cylinder */
  46. __be16 nsect; /* Sectors per track */
  47. __be16 obs3; /* bhead - Label head offset */
  48. __be16 obs4; /* ppart - Physical Partition */
  49. struct sun_partition {
  50. __be32 start_cylinder;
  51. __be32 num_sectors;
  52. } partitions[8];
  53. __be16 magic; /* Magic number */
  54. __be16 csum; /* Label xor'd checksum */
  55. } * label;
  56. struct sun_partition *p;
  57. unsigned long spc;
  58. char b[BDEVNAME_SIZE];
  59. int use_vtoc;
  60. int nparts;
  61. label = read_part_sector(state, 0, &sect);
  62. if (!label)
  63. return -1;
  64. p = label->partitions;
  65. if (be16_to_cpu(label->magic) != SUN_LABEL_MAGIC) {
  66. /* printk(KERN_INFO "Dev %s Sun disklabel: bad magic %04x\n",
  67. bdevname(bdev, b), be16_to_cpu(label->magic)); */
  68. put_dev_sector(sect);
  69. return 0;
  70. }
  71. /* Look at the checksum */
  72. ush = ((__be16 *) (label+1)) - 1;
  73. for (csum = 0; ush >= ((__be16 *) label);)
  74. csum ^= *ush--;
  75. if (csum) {
  76. printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",
  77. bdevname(state->bdev, b));
  78. put_dev_sector(sect);
  79. return 0;
  80. }
  81. /* Check to see if we can use the VTOC table */
  82. use_vtoc = ((be32_to_cpu(label->vtoc.sanity) == SUN_VTOC_SANITY) &&
  83. (be32_to_cpu(label->vtoc.version) == 1) &&
  84. (be16_to_cpu(label->vtoc.nparts) <= 8));
  85. /* Use 8 partition entries if not specified in validated VTOC */
  86. nparts = (use_vtoc) ? be16_to_cpu(label->vtoc.nparts) : 8;
  87. /*
  88. * So that old Linux-Sun partitions continue to work,
  89. * alow the VTOC to be used under the additional condition ...
  90. */
  91. use_vtoc = use_vtoc || !(label->vtoc.sanity ||
  92. label->vtoc.version || label->vtoc.nparts);
  93. spc = be16_to_cpu(label->ntrks) * be16_to_cpu(label->nsect);
  94. for (i = 0; i < nparts; i++, p++) {
  95. unsigned long st_sector;
  96. unsigned int num_sectors;
  97. st_sector = be32_to_cpu(p->start_cylinder) * spc;
  98. num_sectors = be32_to_cpu(p->num_sectors);
  99. if (num_sectors) {
  100. put_partition(state, slot, st_sector, num_sectors);
  101. state->parts[slot].flags = 0;
  102. if (use_vtoc) {
  103. if (be16_to_cpu(label->vtoc.infos[i].id) == LINUX_RAID_PARTITION)
  104. state->parts[slot].flags |= ADDPART_FLAG_RAID;
  105. else if (be16_to_cpu(label->vtoc.infos[i].id) == SUN_WHOLE_DISK)
  106. state->parts[slot].flags |= ADDPART_FLAG_WHOLEDISK;
  107. }
  108. }
  109. slot++;
  110. }
  111. strlcat(state->pp_buf, "\n", PAGE_SIZE);
  112. put_dev_sector(sect);
  113. return 1;
  114. }