sun.c 3.8 KB

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