71 |
|
|
72 |
|
// Struct for each drive |
73 |
|
struct disk_drive_info { |
74 |
< |
disk_drive_info() : num(0), fh(NULL), read_only(false), status(0) {} |
74 |
> |
disk_drive_info() : num(0), fh(NULL), start_byte(0), read_only(false), status(0) {} |
75 |
|
disk_drive_info(void *fh_, bool ro) : num(0), fh(fh_), read_only(ro), status(0) {} |
76 |
|
|
77 |
|
void close_fh(void) { Sys_close(fh); } |
78 |
|
|
79 |
|
int num; // Drive number |
80 |
|
void *fh; // File handle |
81 |
+ |
loff_t start_byte; // Start of HFS partition on disk |
82 |
|
uint32 num_blocks; // Size in 512-byte blocks |
83 |
|
bool to_be_mounted; // Flag: drive must be mounted in accRun |
84 |
|
bool read_only; // Flag: force write protection |
112 |
|
|
113 |
|
|
114 |
|
/* |
115 |
+ |
* Find HFS partition, set info->start_byte and info->num_blocks |
116 |
+ |
* (0 = no partition map or HFS partition found, assume flat disk image) |
117 |
+ |
*/ |
118 |
+ |
|
119 |
+ |
static void find_hfs_partition(disk_drive_info &info) |
120 |
+ |
{ |
121 |
+ |
info.start_byte = 0; |
122 |
+ |
info.num_blocks = 0; |
123 |
+ |
uint8 *map = new uint8[512]; |
124 |
+ |
|
125 |
+ |
// Search first 64 blocks for HFS partition |
126 |
+ |
for (int i=0; i<64; i++) { |
127 |
+ |
if (Sys_read(info.fh, map, i * 512, 512) != 512) |
128 |
+ |
break; |
129 |
+ |
|
130 |
+ |
// Not a partition map block? Then look at next block |
131 |
+ |
uint16 sig = (map[0] << 8) | map[1]; |
132 |
+ |
if (sig != 0x504d) |
133 |
+ |
continue; |
134 |
+ |
|
135 |
+ |
// Partition map block found, Apple HFS partition? |
136 |
+ |
if (strcmp((char *)(map + 48), "Apple_HFS") == 0) { |
137 |
+ |
info.start_byte = ntohl(((uint32 *)map)[2]) << 9; |
138 |
+ |
info.num_blocks = ntohl(((uint32 *)map)[3]); |
139 |
+ |
D(bug(" HFS partition found at %d, %d blocks\n", info.start_byte, info.num_blocks)); |
140 |
+ |
break; |
141 |
+ |
} |
142 |
+ |
} |
143 |
+ |
delete[] map; |
144 |
+ |
} |
145 |
+ |
|
146 |
+ |
|
147 |
+ |
/* |
148 |
|
* Initialization |
149 |
|
*/ |
150 |
|
|
197 |
|
info->read_only = SysIsReadOnly(info->fh); |
198 |
|
WriteMacInt8(info->status + dsDiskInPlace, 1); // Inserted removable disk |
199 |
|
WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0xff : 0); |
200 |
< |
info->num_blocks = SysGetFileSize(info->fh) / 512; |
200 |
> |
find_hfs_partition(*info); |
201 |
> |
if (info->start_byte == 0) |
202 |
> |
info->num_blocks = SysGetFileSize(info->fh) / 512; |
203 |
|
WriteMacInt16(info->status + dsDriveSize, info->num_blocks & 0xffff); |
204 |
|
WriteMacInt16(info->status + dsDriveS1, info->num_blocks >> 16); |
205 |
|
info->to_be_mounted = true; |
285 |
|
if (disk_in_place) { |
286 |
|
D(bug(" disk inserted\n")); |
287 |
|
WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0x80 : 0); |
288 |
< |
info->num_blocks = SysGetFileSize(info->fh) / 512; |
288 |
> |
find_hfs_partition(*info); |
289 |
> |
if (info->start_byte == 0) |
290 |
> |
info->num_blocks = SysGetFileSize(info->fh) / 512; |
291 |
|
info->to_be_mounted = true; |
292 |
|
} |
293 |
|
D(bug(" %d blocks\n", info->num_blocks)); |
333 |
|
if ((ReadMacInt16(pb + ioTrap) & 0xff) == aRdCmd) { |
334 |
|
|
335 |
|
// Read |
336 |
< |
actual = Sys_read(info->fh, buffer, position, length); |
336 |
> |
actual = Sys_read(info->fh, buffer, position + info->start_byte, length); |
337 |
|
if (actual != length) |
338 |
|
return readErr; |
339 |
|
|
342 |
|
// Write |
343 |
|
if (info->read_only) |
344 |
|
return wPrErr; |
345 |
< |
actual = Sys_write(info->fh, buffer, position, length); |
345 |
> |
actual = Sys_write(info->fh, buffer, position + info->start_byte, length); |
346 |
|
if (actual != length) |
347 |
|
return writErr; |
348 |
|
} |