mac.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * fs/partitions/mac.c
  3. *
  4. * Code extracted from drivers/block/genhd.c
  5. * Copyright (C) 1991-1998 Linus Torvalds
  6. * Re-organised Feb 1998 Russell King
  7. */
  8. #include <linux/ctype.h>
  9. #include "check.h"
  10. #include "mac.h"
  11. #ifdef CONFIG_PPC_PMAC
  12. #include <asm/machdep.h>
  13. extern void note_bootable_part(dev_t dev, int part, int goodness);
  14. #endif
  15. /*
  16. * Code to understand MacOS partition tables.
  17. */
  18. static inline void mac_fix_string(char *stg, int len)
  19. {
  20. int i;
  21. for (i = len - 1; i >= 0 && stg[i] == ' '; i--)
  22. stg[i] = 0;
  23. }
  24. int mac_partition(struct parsed_partitions *state)
  25. {
  26. Sector sect;
  27. unsigned char *data;
  28. int slot, blocks_in_map;
  29. unsigned secsize, datasize, partoffset;
  30. #ifdef CONFIG_PPC_PMAC
  31. int found_root = 0;
  32. int found_root_goodness = 0;
  33. #endif
  34. struct mac_partition *part;
  35. struct mac_driver_desc *md;
  36. /* Get 0th block and look at the first partition map entry. */
  37. md = read_part_sector(state, 0, &sect);
  38. if (!md)
  39. return -1;
  40. if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
  41. put_dev_sector(sect);
  42. return 0;
  43. }
  44. secsize = be16_to_cpu(md->block_size);
  45. put_dev_sector(sect);
  46. datasize = round_down(secsize, 512);
  47. data = read_part_sector(state, datasize / 512, &sect);
  48. if (!data)
  49. return -1;
  50. partoffset = secsize % 512;
  51. if (partoffset + sizeof(*part) > datasize)
  52. return -1;
  53. part = (struct mac_partition *) (data + partoffset);
  54. if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
  55. put_dev_sector(sect);
  56. return 0; /* not a MacOS disk */
  57. }
  58. blocks_in_map = be32_to_cpu(part->map_count);
  59. if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
  60. put_dev_sector(sect);
  61. return 0;
  62. }
  63. strlcat(state->pp_buf, " [mac]", PAGE_SIZE);
  64. for (slot = 1; slot <= blocks_in_map; ++slot) {
  65. int pos = slot * secsize;
  66. put_dev_sector(sect);
  67. data = read_part_sector(state, pos/512, &sect);
  68. if (!data)
  69. return -1;
  70. part = (struct mac_partition *) (data + pos%512);
  71. if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
  72. break;
  73. put_partition(state, slot,
  74. be32_to_cpu(part->start_block) * (secsize/512),
  75. be32_to_cpu(part->block_count) * (secsize/512));
  76. if (!strnicmp(part->type, "Linux_RAID", 10))
  77. state->parts[slot].flags = ADDPART_FLAG_RAID;
  78. #ifdef CONFIG_PPC_PMAC
  79. /*
  80. * If this is the first bootable partition, tell the
  81. * setup code, in case it wants to make this the root.
  82. */
  83. if (machine_is(powermac)) {
  84. int goodness = 0;
  85. mac_fix_string(part->processor, 16);
  86. mac_fix_string(part->name, 32);
  87. mac_fix_string(part->type, 32);
  88. if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
  89. && strcasecmp(part->processor, "powerpc") == 0)
  90. goodness++;
  91. if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
  92. || (strnicmp(part->type, "Linux", 5) == 0
  93. && strcasecmp(part->type, "Linux_swap") != 0)) {
  94. int i, l;
  95. goodness++;
  96. l = strlen(part->name);
  97. if (strcmp(part->name, "/") == 0)
  98. goodness++;
  99. for (i = 0; i <= l - 4; ++i) {
  100. if (strnicmp(part->name + i, "root",
  101. 4) == 0) {
  102. goodness += 2;
  103. break;
  104. }
  105. }
  106. if (strnicmp(part->name, "swap", 4) == 0)
  107. goodness--;
  108. }
  109. if (goodness > found_root_goodness) {
  110. found_root = slot;
  111. found_root_goodness = goodness;
  112. }
  113. }
  114. #endif /* CONFIG_PPC_PMAC */
  115. }
  116. #ifdef CONFIG_PPC_PMAC
  117. if (found_root_goodness)
  118. note_bootable_part(state->bdev->bd_dev, found_root,
  119. found_root_goodness);
  120. #endif
  121. put_dev_sector(sect);
  122. strlcat(state->pp_buf, "\n", PAGE_SIZE);
  123. return 1;
  124. }