2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
26 #include "volume_id.h"
31 struct mac_driver_desc {
35 } __attribute__((__packed__));
37 struct mac_partition {
45 } __attribute__((__packed__));
47 int volume_id_probe_mac_partition_map(struct volume_id *id, uint64_t off)
50 struct mac_driver_desc *driver;
51 struct mac_partition *part;
53 dbg("probing at offset 0x%llx", (unsigned long long) off);
55 buf = volume_id_get_buffer(id, off, 0x200);
59 part = (struct mac_partition *) buf;
60 if ((memcmp(part->signature, "PM", 2) == 0) &&
61 (memcmp(part->type, "Apple_partition_map", 19) == 0)) {
62 /* linux creates an own subdevice for the map
63 * just return the type if the drive header is missing */
64 volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
65 id->type = "mac_partition_map";
69 driver = (struct mac_driver_desc *) buf;
70 if (memcmp(driver->signature, "ER", 2) == 0) {
71 /* we are on a main device, like a CD
72 * just try to probe the first partition from the map */
73 unsigned int bsize = be16_to_cpu(driver->block_size);
77 /* get first entry of partition table */
78 buf = volume_id_get_buffer(id, off + bsize, 0x200);
82 part = (struct mac_partition *) buf;
83 if (memcmp(part->signature, "PM", 2) != 0)
86 part_count = be32_to_cpu(part->map_count);
87 dbg("expecting %d partition entries", part_count);
89 if (id->partitions != NULL)
92 malloc(part_count * sizeof(struct volume_id_partition));
93 if (id->partitions == NULL)
95 memset(id->partitions, 0x00, sizeof(struct volume_id_partition));
97 id->partition_count = part_count;
99 for (i = 0; i < part_count; i++) {
103 buf = volume_id_get_buffer(id, off + ((i+1) * bsize), 0x200);
107 part = (struct mac_partition *) buf;
108 if (memcmp(part->signature, "PM", 2) != 0)
111 poff = be32_to_cpu(part->start_block) * bsize;
112 plen = be32_to_cpu(part->block_count) * bsize;
113 dbg("found '%s' partition entry at 0x%llx, len 0x%llx",
114 part->type, (unsigned long long) poff, (unsigned long long) plen);
116 id->partitions[i].off = poff;
117 id->partitions[i].len = plen;
119 if (memcmp(part->type, "Apple_Free", 10) == 0) {
120 volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNUSED);
121 } else if (memcmp(part->type, "Apple_partition_map", 19) == 0) {
122 volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_PARTITIONTABLE);
124 volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNPROBED);
127 volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
128 id->type = "mac_partition_map";