mac.c 3.3 KB

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