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.
26 static struct RdbPartition table
[RDB_LOCATION_LIMIT
];
28 static int checksum(struct AmigaBlock
*_header
)
30 struct AmigaBlock
*header
;
32 memmove(header
, _header
, 512);
33 int32_t *block
= (int32_t *) header
;
36 if (header
->amiga_SummedLongss
> 512)
37 header
->amiga_SummedLongss
= 512;
38 for (i
= 0; i
< header
->amiga_SummedLongss
; i
++)
44 static block_dev_desc_t
*get_dev(int dev
)
46 block_dev_desc_t
*bdev
= NULL
;
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
);
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
));
76 static struct RigidDiskBlock
*get_rdb(block_dev_desc_t
* dev_desc
)
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
);
85 struct RigidDiskBlock
*trdb
=
86 (struct RigidDiskBlock
*)block_buffer
;
87 if (trdb
->rdb_ID
== IDNAME_RIGIDDISK
) {
88 if (checksum((struct AmigaBlock
*)trdb
) != 0)
94 printf("Done scanning, no RDB found\n");
98 static int get_partition_info(block_dev_desc_t
* dev_desc
,
99 struct RigidDiskBlock
*rdb
,
100 int part
, disk_partition_t
* info
)
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
);
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)
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';
149 void RdbPartitionTable_init(void)
151 block_dev_desc_t
*dev_desc
;
152 struct RigidDiskBlock
*rdb
;
153 disk_partition_t
*info
;
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");
165 rdb
= get_rdb(dev_desc
);
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
)) {
175 table
[i
].name
= (char *) info
->name
+ 1;
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
)
187 return &table
[partition
];
190 struct RdbPartition
*RdbPartitionTable_getbyname(char *name
)
193 for(i
= 0; i
< RDB_LOCATION_LIMIT
&& table
[i
].name
!= NULL
; i
++) {
194 if(strcasecmp(name
, table
[i
].name
) == 0)
200 void RdbPartitionTable_dump(void)
203 for(i
= 0; i
< RDB_LOCATION_LIMIT
&& table
[i
].name
!= NULL
; i
++) {
204 printf("%2d. %s\n", i
, table
[i
].name
);