1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include "volume_id_internal.h"
33
34struct mac_driver_desc {
35 uint8_t signature[2];
36 uint16_t block_size;
37 uint32_t block_count;
38} PACKED;
39
40struct mac_partition {
41 uint8_t signature[2];
42 uint16_t res1;
43 uint32_t map_count;
44 uint32_t start_block;
45 uint32_t block_count;
46 uint8_t name[32];
47 uint8_t type[32];
48} PACKED;
49
50int FAST_FUNC volume_id_probe_mac_partition_map(struct volume_id *id, uint64_t off)
51{
52 const uint8_t *buf;
53 struct mac_driver_desc *driver;
54 struct mac_partition *part;
55
56 dbg("probing at offset 0x%llx", (unsigned long long) off);
57
58 buf = volume_id_get_buffer(id, off, 0x200);
59 if (buf == NULL)
60 return -1;
61
62 part = (struct mac_partition *) buf;
63 if (part->signature[0] == 'P' && part->signature[1] == 'M'
64 && (memcmp(part->type, "Apple_partition_map", 19) == 0)
65 ) {
66
67
68
69
70 return 0;
71 }
72
73 driver = (struct mac_driver_desc *) buf;
74 if (driver->signature[0] == 'E' && driver->signature[1] == 'R') {
75
76
77 unsigned bsize = be16_to_cpu(driver->block_size);
78 int part_count;
79 int i;
80
81
82 buf = volume_id_get_buffer(id, off + bsize, 0x200);
83 if (buf == NULL)
84 return -1;
85
86 part = (struct mac_partition *) buf;
87 if (part->signature[0] != 'P' || part->signature[1] != 'M')
88 return -1;
89
90 part_count = be32_to_cpu(part->map_count);
91 dbg("expecting %d partition entries", part_count);
92
93 if (id->partitions != NULL)
94 free(id->partitions);
95 id->partitions = xzalloc(part_count * sizeof(struct volume_id_partition));
96
97 id->partition_count = part_count;
98
99 for (i = 0; i < part_count; i++) {
100 uint64_t poff;
101 uint64_t plen;
102
103 buf = volume_id_get_buffer(id, off + ((i+1) * bsize), 0x200);
104 if (buf == NULL)
105 return -1;
106
107 part = (struct mac_partition *) buf;
108 if (part->signature[0] != 'P' || part->signature[1] != 'M')
109 return -1;
110
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,
115 (unsigned long long) plen);
116
117
118
119
120
121
122
123
124
125
126
127 }
128
129
130 return 0;
131 }
132
133 return -1;
134}
135