5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * Support for harddisk partitions.
27 * To be compatible with LinuxPPC and Apple we use the standard Apple
28 * SCSI disk partitioning scheme. For more information see:
29 * http://developer.apple.com/techpubs/mac/Devices/Devices-126.html#MARKER-14-92
38 #if ((CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI)) && defined(CONFIG_MAC_PARTITION)
40 /* stdlib.h causes some compatibility problems; should fixe these! -- wd */
41 #ifndef __ldiv_t_defined
43 long int quot; /* Quotient */
44 long int rem; /* Remainder */
46 extern ldiv_t ldiv (long int __numer, long int __denom);
47 # define __ldiv_t_defined 1
51 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p);
52 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p);
55 * Test for a valid MAC partition
57 int test_part_mac (block_dev_desc_t *dev_desc)
59 mac_driver_desc_t ddesc;
60 mac_partition_t mpart;
63 if (part_mac_read_ddb (dev_desc, &ddesc)) {
64 /* error reading Driver Desriptor Block, or no valid Signature */
68 n = 1; /* assuming at least one partition */
69 for (i=1; i<=n; ++i) {
70 if ((dev_desc->block_read(dev_desc->dev, i, 1, (ulong *)&mpart) != 1) ||
71 (mpart.signature != MAC_PARTITION_MAGIC) ) {
74 /* update partition count */
81 void print_part_mac (block_dev_desc_t *dev_desc)
84 mac_driver_desc_t ddesc;
85 mac_partition_t mpart;
88 if (part_mac_read_ddb (dev_desc, &ddesc)) {
89 /* error reading Driver Desriptor Block, or no valid Signature */
95 mb = ldiv(n, ((1024 * 1024) / ddesc.blk_size)); /* MB */
96 /* round to 1 digit */
97 mb.rem *= 10 * ddesc.blk_size;
99 mb.rem /= 1024 * 1024;
101 gb = ldiv(10 * mb.quot + mb.rem, 10240);
106 printf ("Block Size=%d, Number of Blocks=%d, "
107 "Total Capacity: %ld.%ld MB = %ld.%ld GB\n"
108 "DeviceType=0x%x, DeviceId=0x%x\n\n"
110 " length base (size)\n",
113 mb.quot, mb.rem, gb.quot, gb.rem,
114 ddesc.dev_type, ddesc.dev_id
117 n = 1; /* assuming at least one partition */
118 for (i=1; i<=n; ++i) {
122 printf ("%4ld: ", i);
123 if (dev_desc->block_read (dev_desc->dev, i, 1, (ulong *)&mpart) != 1) {
124 printf ("** Can't read Partition Map on %d:%ld **\n",
129 if (mpart.signature != MAC_PARTITION_MAGIC) {
130 printf ("** Bad Signature on %d:%ld - "
131 "expected 0x%04x, got 0x%04x\n",
132 dev_desc->dev, i, MAC_PARTITION_MAGIC, mpart.signature);
136 /* update partition count */
140 bytes = mpart.block_count;
141 bytes /= (1024 / ddesc.blk_size); /* kB; assumes blk_size == 512 */
151 printf ("%20.32s %-18.32s %10u @ %-10u (%3ld%c)\n",
165 * Read Device Descriptor Block
167 static int part_mac_read_ddb (block_dev_desc_t *dev_desc, mac_driver_desc_t *ddb_p)
169 if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)ddb_p) != 1) {
170 printf ("** Can't read Driver Desriptor Block **\n");
174 if (ddb_p->signature != MAC_DRIVER_MAGIC) {
176 printf ("** Bad Signature: expected 0x%04x, got 0x%04x\n",
177 MAC_DRIVER_MAGIC, ddb_p->signature);
185 * Read Partition Descriptor Block
187 static int part_mac_read_pdb (block_dev_desc_t *dev_desc, int part, mac_partition_t *pdb_p)
193 * We must always read the descritpor block for
194 * partition 1 first since this is the only way to
195 * know how many partitions we have.
197 if (dev_desc->block_read (dev_desc->dev, n, 1, (ulong *)pdb_p) != 1) {
198 printf ("** Can't read Partition Map on %d:%d **\n",
203 if (pdb_p->signature != MAC_PARTITION_MAGIC) {
204 printf ("** Bad Signature on %d:%d: "
205 "expected 0x%04x, got 0x%04x\n",
206 dev_desc->dev, n, MAC_PARTITION_MAGIC, pdb_p->signature);
213 if ((part < 1) || (part > pdb_p->map_count)) {
214 printf ("** Invalid partition %d:%d [%d:1...%d:%d only]\n",
217 dev_desc->dev, pdb_p->map_count);
221 /* update partition count */
228 int get_partition_info_mac (block_dev_desc_t *dev_desc, int part, disk_partition_t *info)
230 mac_driver_desc_t ddesc;
231 mac_partition_t mpart;
233 if (part_mac_read_ddb (dev_desc, &ddesc)) {
237 info->blksz = ddesc.blk_size;
239 if (part_mac_read_pdb (dev_desc, part, &mpart)) {
243 info->start = mpart.start_block;
244 info->size = mpart.block_count;
245 memcpy (info->type, mpart.type, sizeof(info->type));
246 memcpy (info->name, mpart.name, sizeof(info->name));
251 #endif /* (CONFIG_COMMANDS & CFG_CMD_IDE) && CONFIG_MAC_PARTITION */