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 |
31 |
|
#include <linux/major.h> |
32 |
|
#include <linux/kdev_t.h> |
33 |
|
#include <linux/unistd.h> |
34 |
+ |
#include <dirent.h> |
35 |
|
|
36 |
|
#ifdef __NR__llseek |
37 |
|
_syscall5(int, _llseek, unsigned int, fd, unsigned long, hi, unsigned long, lo, loff_t *, res, unsigned int, wh); |
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 |
|
|
124 |
|
void SysAddFloppyPrefs(void) |
125 |
|
{ |
126 |
|
#if defined(__linux__) |
127 |
< |
PrefsAddString("floppy", "/dev/fd0u1440"); |
128 |
< |
PrefsAddString("floppy", "/dev/fd1u1440"); |
127 |
> |
if (access("/dev/.devfsd", F_OK) < 0) { |
128 |
> |
PrefsAddString("floppy", "/dev/fd0u1440"); |
129 |
> |
PrefsAddString("floppy", "/dev/fd1u1440"); |
130 |
> |
} else { |
131 |
> |
DIR *fd_dir = opendir("/dev/floppy"); |
132 |
> |
if (fd_dir) { |
133 |
> |
struct dirent *floppy_dev; |
134 |
> |
while ((floppy_dev = readdir(fd_dir)) != NULL) { |
135 |
> |
if (strstr(floppy_dev->d_name, "u1440") != NULL) { |
136 |
> |
char fd_dev[20]; |
137 |
> |
sprintf(fd_dev, "/dev/floppy/%s", floppy_dev->d_name); |
138 |
> |
PrefsAddString("floppy", fd_dev); |
139 |
> |
} |
140 |
> |
} |
141 |
> |
closedir(fd_dir); |
142 |
> |
} |
143 |
> |
} |
144 |
|
#elif defined(__NetBSD__) |
145 |
|
PrefsAddString("floppy", "/dev/fd0a"); |
146 |
|
PrefsAddString("floppy", "/dev/fd1a"); |
147 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
148 |
+ |
// FIXME: We assume an Aqua build causes <AvailabilityMacros.h> to |
149 |
+ |
// be included, thusly enabling this part of code that would cause |
150 |
+ |
// Basilisk II to hang otherwise. |
151 |
+ |
#ifdef MAC_OS_X_VERSION_10_0 |
152 |
+ |
PrefsAddString("floppy", "/dev/fd/0"); |
153 |
+ |
PrefsAddString("floppy", "/dev/fd/1"); |
154 |
+ |
#endif |
155 |
|
#else |
156 |
|
PrefsAddString("floppy", "/dev/fd0"); |
157 |
|
PrefsAddString("floppy", "/dev/fd1"); |
162 |
|
/* |
163 |
|
* This gets called when no "disk" prefs items are found |
164 |
|
* It scans for available HFS volumes and adds appropriate prefs items |
165 |
+ |
* On OS X, we could do the same, but on an OS X machine I think it is |
166 |
+ |
* very unlikely that any mounted volumes would contain a system which |
167 |
+ |
* is old enough to boot a 68k Mac, so we just do nothing here for now. |
168 |
|
*/ |
169 |
|
|
170 |
|
void SysAddDiskPrefs(void) |
206 |
|
return; |
207 |
|
|
208 |
|
#if defined(__linux__) |
209 |
< |
PrefsAddString("cdrom", "/dev/cdrom"); |
210 |
< |
#elif defined(__FreeBSD__) |
209 |
> |
if (access("/dev/.devfsd", F_OK) < 0) |
210 |
> |
PrefsAddString("cdrom", "/dev/cdrom"); |
211 |
> |
else { |
212 |
> |
DIR *cd_dir = opendir("/dev/cdroms"); |
213 |
> |
if (cd_dir) { |
214 |
> |
struct dirent *cdrom_dev; |
215 |
> |
while ((cdrom_dev = readdir(cd_dir)) != NULL) { |
216 |
> |
if (strcmp(cdrom_dev->d_name, ".") != 0 && strcmp(cdrom_dev->d_name, "..") != 0) { |
217 |
> |
char cd_dev[20]; |
218 |
> |
sprintf(cd_dev, "/dev/cdroms/%s", cdrom_dev->d_name); |
219 |
> |
PrefsAddString("cdrom", cd_dev); |
220 |
> |
} |
221 |
> |
} |
222 |
> |
closedir(cd_dir); |
223 |
> |
} |
224 |
> |
} |
225 |
> |
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_0) |
226 |
> |
extern void DarwinAddCDROMPrefs(void); |
227 |
> |
|
228 |
> |
DarwinAddCDROMPrefs(); |
229 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
230 |
|
PrefsAddString("cdrom", "/dev/cd0c"); |
182 |
– |
#elif defined(__NetBSD__) |
183 |
– |
PrefsAddString("cdrom", "/dev/cd0d"); |
231 |
|
#endif |
232 |
|
} |
233 |
|
|
239 |
|
void SysAddSerialPrefs(void) |
240 |
|
{ |
241 |
|
#if defined(__linux__) |
242 |
< |
PrefsAddString("seriala", "/dev/ttyS0"); |
243 |
< |
PrefsAddString("serialb", "/dev/ttyS1"); |
242 |
> |
if (access("/dev/.devfsd", F_OK) < 0) { |
243 |
> |
PrefsAddString("seriala", "/dev/ttyS0"); |
244 |
> |
PrefsAddString("serialb", "/dev/ttyS1"); |
245 |
> |
} else { |
246 |
> |
PrefsAddString("seriala", "/dev/tts/0"); |
247 |
> |
PrefsAddString("serialb", "/dev/tts/1"); |
248 |
> |
} |
249 |
|
#elif defined(__FreeBSD__) |
250 |
|
PrefsAddString("seriala", "/dev/cuaa0"); |
251 |
|
PrefsAddString("serialb", "/dev/cuaa1"); |
252 |
|
#elif defined(__NetBSD__) |
253 |
|
PrefsAddString("seriala", "/dev/tty00"); |
254 |
|
PrefsAddString("serialb", "/dev/tty01"); |
255 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
256 |
+ |
// FIXME: We assume an Aqua build causes <AvailabilityMacros.h> to |
257 |
+ |
// be included, thusly enabling this part of code that would cause |
258 |
+ |
// Basilisk II to hang otherwise. |
259 |
+ |
#ifdef MAC_OS_X_VERSION_10_0 |
260 |
+ |
PrefsAddString("seriala", "/dev/ttys0"); |
261 |
+ |
PrefsAddString("serialb", "/dev/ttys1"); |
262 |
+ |
#endif |
263 |
+ |
// PrefsAddString("seriala", "/dev/cu.modem"); |
264 |
+ |
// PrefsAddString("serialb", "/dev/cu.IrDA-IrCOMMch-b"); |
265 |
|
#endif |
266 |
|
} |
267 |
|
|
314 |
|
bool is_cdrom = strncmp(name, "/dev/cd", 7) == 0; |
315 |
|
#endif |
316 |
|
|
317 |
+ |
#if defined(__APPLE__) && defined(__MACH__) |
318 |
+ |
// |
319 |
+ |
// There is no set filename in /dev which is the cdrom, |
320 |
+ |
// so we have to see if it is any of the devices that we found earlier |
321 |
+ |
// |
322 |
+ |
const char *cdrom; |
323 |
+ |
int tmp = 0; |
324 |
+ |
|
325 |
+ |
while ( (cdrom = PrefsFindString("cdrom", tmp) ) != NULL ) |
326 |
+ |
{ |
327 |
+ |
if ( strcmp(name, cdrom) == 0 ) |
328 |
+ |
{ |
329 |
+ |
is_cdrom = 1; |
330 |
+ |
read_only = 1; |
331 |
+ |
break; |
332 |
+ |
} |
333 |
+ |
++tmp; |
334 |
+ |
} |
335 |
+ |
#endif |
336 |
+ |
|
337 |
|
D(bug("Sys_open(%s, %s)\n", name, read_only ? "read-only" : "read/write")); |
338 |
|
|
339 |
|
// Check if write access is allowed, set read-only flag if not |
416 |
|
fh->is_floppy = ((st.st_rdev >> 16) == 2); |
417 |
|
#endif |
418 |
|
} |
419 |
+ |
#if defined(__APPLE__) && defined(__MACH__) |
420 |
+ |
|
421 |
+ |
// In OS X, the device name is OK for sending ioctls to, |
422 |
+ |
// but not for reading raw CDROM data from. |
423 |
+ |
// (it seems to have extra data padded in) |
424 |
+ |
// |
425 |
+ |
// So, we keep the already opened fiole handle, |
426 |
+ |
// and open a slightly different file for CDROM data |
427 |
+ |
// |
428 |
+ |
if ( is_cdrom ) |
429 |
+ |
{ |
430 |
+ |
fh->ioctl_name = fh->name; |
431 |
+ |
fh->ioctl_fd = fh->fd; |
432 |
+ |
|
433 |
+ |
fh->name = (char *) malloc(strlen(name) + 2); |
434 |
+ |
if ( fh->name ) |
435 |
+ |
{ |
436 |
+ |
*fh->name = '\0'; |
437 |
+ |
strcat(fh->name, name); |
438 |
+ |
strcat(fh->name, "s1"); |
439 |
+ |
fh->fd = open(fh->name, (read_only ? O_RDONLY : O_RDWR)); |
440 |
+ |
if ( fh->fd < 0 ) { |
441 |
+ |
printf("WARNING: Cannot open %s (%s)\n", |
442 |
+ |
fh->name, strerror(errno)); |
443 |
+ |
return NULL; |
444 |
+ |
} |
445 |
+ |
} |
446 |
+ |
} |
447 |
+ |
#endif |
448 |
|
} |
449 |
|
} |
450 |
|
if (fh->is_floppy && first_floppy == NULL) |
582 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
583 |
|
fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK); |
584 |
|
} |
585 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) |
586 |
+ |
if ( fh->is_cdrom ) { |
587 |
+ |
|
588 |
+ |
// Stolen from IOKit/storage/IOMediaBSDClient.h |
589 |
+ |
#define DKIOCEJECT _IO('d', 21) |
590 |
+ |
|
591 |
+ |
close(fh->fd); |
592 |
+ |
if ( ioctl(fh->ioctl_fd, DKIOCEJECT) < 0 ) |
593 |
+ |
{ |
594 |
+ |
printf("ioctl(DKIOCEJECT) failed on file %s: %s\n", |
595 |
+ |
fh->ioctl_name, strerror(errno)); |
596 |
+ |
|
597 |
+ |
// If we are running OSX, the device may be is busy |
598 |
+ |
// due to the Finder having the disk mounted and open, |
599 |
+ |
// so we have to use another method. |
600 |
+ |
|
601 |
+ |
// The only problem is that this takes about 5 seconds: |
602 |
+ |
|
603 |
+ |
char *cmd = (char *) malloc(30+sizeof(fh->name)); |
604 |
+ |
|
605 |
+ |
if ( ! cmd ) |
606 |
+ |
return; |
607 |
+ |
close(fh->ioctl_fd); |
608 |
+ |
sprintf(cmd, "diskutil eject %s 2>&1 >/dev/null", fh->name); |
609 |
+ |
system(cmd); |
610 |
+ |
} |
611 |
+ |
} |
612 |
|
#endif |
613 |
|
} |
614 |
|
|
815 |
|
*toc++ = toc_size >> 8; |
816 |
|
*toc++ = toc_size & 0xff; |
817 |
|
return true; |
818 |
+ |
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_2) |
819 |
+ |
extern bool DarwinCDReadTOC(char *name, uint8 *toc); |
820 |
+ |
|
821 |
+ |
return DarwinCDReadTOC(fh->name, toc); |
822 |
|
#elif defined(__FreeBSD__) |
823 |
|
uint8 *p = toc + 2; |
824 |
|
|
889 |
|
*toc++ = toc_size >> 8; |
890 |
|
*toc++ = toc_size & 0xff; |
891 |
|
return true; |
892 |
+ |
#else |
893 |
+ |
return false; |
894 |
|
#endif |
895 |
|
} else |
896 |
|
return false; |
954 |
|
*pos++ = chan.data->what.position.reladdr.msf.second; |
955 |
|
*pos++ = chan.data->what.position.reladdr.msf.frame; |
956 |
|
return true; |
957 |
+ |
#else |
958 |
+ |
return false; |
959 |
|
#endif |
960 |
|
} else |
961 |
|
return false; |
991 |
|
play.end_s = end_s; |
992 |
|
play.end_f = end_f; |
993 |
|
return ioctl(fh->fd, CDIOCPLAYMSF, &play) == 0; |
994 |
+ |
#else |
995 |
+ |
return false; |
996 |
|
#endif |
997 |
|
} else |
998 |
|
return false; |
1014 |
|
return ioctl(fh->fd, CDROMPAUSE) == 0; |
1015 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
1016 |
|
return ioctl(fh->fd, CDIOCPAUSE) == 0; |
1017 |
+ |
#else |
1018 |
+ |
return false; |
1019 |
|
#endif |
1020 |
|
} else |
1021 |
|
return false; |
1037 |
|
return ioctl(fh->fd, CDROMRESUME) == 0; |
1038 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
1039 |
|
return ioctl(fh->fd, CDIOCRESUME) == 0; |
1040 |
+ |
#else |
1041 |
+ |
return false; |
1042 |
|
#endif |
1043 |
|
} else |
1044 |
|
return false; |
1060 |
|
return ioctl(fh->fd, CDROMSTOP) == 0; |
1061 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
1062 |
|
return ioctl(fh->fd, CDIOCSTOP) == 0; |
1063 |
+ |
#else |
1064 |
+ |
return false; |
1065 |
|
#endif |
1066 |
|
} else |
1067 |
|
return false; |