blob: 997d330a4e729559e02de4d531c7098b5240f96a [file] [log] [blame]
Denis Vlasenkode7684a2008-02-18 21:08:49 +00001/*
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
Sven-Göran Bergh3b458012013-07-31 15:45:20 +020021//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o
22
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020023//config:### config FEATURE_VOLUMEID_MAC
24//config:### bool "mac filesystem"
25//config:### default y
26//config:### depends on VOLUMEID
Sven-Göran Bergh15d0a862013-07-31 15:57:59 +020027
Denis Vlasenkode7684a2008-02-18 21:08:49 +000028#include "volume_id_internal.h"
29
30struct mac_driver_desc {
31 uint8_t signature[2];
32 uint16_t block_size;
33 uint32_t block_count;
Denys Vlasenko8dc0e192009-09-16 00:58:11 +020034} PACKED;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000035
36struct mac_partition {
37 uint8_t signature[2];
38 uint16_t res1;
39 uint32_t map_count;
40 uint32_t start_block;
41 uint32_t block_count;
42 uint8_t name[32];
43 uint8_t type[32];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +020044} PACKED;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000045
Denys Vlasenko89300962009-11-01 23:07:18 +010046int FAST_FUNC volume_id_probe_mac_partition_map(struct volume_id *id, uint64_t off)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000047{
48 const uint8_t *buf;
49 struct mac_driver_desc *driver;
50 struct mac_partition *part;
51
52 dbg("probing at offset 0x%llx", (unsigned long long) off);
53
54 buf = volume_id_get_buffer(id, off, 0x200);
55 if (buf == NULL)
56 return -1;
57
58 part = (struct mac_partition *) buf;
Denis Vlasenkod25c33f2008-03-17 09:25:05 +000059 if (part->signature[0] == 'P' && part->signature[1] == 'M' /* "PM" */
60 && (memcmp(part->type, "Apple_partition_map", 19) == 0)
61 ) {
Denis Vlasenkode7684a2008-02-18 21:08:49 +000062 /* linux creates an own subdevice for the map
63 * just return the type if the drive header is missing */
Denis Vlasenkod25c33f2008-03-17 09:25:05 +000064// volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
65// id->type = "mac_partition_map";
Denis Vlasenkode7684a2008-02-18 21:08:49 +000066 return 0;
67 }
68
69 driver = (struct mac_driver_desc *) buf;
Denis Vlasenkod25c33f2008-03-17 09:25:05 +000070 if (driver->signature[0] == 'E' && driver->signature[1] == 'R') { /* "ER" */
Denis Vlasenkode7684a2008-02-18 21:08:49 +000071 /* we are on a main device, like a CD
72 * just try to probe the first partition from the map */
73 unsigned bsize = be16_to_cpu(driver->block_size);
74 int part_count;
75 int i;
76
77 /* get first entry of partition table */
78 buf = volume_id_get_buffer(id, off + bsize, 0x200);
79 if (buf == NULL)
80 return -1;
81
82 part = (struct mac_partition *) buf;
Denis Vlasenkod25c33f2008-03-17 09:25:05 +000083 if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */
Denis Vlasenkode7684a2008-02-18 21:08:49 +000084 return -1;
85
86 part_count = be32_to_cpu(part->map_count);
87 dbg("expecting %d partition entries", part_count);
88
89 if (id->partitions != NULL)
90 free(id->partitions);
Denis Vlasenkod25c33f2008-03-17 09:25:05 +000091 id->partitions = xzalloc(part_count * sizeof(struct volume_id_partition));
Denis Vlasenkode7684a2008-02-18 21:08:49 +000092
93 id->partition_count = part_count;
94
95 for (i = 0; i < part_count; i++) {
96 uint64_t poff;
97 uint64_t plen;
98
99 buf = volume_id_get_buffer(id, off + ((i+1) * bsize), 0x200);
100 if (buf == NULL)
101 return -1;
102
103 part = (struct mac_partition *) buf;
Denis Vlasenkod25c33f2008-03-17 09:25:05 +0000104 if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000105 return -1;
106
107 poff = be32_to_cpu(part->start_block) * bsize;
108 plen = be32_to_cpu(part->block_count) * bsize;
109 dbg("found '%s' partition entry at 0x%llx, len 0x%llx",
Denis Vlasenkod25c33f2008-03-17 09:25:05 +0000110 part->type, (unsigned long long) poff,
111 (unsigned long long) plen);
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000112
Denis Vlasenkod25c33f2008-03-17 09:25:05 +0000113// id->partitions[i].pt_off = poff;
114// id->partitions[i].pt_len = plen;
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000115
Denis Vlasenkod25c33f2008-03-17 09:25:05 +0000116// if (memcmp(part->type, "Apple_Free", 10) == 0) {
117// volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNUSED);
118// } else if (memcmp(part->type, "Apple_partition_map", 19) == 0) {
119// volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_PARTITIONTABLE);
120// } else {
121// volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNPROBED);
122// }
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000123 }
Denis Vlasenkod25c33f2008-03-17 09:25:05 +0000124// volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
125// id->type = "mac_partition_map";
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000126 return 0;
127 }
128
129 return -1;
130}