1 |
|
/* |
2 |
|
* sys_unix.cpp - System dependent routines, Unix implementation |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2002 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2003 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
77 |
|
int cdrom_cap; // CD-ROM capability flags (only valid if is_cdrom is true) |
78 |
|
#elif defined(__FreeBSD__) |
79 |
|
struct ioc_capability cdrom_cap; |
80 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
81 |
+ |
char *ioctl_name; // For CDs on OS X - a device for special ioctls |
82 |
+ |
int ioctl_fd; |
83 |
|
#endif |
84 |
|
}; |
85 |
|
|
144 |
|
#elif defined(__NetBSD__) |
145 |
|
PrefsAddString("floppy", "/dev/fd0a"); |
146 |
|
PrefsAddString("floppy", "/dev/fd1a"); |
147 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
148 |
+ |
PrefsAddString("floppy", "/dev/fd/0"); |
149 |
+ |
PrefsAddString("floppy", "/dev/fd/1"); |
150 |
|
#else |
151 |
|
PrefsAddString("floppy", "/dev/fd0"); |
152 |
|
PrefsAddString("floppy", "/dev/fd1"); |
157 |
|
/* |
158 |
|
* This gets called when no "disk" prefs items are found |
159 |
|
* It scans for available HFS volumes and adds appropriate prefs items |
160 |
+ |
* On OS X, we could do the same, but on an OS X machine I think it is |
161 |
+ |
* very unlikely that any mounted volumes would contain a system which |
162 |
+ |
* is old enough to boot a 68k Mac, so we just do nothing here for now. |
163 |
|
*/ |
164 |
|
|
165 |
|
void SysAddDiskPrefs(void) |
217 |
|
closedir(cd_dir); |
218 |
|
} |
219 |
|
} |
220 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
221 |
+ |
extern void DarwinAddCDROMPrefs(void); |
222 |
+ |
|
223 |
+ |
DarwinAddCDROMPrefs(); |
224 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
225 |
|
PrefsAddString("cdrom", "/dev/cd0c"); |
226 |
|
#endif |
247 |
|
#elif defined(__NetBSD__) |
248 |
|
PrefsAddString("seriala", "/dev/tty00"); |
249 |
|
PrefsAddString("serialb", "/dev/tty01"); |
250 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
251 |
+ |
PrefsAddString("seriala", "/dev/ttys0"); |
252 |
+ |
PrefsAddString("serialb", "/dev/ttys1"); |
253 |
+ |
// PrefsAddString("seriala", "/dev/cu.modem"); |
254 |
+ |
// PrefsAddString("serialb", "/dev/cu.IrDA-IrCOMMch-b"); |
255 |
|
#endif |
256 |
|
} |
257 |
|
|
304 |
|
bool is_cdrom = strncmp(name, "/dev/cd", 7) == 0; |
305 |
|
#endif |
306 |
|
|
307 |
+ |
#if defined(__APPLE__) && defined(__MACH__) |
308 |
+ |
// |
309 |
+ |
// There is no set filename in /dev which is the cdrom, |
310 |
+ |
// so we have to see if it is any of the devices that we found earlier |
311 |
+ |
// |
312 |
+ |
const char *cdrom; |
313 |
+ |
int tmp = 0; |
314 |
+ |
|
315 |
+ |
while ( (cdrom = PrefsFindString("cdrom", tmp) ) != NULL ) |
316 |
+ |
{ |
317 |
+ |
if ( strcmp(name, cdrom) == 0 ) |
318 |
+ |
{ |
319 |
+ |
is_cdrom = 1; |
320 |
+ |
read_only = 1; |
321 |
+ |
break; |
322 |
+ |
} |
323 |
+ |
++tmp; |
324 |
+ |
} |
325 |
+ |
#endif |
326 |
+ |
|
327 |
|
D(bug("Sys_open(%s, %s)\n", name, read_only ? "read-only" : "read/write")); |
328 |
|
|
329 |
|
// Check if write access is allowed, set read-only flag if not |
406 |
|
fh->is_floppy = ((st.st_rdev >> 16) == 2); |
407 |
|
#endif |
408 |
|
} |
409 |
+ |
#if defined(__APPLE__) && defined(__MACH__) |
410 |
+ |
|
411 |
+ |
// In OS X, the device name is OK for sending ioctls to, |
412 |
+ |
// but not for reading raw CDROM data from. |
413 |
+ |
// (it seems to have extra data padded in) |
414 |
+ |
// |
415 |
+ |
// So, we keep the already opened fiole handle, |
416 |
+ |
// and open a slightly different file for CDROM data |
417 |
+ |
// |
418 |
+ |
if ( is_cdrom ) |
419 |
+ |
{ |
420 |
+ |
fh->ioctl_name = fh->name; |
421 |
+ |
fh->ioctl_fd = fh->fd; |
422 |
+ |
|
423 |
+ |
fh->name = (char *) malloc(strlen(name) + 2); |
424 |
+ |
if ( fh->name ) |
425 |
+ |
{ |
426 |
+ |
*fh->name = '\0'; |
427 |
+ |
strcat(fh->name, name); |
428 |
+ |
strcat(fh->name, "s1"); |
429 |
+ |
fh->fd = open(fh->name, (read_only ? O_RDONLY : O_RDWR)); |
430 |
+ |
if ( fh->fd < 0 ) { |
431 |
+ |
printf("WARNING: Cannot open %s (%s)\n", |
432 |
+ |
fh->name, strerror(errno)); |
433 |
+ |
return NULL; |
434 |
+ |
} |
435 |
+ |
} |
436 |
+ |
} |
437 |
+ |
#endif |
438 |
|
} |
439 |
|
} |
440 |
|
if (fh->is_floppy && first_floppy == NULL) |
572 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
573 |
|
fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK); |
574 |
|
} |
575 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
576 |
+ |
if ( fh->is_cdrom ) { |
577 |
+ |
|
578 |
+ |
// Stolen from IOKit/storage/IOMediaBSDClient.h |
579 |
+ |
#define DKIOCEJECT _IO('d', 21) |
580 |
+ |
|
581 |
+ |
close(fh->fd); |
582 |
+ |
if ( ioctl(fh->ioctl_fd, DKIOCEJECT) < 0 ) |
583 |
+ |
{ |
584 |
+ |
printf("ioctl(DKIOCEJECT) failed on file %s: %s\n", |
585 |
+ |
fh->ioctl_name, strerror(errno)); |
586 |
+ |
|
587 |
+ |
// If we are running OSX, the device may be is busy |
588 |
+ |
// due to the Finder having the disk mounted and open, |
589 |
+ |
// so we have to use another method. |
590 |
+ |
|
591 |
+ |
// The only problem is that this takes about 5 seconds: |
592 |
+ |
|
593 |
+ |
char *cmd = (char *) malloc(30+sizeof(fh->name)); |
594 |
+ |
|
595 |
+ |
if ( ! cmd ) |
596 |
+ |
return; |
597 |
+ |
close(fh->ioctl_fd); |
598 |
+ |
sprintf(cmd, "diskutil eject %s 2>&1 >/dev/null", fh->name); |
599 |
+ |
system(cmd); |
600 |
+ |
} |
601 |
+ |
} |
602 |
|
#endif |
603 |
|
} |
604 |
|
|
805 |
|
*toc++ = toc_size >> 8; |
806 |
|
*toc++ = toc_size & 0xff; |
807 |
|
return true; |
808 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_2) |
809 |
+ |
extern bool DarwinCDReadTOC(char *name, uint8 *toc); |
810 |
+ |
|
811 |
+ |
return DarwinCDReadTOC(fh->name, toc); |
812 |
|
#elif defined(__FreeBSD__) |
813 |
|
uint8 *p = toc + 2; |
814 |
|
|