3
0

unused_mac.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. //kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o
  21. //config:
  22. //config:### config FEATURE_VOLUMEID_MAC
  23. //config:### bool "mac filesystem"
  24. //config:### default y
  25. //config:### depends on VOLUMEID
  26. //config:### help
  27. //config:### TODO
  28. //config:
  29. #include "volume_id_internal.h"
  30. struct mac_driver_desc {
  31. uint8_t signature[2];
  32. uint16_t block_size;
  33. uint32_t block_count;
  34. } PACKED;
  35. struct mac_partition {
  36. uint8_t signature[2];
  37. uint16_t res1;
  38. uint32_t map_count;
  39. uint32_t start_block;
  40. uint32_t block_count;
  41. uint8_t name[32];
  42. uint8_t type[32];
  43. } PACKED;
  44. int FAST_FUNC volume_id_probe_mac_partition_map(struct volume_id *id, uint64_t off)
  45. {
  46. const uint8_t *buf;
  47. struct mac_driver_desc *driver;
  48. struct mac_partition *part;
  49. dbg("probing at offset 0x%llx", (unsigned long long) off);
  50. buf = volume_id_get_buffer(id, off, 0x200);
  51. if (buf == NULL)
  52. return -1;
  53. part = (struct mac_partition *) buf;
  54. if (part->signature[0] == 'P' && part->signature[1] == 'M' /* "PM" */
  55. && (memcmp(part->type, "Apple_partition_map", 19) == 0)
  56. ) {
  57. /* linux creates an own subdevice for the map
  58. * just return the type if the drive header is missing */
  59. // volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
  60. // id->type = "mac_partition_map";
  61. return 0;
  62. }
  63. driver = (struct mac_driver_desc *) buf;
  64. if (driver->signature[0] == 'E' && driver->signature[1] == 'R') { /* "ER" */
  65. /* we are on a main device, like a CD
  66. * just try to probe the first partition from the map */
  67. unsigned bsize = be16_to_cpu(driver->block_size);
  68. int part_count;
  69. int i;
  70. /* get first entry of partition table */
  71. buf = volume_id_get_buffer(id, off + bsize, 0x200);
  72. if (buf == NULL)
  73. return -1;
  74. part = (struct mac_partition *) buf;
  75. if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */
  76. return -1;
  77. part_count = be32_to_cpu(part->map_count);
  78. dbg("expecting %d partition entries", part_count);
  79. if (id->partitions != NULL)
  80. free(id->partitions);
  81. id->partitions = xzalloc(part_count * sizeof(struct volume_id_partition));
  82. id->partition_count = part_count;
  83. for (i = 0; i < part_count; i++) {
  84. uint64_t poff;
  85. uint64_t plen;
  86. buf = volume_id_get_buffer(id, off + ((i+1) * bsize), 0x200);
  87. if (buf == NULL)
  88. return -1;
  89. part = (struct mac_partition *) buf;
  90. if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */
  91. return -1;
  92. poff = be32_to_cpu(part->start_block) * bsize;
  93. plen = be32_to_cpu(part->block_count) * bsize;
  94. dbg("found '%s' partition entry at 0x%llx, len 0x%llx",
  95. part->type, (unsigned long long) poff,
  96. (unsigned long long) plen);
  97. // id->partitions[i].pt_off = poff;
  98. // id->partitions[i].pt_len = plen;
  99. // if (memcmp(part->type, "Apple_Free", 10) == 0) {
  100. // volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNUSED);
  101. // } else if (memcmp(part->type, "Apple_partition_map", 19) == 0) {
  102. // volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_PARTITIONTABLE);
  103. // } else {
  104. // volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNPROBED);
  105. // }
  106. }
  107. // volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
  108. // id->type = "mac_partition_map";
  109. return 0;
  110. }
  111. return -1;
  112. }