1 |
|
/* |
2 |
|
* sys_unix.cpp - System dependent routines, Unix implementation |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2002 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 |
25 |
|
#include <errno.h> |
26 |
|
|
27 |
|
#ifdef __linux__ |
28 |
+ |
#include <sys/mount.h> |
29 |
|
#include <linux/cdrom.h> |
30 |
|
#include <linux/fd.h> |
30 |
– |
#include <linux/fs.h> |
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, uint, fd, ulong, hi, ulong, lo, loff_t *, res, uint, wh); |
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(uint fd, ulong hi, ulong lo, loff_t *res, uint wh) |
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; |
121 |
|
void SysAddFloppyPrefs(void) |
122 |
|
{ |
123 |
|
#if defined(__linux__) |
124 |
< |
PrefsAddString("floppy", "/dev/fd0H1440"); |
125 |
< |
PrefsAddString("floppy", "/dev/fd1H1440"); |
124 |
> |
if (access("/dev/.devfsd", F_OK) < 0) { |
125 |
> |
PrefsAddString("floppy", "/dev/fd0u1440"); |
126 |
> |
PrefsAddString("floppy", "/dev/fd1u1440"); |
127 |
> |
} else { |
128 |
> |
DIR *fd_dir = opendir("/dev/floppy"); |
129 |
> |
if (fd_dir) { |
130 |
> |
struct dirent *floppy_dev; |
131 |
> |
while ((floppy_dev = readdir(fd_dir)) != NULL) { |
132 |
> |
if (strstr(floppy_dev->d_name, "u1440") != NULL) { |
133 |
> |
char fd_dev[20]; |
134 |
> |
sprintf(fd_dev, "/dev/floppy/%s", floppy_dev->d_name); |
135 |
> |
PrefsAddString("floppy", fd_dev); |
136 |
> |
} |
137 |
> |
} |
138 |
> |
closedir(fd_dir); |
139 |
> |
} |
140 |
> |
} |
141 |
|
#elif defined(__NetBSD__) |
142 |
|
PrefsAddString("floppy", "/dev/fd0a"); |
143 |
|
PrefsAddString("floppy", "/dev/fd1a"); |
162 |
|
while(fgets(line, 255, f)) { |
163 |
|
// Read line |
164 |
|
int len = strlen(line); |
165 |
< |
if (len == 0) |
165 |
> |
if (len == 0 || line[0] == '#') |
166 |
|
continue; |
167 |
|
line[len-1] = 0; |
168 |
|
|
192 |
|
return; |
193 |
|
|
194 |
|
#if defined(__linux__) |
195 |
< |
PrefsAddString("cdrom", "/dev/cdrom"); |
196 |
< |
#elif defined(__FreeBSD__) |
195 |
> |
if (access("/dev/.devfsd", F_OK) < 0) |
196 |
> |
PrefsAddString("cdrom", "/dev/cdrom"); |
197 |
> |
else { |
198 |
> |
DIR *cd_dir = opendir("/dev/cdroms"); |
199 |
> |
if (cd_dir) { |
200 |
> |
struct dirent *cdrom_dev; |
201 |
> |
while ((cdrom_dev = readdir(cd_dir)) != NULL) { |
202 |
> |
if (strcmp(cdrom_dev->d_name, ".") != 0 && strcmp(cdrom_dev->d_name, "..") != 0) { |
203 |
> |
char cd_dev[20]; |
204 |
> |
sprintf(cd_dev, "/dev/cdroms/%s", cdrom_dev->d_name); |
205 |
> |
PrefsAddString("cdrom", cd_dev); |
206 |
> |
} |
207 |
> |
} |
208 |
> |
closedir(cd_dir); |
209 |
> |
} |
210 |
> |
} |
211 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
212 |
|
PrefsAddString("cdrom", "/dev/cd0c"); |
182 |
– |
#elif defined(__NetBSD__) |
183 |
– |
PrefsAddString("cdrom", "/dev/cd0d"); |
213 |
|
#endif |
214 |
|
} |
215 |
|
|
221 |
|
void SysAddSerialPrefs(void) |
222 |
|
{ |
223 |
|
#if defined(__linux__) |
224 |
< |
PrefsAddString("seriala", "/dev/ttyS0"); |
225 |
< |
PrefsAddString("serialb", "/dev/ttyS1"); |
224 |
> |
if (access("/dev/.devfsd", F_OK) < 0) { |
225 |
> |
PrefsAddString("seriala", "/dev/ttyS0"); |
226 |
> |
PrefsAddString("serialb", "/dev/ttyS1"); |
227 |
> |
} else { |
228 |
> |
PrefsAddString("seriala", "/dev/tts/0"); |
229 |
> |
PrefsAddString("serialb", "/dev/tts/1"); |
230 |
> |
} |
231 |
|
#elif defined(__FreeBSD__) |
232 |
|
PrefsAddString("seriala", "/dev/cuaa0"); |
233 |
|
PrefsAddString("serialb", "/dev/cuaa1"); |
307 |
|
} |
308 |
|
|
309 |
|
// Open file/device |
310 |
< |
#if defined(__linux__) |
310 |
> |
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) |
311 |
|
int fd = open(name, (read_only ? O_RDONLY : O_RDWR) | (is_cdrom ? O_NONBLOCK : 0)); |
312 |
|
#else |
313 |
|
int fd = open(name, read_only ? O_RDONLY : O_RDWR); |
490 |
|
fsync(fh->fd); |
491 |
|
ioctl(fh->fd, FDFLUSH); |
492 |
|
ioctl(fh->fd, FDEJECT); |
493 |
+ |
close(fh->fd); // Close and reopen so the driver will see the media change |
494 |
+ |
fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR); |
495 |
|
} else if (fh->is_cdrom) { |
496 |
|
ioctl(fh->fd, CDROMEJECT); |
497 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
500 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
501 |
|
if (fh->is_floppy) { |
502 |
|
fsync(fh->fd); |
467 |
– |
//ioctl(fh->fd, FDFLUSH); |
468 |
– |
//ioctl(fh->fd, FDEJECT); |
503 |
|
} else if (fh->is_cdrom) { |
504 |
|
ioctl(fh->fd, CDIOCEJECT); |
505 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
581 |
|
} else if (fh->is_floppy) { |
582 |
|
char block[512]; |
583 |
|
lseek(fh->fd, 0, SEEK_SET); |
584 |
< |
return read(fh->fd, block, 512) == 512; |
584 |
> |
ssize_t actual = read(fh->fd, block, 512); |
585 |
> |
if (actual < 0) { |
586 |
> |
close(fh->fd); // Close and reopen so the driver will see the media change |
587 |
> |
fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR); |
588 |
> |
actual = read(fh->fd, block, 512); |
589 |
> |
} |
590 |
> |
return actual == 512; |
591 |
|
} else if (fh->is_cdrom) { |
592 |
+ |
#ifdef CDROM_MEDIA_CHANGED |
593 |
+ |
if (fh->cdrom_cap & CDC_MEDIA_CHANGED) { |
594 |
+ |
// If we don't do this, all attempts to read from a disc fail |
595 |
+ |
// once the tray has been opened (altough the TOC reads fine). |
596 |
+ |
// Can somebody explain this to me? |
597 |
+ |
if (ioctl(fh->fd, CDROM_MEDIA_CHANGED) == 1) { |
598 |
+ |
close(fh->fd); |
599 |
+ |
fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK); |
600 |
+ |
} |
601 |
+ |
} |
602 |
+ |
#endif |
603 |
|
#ifdef CDROM_DRIVE_STATUS |
604 |
|
if (fh->cdrom_cap & CDC_DRIVE_STATUS) { |
605 |
|
return ioctl(fh->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) == CDS_DISC_OK; |
781 |
|
*toc++ = toc_size >> 8; |
782 |
|
*toc++ = toc_size & 0xff; |
783 |
|
return true; |
784 |
+ |
#else |
785 |
+ |
return false; |
786 |
|
#endif |
787 |
|
} else |
788 |
|
return false; |
846 |
|
*pos++ = chan.data->what.position.reladdr.msf.second; |
847 |
|
*pos++ = chan.data->what.position.reladdr.msf.frame; |
848 |
|
return true; |
849 |
+ |
#else |
850 |
+ |
return false; |
851 |
|
#endif |
852 |
|
} else |
853 |
|
return false; |
883 |
|
play.end_s = end_s; |
884 |
|
play.end_f = end_f; |
885 |
|
return ioctl(fh->fd, CDIOCPLAYMSF, &play) == 0; |
886 |
+ |
#else |
887 |
+ |
return false; |
888 |
|
#endif |
889 |
|
} else |
890 |
|
return false; |
906 |
|
return ioctl(fh->fd, CDROMPAUSE) == 0; |
907 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
908 |
|
return ioctl(fh->fd, CDIOCPAUSE) == 0; |
909 |
+ |
#else |
910 |
+ |
return false; |
911 |
|
#endif |
912 |
|
} else |
913 |
|
return false; |
929 |
|
return ioctl(fh->fd, CDROMRESUME) == 0; |
930 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
931 |
|
return ioctl(fh->fd, CDIOCRESUME) == 0; |
932 |
+ |
#else |
933 |
+ |
return false; |
934 |
|
#endif |
935 |
|
} else |
936 |
|
return false; |
952 |
|
return ioctl(fh->fd, CDROMSTOP) == 0; |
953 |
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
954 |
|
return ioctl(fh->fd, CDIOCSTOP) == 0; |
955 |
+ |
#else |
956 |
+ |
return false; |
957 |
|
#endif |
958 |
|
} else |
959 |
|
return false; |