mac.c 3.1 KB

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