mac.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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;
  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. data = read_part_sector(state, secsize/512, &sect);
  47. if (!data)
  48. return -1;
  49. part = (struct mac_partition *) (data + secsize%512);
  50. if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
  51. put_dev_sector(sect);
  52. return 0; /* not a MacOS disk */
  53. }
  54. blocks_in_map = be32_to_cpu(part->map_count);
  55. if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
  56. put_dev_sector(sect);
  57. return 0;
  58. }
  59. if (blocks_in_map >= state->limit)
  60. blocks_in_map = state->limit - 1;
  61. strlcat(state->pp_buf, " [mac]", PAGE_SIZE);
  62. for (slot = 1; slot <= blocks_in_map; ++slot) {
  63. int pos = slot * secsize;
  64. put_dev_sector(sect);
  65. data = read_part_sector(state, pos/512, &sect);
  66. if (!data)
  67. return -1;
  68. part = (struct mac_partition *) (data + pos%512);
  69. if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
  70. break;
  71. put_partition(state, slot,
  72. be32_to_cpu(part->start_block) * (secsize/512),
  73. be32_to_cpu(part->block_count) * (secsize/512));
  74. if (!strnicmp(part->type, "Linux_RAID", 10))
  75. state->parts[slot].flags = ADDPART_FLAG_RAID;
  76. #ifdef CONFIG_PPC_PMAC
  77. /*
  78. * If this is the first bootable partition, tell the
  79. * setup code, in case it wants to make this the root.
  80. */
  81. if (machine_is(powermac)) {
  82. int goodness = 0;
  83. mac_fix_string(part->processor, 16);
  84. mac_fix_string(part->name, 32);
  85. mac_fix_string(part->type, 32);
  86. if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
  87. && strcasecmp(part->processor, "powerpc") == 0)
  88. goodness++;
  89. if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
  90. || (strnicmp(part->type, "Linux", 5) == 0
  91. && strcasecmp(part->type, "Linux_swap") != 0)) {
  92. int i, l;
  93. goodness++;
  94. l = strlen(part->name);
  95. if (strcmp(part->name, "/") == 0)
  96. goodness++;
  97. for (i = 0; i <= l - 4; ++i) {
  98. if (strnicmp(part->name + i, "root",
  99. 4) == 0) {
  100. goodness += 2;
  101. break;
  102. }
  103. }
  104. if (strnicmp(part->name, "swap", 4) == 0)
  105. goodness--;
  106. }
  107. if (goodness > found_root_goodness) {
  108. found_root = slot;
  109. found_root_goodness = goodness;
  110. }
  111. }
  112. #endif /* CONFIG_PPC_PMAC */
  113. }
  114. #ifdef CONFIG_PPC_PMAC
  115. if (found_root_goodness)
  116. note_bootable_part(state->bdev->bd_dev, found_root,
  117. found_root_goodness);
  118. #endif
  119. put_dev_sector(sect);
  120. strlcat(state->pp_buf, "\n", PAGE_SIZE);
  121. return 1;
  122. }