bc: convert to "G trick" - this returns bc to zero bss increase
[oweals/busybox.git] / util-linux / volume_id / unused_mac.c
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 //config:### config FEATURE_VOLUMEID_MAC
21 //config:###    bool "mac filesystem"
22 //config:###    default y
23 //config:###    depends on VOLUMEID
24
25 //kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o
26
27 #include "volume_id_internal.h"
28
29 struct mac_driver_desc {
30         uint8_t         signature[2];
31         uint16_t        block_size;
32         uint32_t        block_count;
33 } PACKED;
34
35 struct mac_partition {
36         uint8_t         signature[2];
37         uint16_t        res1;
38         uint32_t        map_count;
39         uint32_t        start_block;
40         uint32_t        block_count;
41         uint8_t         name[32];
42         uint8_t         type[32];
43 } PACKED;
44
45 int FAST_FUNC volume_id_probe_mac_partition_map(struct volume_id *id, uint64_t off)
46 {
47         const uint8_t *buf;
48         struct mac_driver_desc *driver;
49         struct mac_partition *part;
50
51         dbg("probing at offset 0x%llx", (unsigned long long) off);
52
53         buf = volume_id_get_buffer(id, off, 0x200);
54         if (buf == NULL)
55                 return -1;
56
57         part = (struct mac_partition *) buf;
58         if (part->signature[0] == 'P' && part->signature[1] == 'M' /* "PM" */
59          && (memcmp(part->type, "Apple_partition_map", 19) == 0)
60         ) {
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";
65                 return 0;
66         }
67
68         driver = (struct mac_driver_desc *) buf;
69         if (driver->signature[0] == 'E' && driver->signature[1] == 'R') { /* "ER" */
70                 /* we are on a main device, like a CD
71                  * just try to probe the first partition from the map */
72                 unsigned bsize = be16_to_cpu(driver->block_size);
73                 int part_count;
74                 int i;
75
76                 /* get first entry of partition table */
77                 buf = volume_id_get_buffer(id, off +  bsize, 0x200);
78                 if (buf == NULL)
79                         return -1;
80
81                 part = (struct mac_partition *) buf;
82                 if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */
83                         return -1;
84
85                 part_count = be32_to_cpu(part->map_count);
86                 dbg("expecting %d partition entries", part_count);
87
88                 if (id->partitions != NULL)
89                         free(id->partitions);
90                 id->partitions = xzalloc(part_count * sizeof(struct volume_id_partition));
91
92                 id->partition_count = part_count;
93
94                 for (i = 0; i < part_count; i++) {
95                         uint64_t poff;
96                         uint64_t plen;
97
98                         buf = volume_id_get_buffer(id, off + ((i+1) * bsize), 0x200);
99                         if (buf == NULL)
100                                 return -1;
101
102                         part = (struct mac_partition *) buf;
103                         if (part->signature[0] != 'P' || part->signature[1] != 'M') /* not "PM" */
104                                 return -1;
105
106                         poff = be32_to_cpu(part->start_block) * bsize;
107                         plen = be32_to_cpu(part->block_count) * bsize;
108                         dbg("found '%s' partition entry at 0x%llx, len 0x%llx",
109                                         part->type, (unsigned long long) poff,
110                                         (unsigned long long) plen);
111
112 //                      id->partitions[i].pt_off = poff;
113 //                      id->partitions[i].pt_len = plen;
114
115 //                      if (memcmp(part->type, "Apple_Free", 10) == 0) {
116 //                              volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNUSED);
117 //                      } else if (memcmp(part->type, "Apple_partition_map", 19) == 0) {
118 //                              volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_PARTITIONTABLE);
119 //                      } else {
120 //                              volume_id_set_usage_part(&id->partitions[i], VOLUME_ID_UNPROBED);
121 //                      }
122                 }
123 //              volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
124 //              id->type = "mac_partition_map";
125                 return 0;
126         }
127
128         return -1;
129 }