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