mac.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, struct block_device *bdev)
  25. {
  26. int slot = 1;
  27. Sector sect;
  28. unsigned char *data;
  29. int blk, blocks_in_map;
  30. unsigned secsize;
  31. #ifdef CONFIG_PPC_PMAC
  32. int found_root = 0;
  33. int found_root_goodness = 0;
  34. #endif
  35. struct mac_partition *part;
  36. struct mac_driver_desc *md;
  37. /* Get 0th block and look at the first partition map entry. */
  38. md = (struct mac_driver_desc *) read_dev_sector(bdev, 0, &sect);
  39. if (!md)
  40. return -1;
  41. if (be16_to_cpu(md->signature) != MAC_DRIVER_MAGIC) {
  42. put_dev_sector(sect);
  43. return 0;
  44. }
  45. secsize = be16_to_cpu(md->block_size);
  46. put_dev_sector(sect);
  47. data = read_dev_sector(bdev, secsize/512, &sect);
  48. if (!data)
  49. return -1;
  50. part = (struct mac_partition *) (data + secsize%512);
  51. if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
  52. put_dev_sector(sect);
  53. return 0; /* not a MacOS disk */
  54. }
  55. printk(" [mac]");
  56. blocks_in_map = be32_to_cpu(part->map_count);
  57. for (blk = 1; blk <= blocks_in_map; ++blk) {
  58. int pos = blk * secsize;
  59. put_dev_sector(sect);
  60. data = read_dev_sector(bdev, pos/512, &sect);
  61. if (!data)
  62. return -1;
  63. part = (struct mac_partition *) (data + pos%512);
  64. if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
  65. break;
  66. put_partition(state, slot,
  67. be32_to_cpu(part->start_block) * (secsize/512),
  68. be32_to_cpu(part->block_count) * (secsize/512));
  69. if (!strnicmp(part->type, "Linux_RAID", 10))
  70. state->parts[slot].flags = 1;
  71. #ifdef CONFIG_PPC_PMAC
  72. /*
  73. * If this is the first bootable partition, tell the
  74. * setup code, in case it wants to make this the root.
  75. */
  76. if (machine_is(powermac)) {
  77. int goodness = 0;
  78. mac_fix_string(part->processor, 16);
  79. mac_fix_string(part->name, 32);
  80. mac_fix_string(part->type, 32);
  81. if ((be32_to_cpu(part->status) & MAC_STATUS_BOOTABLE)
  82. && strcasecmp(part->processor, "powerpc") == 0)
  83. goodness++;
  84. if (strcasecmp(part->type, "Apple_UNIX_SVR2") == 0
  85. || (strnicmp(part->type, "Linux", 5) == 0
  86. && strcasecmp(part->type, "Linux_swap") != 0)) {
  87. int i, l;
  88. goodness++;
  89. l = strlen(part->name);
  90. if (strcmp(part->name, "/") == 0)
  91. goodness++;
  92. for (i = 0; i <= l - 4; ++i) {
  93. if (strnicmp(part->name + i, "root",
  94. 4) == 0) {
  95. goodness += 2;
  96. break;
  97. }
  98. }
  99. if (strnicmp(part->name, "swap", 4) == 0)
  100. goodness--;
  101. }
  102. if (goodness > found_root_goodness) {
  103. found_root = blk;
  104. found_root_goodness = goodness;
  105. }
  106. }
  107. #endif /* CONFIG_PPC_PMAC */
  108. ++slot;
  109. }
  110. #ifdef CONFIG_PPC_PMAC
  111. if (found_root_goodness)
  112. note_bootable_part(bdev->bd_dev, found_root, found_root_goodness);
  113. #endif
  114. put_dev_sector(sect);
  115. printk("\n");
  116. return 1;
  117. }