1 |
|
/* |
2 |
|
* sys_unix.cpp - System dependent routines, Unix implementation |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2003 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2005 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 |
24 |
|
#include <sys/stat.h> |
25 |
|
#include <errno.h> |
26 |
|
|
27 |
+ |
#ifdef HAVE_AVAILABILITYMACROS_H |
28 |
+ |
#include <AvailabilityMacros.h> |
29 |
+ |
#endif |
30 |
+ |
|
31 |
|
#ifdef __linux__ |
32 |
|
#include <sys/mount.h> |
33 |
|
#include <linux/cdrom.h> |
34 |
|
#include <linux/fd.h> |
35 |
|
#include <linux/major.h> |
36 |
|
#include <linux/kdev_t.h> |
33 |
– |
#include <linux/unistd.h> |
37 |
|
#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); |
38 |
– |
#else |
39 |
– |
static int _llseek(unsigned int fd, unsigned long hi, unsigned long lo, loff_t *res, unsigned int wh) |
40 |
– |
{ |
41 |
– |
if (hi) |
42 |
– |
return -1; |
43 |
– |
*res = lseek(fd, lo, wh); |
44 |
– |
if (*res == -1) |
45 |
– |
return -1; |
46 |
– |
return 0; |
47 |
– |
} |
48 |
– |
#endif |
38 |
|
#endif |
39 |
|
|
40 |
|
#if defined(__FreeBSD__) || defined(__NetBSD__) |
134 |
|
PrefsAddString("floppy", "/dev/fd0a"); |
135 |
|
PrefsAddString("floppy", "/dev/fd1a"); |
136 |
|
#elif defined(__APPLE__) && defined(__MACH__) |
137 |
< |
PrefsAddString("floppy", "/dev/fd/0"); |
138 |
< |
PrefsAddString("floppy", "/dev/fd/1"); |
137 |
> |
#if defined(AQUA) || defined(HAVE_FRAMEWORK_COREFOUNDATION) |
138 |
> |
extern void DarwinAddFloppyPrefs(void); |
139 |
> |
|
140 |
> |
DarwinAddFloppyPrefs(); |
141 |
> |
#else |
142 |
> |
// Until I can convince the other guys that my Darwin code is useful, |
143 |
> |
// we just add something safe (a non-existant device): |
144 |
> |
PrefsAddString("floppy", "/dev/null"); |
145 |
> |
#endif |
146 |
|
#else |
147 |
|
PrefsAddString("floppy", "/dev/fd0"); |
148 |
|
PrefsAddString("floppy", "/dev/fd1"); |
214 |
|
} |
215 |
|
} |
216 |
|
#elif defined(__APPLE__) && defined(__MACH__) |
217 |
+ |
#if defined(AQUA) || defined(HAVE_FRAMEWORK_COREFOUNDATION) |
218 |
|
extern void DarwinAddCDROMPrefs(void); |
219 |
|
|
220 |
|
DarwinAddCDROMPrefs(); |
221 |
+ |
#else |
222 |
+ |
// Until I can convince the other guys that my Darwin code is useful, |
223 |
+ |
// we just do nothing (it is safe to have no cdrom device) |
224 |
+ |
#endif |
225 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
226 |
|
PrefsAddString("cdrom", "/dev/cd0c"); |
227 |
|
#endif |
249 |
|
PrefsAddString("seriala", "/dev/tty00"); |
250 |
|
PrefsAddString("serialb", "/dev/tty01"); |
251 |
|
#elif defined(__APPLE__) && defined(__MACH__) |
252 |
< |
PrefsAddString("seriala", "/dev/ttys0"); |
253 |
< |
PrefsAddString("serialb", "/dev/ttys1"); |
254 |
< |
// PrefsAddString("seriala", "/dev/cu.modem"); |
255 |
< |
// PrefsAddString("serialb", "/dev/cu.IrDA-IrCOMMch-b"); |
252 |
> |
#if defined(AQUA) || defined(HAVE_FRAMEWORK_COREFOUNDATION) |
253 |
> |
extern void DarwinAddSerialPrefs(void); |
254 |
> |
|
255 |
> |
DarwinAddSerialPrefs(); |
256 |
> |
#else |
257 |
> |
// Until I can convince the other guys that my Darwin code is useful, |
258 |
> |
// we just add something safe (non-existant devices): |
259 |
> |
PrefsAddString("seriala", "/dev/null"); |
260 |
> |
PrefsAddString("serialb", "/dev/null"); |
261 |
> |
#endif |
262 |
|
#endif |
263 |
|
} |
264 |
|
|
374 |
|
if (fh->is_file) { |
375 |
|
// Detect disk image file layout |
376 |
|
loff_t size = 0; |
370 |
– |
#if defined(__linux__) |
371 |
– |
_llseek(fh->fd, 0, 0, &size, SEEK_END); |
372 |
– |
#else |
377 |
|
size = lseek(fd, 0, SEEK_END); |
374 |
– |
#endif |
378 |
|
uint8 data[256]; |
379 |
|
lseek(fd, 0, SEEK_SET); |
380 |
|
read(fd, data, 256); |
479 |
|
return 0; |
480 |
|
|
481 |
|
// Seek to position |
479 |
– |
#if defined(__linux__) |
480 |
– |
loff_t pos = offset + fh->start_byte, res; |
481 |
– |
if (_llseek(fh->fd, pos >> 32, pos, &res, SEEK_SET) < 0) |
482 |
– |
return 0; |
483 |
– |
#else |
482 |
|
if (lseek(fh->fd, offset + fh->start_byte, SEEK_SET) < 0) |
483 |
|
return 0; |
486 |
– |
#endif |
484 |
|
|
485 |
|
// Read data |
486 |
|
return read(fh->fd, buffer, length); |
499 |
|
return 0; |
500 |
|
|
501 |
|
// Seek to position |
505 |
– |
#if defined(__linux__) |
506 |
– |
loff_t pos = offset + fh->start_byte, res; |
507 |
– |
if (_llseek(fh->fd, pos >> 32, pos, &res, SEEK_SET) < 0) |
508 |
– |
return 0; |
509 |
– |
#else |
502 |
|
if (lseek(fh->fd, offset + fh->start_byte, SEEK_SET) < 0) |
503 |
|
return 0; |
512 |
– |
#endif |
504 |
|
|
505 |
|
// Write data |
506 |
|
return write(fh->fd, buffer, length); |
796 |
|
*toc++ = toc_size >> 8; |
797 |
|
*toc++ = toc_size & 0xff; |
798 |
|
return true; |
799 |
< |
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_2) |
799 |
> |
#elif defined(__APPLE__) && defined(__MACH__) && defined(MAC_OS_X_VERSION_10_2) && defined(HAVE_FRAMEWORK_COREFOUNDATION) |
800 |
|
extern bool DarwinCDReadTOC(char *name, uint8 *toc); |
801 |
|
|
802 |
|
return DarwinCDReadTOC(fh->name, toc); |