alsa.audio: build the bridge link lib only for linux architecture
[AROS.git] / arch / ppc-sam440 / boot / parthenope / src / rdb.c
blobc20c1a03795f87ec40ea4cfb8c346d3c32b75ad4
1 /* rdb.c */
3 /* <project_name> -- <project_description>
5 * Copyright (C) 2006 - 2007
6 * Giuseppe Coviello <cjg@cruxppc.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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, MA 02111-1307, USA.
23 #include "context.h"
24 #include "rdb.h"
26 static struct RdbPartition table[RDB_LOCATION_LIMIT];
28 static int checksum(struct AmigaBlock *_header)
30 struct AmigaBlock *header;
31 header = malloc(512);
32 memmove(header, _header, 512);
33 int32_t *block = (int32_t *) header;
34 uint32_t i;
35 int32_t sum = 0;
36 if (header->amiga_SummedLongss > 512)
37 header->amiga_SummedLongss = 512;
38 for (i = 0; i < header->amiga_SummedLongss; i++)
39 sum += *block++;
40 free(header);
41 return sum;
44 static block_dev_desc_t *get_dev(int dev)
46 block_dev_desc_t *bdev = NULL;
47 SCAN_HANDLE hnd;
48 uint32_t blocksize;
50 hnd = get_curr_device();
51 if (open_specific_unit(hnd) &&
52 hnd->ush_device.type == DEV_TYPE_HARDDISK) {
53 bdev = malloc(sizeof(block_dev_desc_t));
54 memmove(bdev, &hnd->ush_device, sizeof(block_dev_desc_t));
55 printf("* using specific unit %d.%d\n", bdev->type, bdev->dev);
56 return bdev;
60 for (hnd = start_unit_scan(get_scan_list(), &blocksize);
61 hnd != NULL; hnd = next_unit_scan(hnd, &blocksize)) {
62 if (hnd->ush_device.type == DEV_TYPE_HARDDISK) {
63 bdev = malloc(sizeof(block_dev_desc_t));
64 memmove(bdev, &hnd->ush_device,
65 sizeof(block_dev_desc_t));
66 break;
70 end_unit_scan(hnd);
71 end_global_scan();
73 return bdev;
76 static struct RigidDiskBlock *get_rdb(block_dev_desc_t * dev_desc)
78 int i;
79 char *block_buffer = malloc(dev_desc->blksz);
81 for (i = 0; i < RDB_LOCATION_LIMIT; i++) {
82 unsigned res = dev_desc->block_read(dev_desc->dev, i, 1,
83 (unsigned *)block_buffer);
84 if (res == 1) {
85 struct RigidDiskBlock *trdb =
86 (struct RigidDiskBlock *)block_buffer;
87 if (trdb->rdb_ID == IDNAME_RIGIDDISK) {
88 if (checksum((struct AmigaBlock *)trdb) != 0)
89 continue;
90 return trdb;
94 printf("Done scanning, no RDB found\n");
95 return NULL;
98 static int get_partition_info(block_dev_desc_t * dev_desc,
99 struct RigidDiskBlock *rdb,
100 int part, disk_partition_t * info)
102 char *block_buffer;
103 struct PartitionBlock *p;
104 struct AmigaPartitionGeometry *g;
105 unsigned block, disk_type;
107 block = rdb->rdb_PartitionList;
108 block_buffer = malloc(dev_desc->blksz);
109 p = NULL;
110 while (block != 0xFFFFFFFF) {
111 if (dev_desc->block_read(dev_desc->dev, block, 1,
112 (unsigned *)block_buffer)) {
113 p = (struct PartitionBlock *)block_buffer;
114 if (p->pb_ID == IDNAME_PARTITION) {
115 if (checksum((struct AmigaBlock *)p) != 0)
116 continue;
117 if (part-- == 0)
118 break;
119 block = p->pb_Next;
120 } else
121 block = 0xFFFFFFFF;
122 p = NULL;
123 } else
124 block = 0xFFFFFFFF;
127 if (p == NULL)
128 return -1;
130 g = (struct AmigaPartitionGeometry *)&(p->pb_Environment[0]);
131 info->start = g->apg_LowCyl * g->apg_BlockPerTrack * g->apg_Surfaces;
132 info->size = (g->apg_HighCyl - g->apg_LowCyl + 1)
133 * g->apg_BlockPerTrack * g->apg_Surfaces - 1;
134 info->blksz = rdb->rdb_BlockBytes;
135 strcpy((char *)info->name, p->pb_DriveName);
137 disk_type = g->apg_DosType;
139 info->type[0] = (disk_type & 0xFF000000) >> 24;
140 info->type[1] = (disk_type & 0x00FF0000) >> 16;
141 info->type[2] = (disk_type & 0x0000FF00) >> 8;
142 info->type[3] = '\\';
143 info->type[4] = (disk_type & 0x000000FF) + '0';
144 info->type[5] = 0;
146 return 0;
149 void RdbPartitionTable_init(void)
151 block_dev_desc_t *dev_desc;
152 struct RigidDiskBlock *rdb;
153 disk_partition_t *info;
154 int i;
156 for(i = 0; i < RDB_LOCATION_LIMIT; i++)
157 table[i].name = NULL;
159 dev_desc = get_dev(0);
160 if (dev_desc == NULL) {
161 printf("** Block device not supported\n");
162 return;
165 rdb = get_rdb(dev_desc);
166 if(rdb == NULL)
167 return;
169 for(i = 0; i < RDB_LOCATION_LIMIT; i++) {
170 info = malloc(sizeof(disk_partition_t));
171 if (get_partition_info(dev_desc, rdb, i, info)) {
172 free(info);
173 continue;
175 table[i].name = (char *) info->name + 1;
176 table[i].disk = 0;
177 table[i].partition = i;
178 table[i].dev_desc = dev_desc;
179 table[i].info = info;
183 struct RdbPartition *RdbPartitionTable_get(uint8_t disk, uint8_t partition)
185 if(partition >= RDB_LOCATION_LIMIT || table[partition].name == NULL)
186 return NULL;
187 return &table[partition];
190 struct RdbPartition *RdbPartitionTable_getbyname(char *name)
192 int i;
193 for(i = 0; i < RDB_LOCATION_LIMIT && table[i].name != NULL; i++) {
194 if(strcasecmp(name, table[i].name) == 0)
195 return &table[i];
197 return NULL;
200 void RdbPartitionTable_dump(void)
202 int i;
203 for(i = 0; i < RDB_LOCATION_LIMIT && table[i].name != NULL; i++) {
204 printf("%2d. %s\n", i, table[i].name);