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"
30 struct mac_driver_desc {
34 } __attribute__((__packed__));
36 struct mac_partition {
44 } __attribute__((__packed__));
46 int volume_id_probe_mac_partition_map(struct volume_id *id, uint64_t off)
49 struct mac_driver_desc *driver;
50 struct mac_partition *part;
52 dbg("probing at offset 0x%llx", (unsigned long long) off);
54 buf = volume_id_get_buffer(id, off, 0x200);
58 part = (struct mac_partition *) buf;
59 if ((memcmp(part->signature, "PM", 2) == 0) &&
60 (memcmp(part->type, "Apple_partition_map", 19) == 0)) {
61 /* linux creates an own subdevice for the map
62 * just return the type if the drive header is missing */
63 volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
64 id->type = "mac_partition_map";
68 driver = (struct mac_driver_desc *) buf;
69 if (memcmp(driver->signature, "ER", 2) == 0) {
70 /* we are on a main device, like a CD
71 * just try to probe the first partition from the map */
72 unsigned int bsize = be16_to_cpu(driver->block_size);
76 /* get first entry of partition table */
77 buf = volume_id_get_buffer(id, off + bsize, 0x200);
81 part = (struct mac_partition *) buf;
82 if (memcmp(part->signature, "PM", 2) != 0)
85 part_count = be32_to_cpu(part->map_count);
86 dbg("expecting %d partition entries", part_count);
88 if (id->partitions != NULL)
91 malloc(part_count * sizeof(struct volume_id_partition));
92 if (id->partitions == NULL)
94 memset(id->partitions, 0x00, sizeof(struct volume_id_partition));
96 id->partition_count = part_count;
98 for (i = 0; i < part_count; i++) {
102 buf = volume_id_get_buffer(id, off + ((i+1) * bsize), 0x200);
106 part = (struct mac_partition *) buf;
107 if (memcmp(part->signature, "PM", 2) != 0)
110 poff = be32_to_cpu(part->start_block) * bsize;
111 plen = be32_to_cpu(part->block_count) * bsize;
112 dbg("found '%s' partition entry at 0x%llx, len 0x%llx",
113 part->type, (unsigned long long) poff, (unsigned long long) plen);
115 id->partitions[i].off = poff;
116 id->partitions[i].len = plen;
118 if (memcmp(part->type, "Apple_Free", 10) == 0) {
119 volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNUSED);
120 } else if (memcmp(part->type, "Apple_partition_map", 19) == 0) {
121 volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_PARTITIONTABLE);
123 volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNPROBED);
126 volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
127 id->type = "mac_partition_map";