Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 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 | |
Sven-Göran Bergh | 3b45801 | 2013-07-31 15:45:20 +0200 | [diff] [blame] | 21 | //kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o |
| 22 | |
Sven-Göran Bergh | 15d0a86 | 2013-07-31 15:57:59 +0200 | [diff] [blame] | 23 | //config: |
| 24 | //config:### config FEATURE_VOLUMEID_MAC |
| 25 | //config:### bool "mac filesystem" |
| 26 | //config:### default y |
| 27 | //config:### depends on VOLUMEID |
| 28 | //config:### help |
| 29 | //config:### TODO |
| 30 | //config: |
| 31 | |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 32 | #include "volume_id_internal.h" |
| 33 | |
| 34 | struct mac_driver_desc { |
| 35 | uint8_t signature[2]; |
| 36 | uint16_t block_size; |
| 37 | uint32_t block_count; |
Denys Vlasenko | 8dc0e19 | 2009-09-16 00:58:11 +0200 | [diff] [blame] | 38 | } PACKED; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 39 | |
| 40 | struct 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]; |
Denys Vlasenko | 8dc0e19 | 2009-09-16 00:58:11 +0200 | [diff] [blame] | 48 | } PACKED; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 49 | |
Denys Vlasenko | 8930096 | 2009-11-01 23:07:18 +0100 | [diff] [blame] | 50 | int FAST_FUNC volume_id_probe_mac_partition_map(struct volume_id *id, uint64_t off) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 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; |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 63 | if (part->signature[0] == 'P' && part->signature[1] == 'M' /* "PM" */ |
| 64 | && (memcmp(part->type, "Apple_partition_map", 19) == 0) |
| 65 | ) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 66 | /* linux creates an own subdevice for the map |
| 67 | * just return the type if the drive header is missing */ |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 68 | // volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE); |
| 69 | // id->type = "mac_partition_map"; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | driver = (struct mac_driver_desc *) buf; |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 74 | if (driver->signature[0] == 'E' && driver->signature[1] == 'R') { /* "ER" */ |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 75 | /* we are on a main device, like a CD |
| 76 | * just try to probe the first partition from the map */ |
| 77 | unsigned bsize = be16_to_cpu(driver->block_size); |
| 78 | int part_count; |
| 79 | int i; |
| 80 | |
| 81 | /* get first entry of partition table */ |
| 82 | buf = volume_id_get_buffer(id, off + bsize, 0x200); |
| 83 | if (buf == NULL) |
| 84 | return -1; |
| 85 | |
| 86 | part = (struct mac_partition *) buf; |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 87 | if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */ |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 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); |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 95 | id->partitions = xzalloc(part_count * sizeof(struct volume_id_partition)); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 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; |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 108 | if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */ |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 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", |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 114 | part->type, (unsigned long long) poff, |
| 115 | (unsigned long long) plen); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 116 | |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 117 | // id->partitions[i].pt_off = poff; |
| 118 | // id->partitions[i].pt_len = plen; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 119 | |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 120 | // if (memcmp(part->type, "Apple_Free", 10) == 0) { |
| 121 | // volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNUSED); |
| 122 | // } else if (memcmp(part->type, "Apple_partition_map", 19) == 0) { |
| 123 | // volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_PARTITIONTABLE); |
| 124 | // } else { |
| 125 | // volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNPROBED); |
| 126 | // } |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 127 | } |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 128 | // volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE); |
| 129 | // id->type = "mac_partition_map"; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | return -1; |
| 134 | } |