25 |
|
#include <errno.h> |
26 |
|
|
27 |
|
#ifdef __linux__ |
28 |
+ |
#include <sys/mount.h> |
29 |
|
#include <linux/cdrom.h> |
30 |
|
#include <linux/fd.h> |
31 |
|
#include <linux/major.h> |
47 |
|
#endif |
48 |
|
#endif |
49 |
|
|
50 |
< |
#ifdef __FreeBSD__ |
50 |
> |
#if defined(__FreeBSD__) || defined(__NetBSD__) |
51 |
|
#include <sys/cdio.h> |
52 |
|
#endif |
53 |
|
|
122 |
|
#if defined(__linux__) |
123 |
|
PrefsAddString("floppy", "/dev/fd0H1440"); |
124 |
|
PrefsAddString("floppy", "/dev/fd1H1440"); |
125 |
+ |
#elif defined(__NetBSD__) |
126 |
+ |
PrefsAddString("floppy", "/dev/fd0a"); |
127 |
+ |
PrefsAddString("floppy", "/dev/fd1a"); |
128 |
|
#else |
129 |
|
PrefsAddString("floppy", "/dev/fd0"); |
130 |
|
PrefsAddString("floppy", "/dev/fd1"); |
152 |
|
|
153 |
|
// Parse line |
154 |
|
char *dev, *mnt_point, *fstype; |
155 |
< |
if (sscanf(line, "%s %s %s", &dev, &mnt_point, &fstype) == 3) { |
155 |
> |
if (sscanf(line, "%as %as %as", &dev, &mnt_point, &fstype) == 3) { |
156 |
|
if (strcmp(fstype, "hfs") == 0) |
157 |
|
PrefsAddString("disk", dev); |
158 |
|
} |
159 |
+ |
free(dev); free(mnt_point); free(fstype); |
160 |
|
} |
161 |
|
fclose(f); |
162 |
|
} |
179 |
|
PrefsAddString("cdrom", "/dev/cdrom"); |
180 |
|
#elif defined(__FreeBSD__) |
181 |
|
PrefsAddString("cdrom", "/dev/cd0c"); |
182 |
+ |
#elif defined(__NetBSD__) |
183 |
+ |
PrefsAddString("cdrom", "/dev/cd0d"); |
184 |
|
#endif |
185 |
|
} |
186 |
|
|
197 |
|
#elif defined(__FreeBSD__) |
198 |
|
PrefsAddString("seriala", "/dev/cuaa0"); |
199 |
|
PrefsAddString("serialb", "/dev/cuaa1"); |
200 |
+ |
#elif defined(__NetBSD__) |
201 |
+ |
PrefsAddString("seriala", "/dev/tty00"); |
202 |
+ |
PrefsAddString("serialb", "/dev/tty01"); |
203 |
|
#endif |
204 |
|
} |
205 |
|
|
224 |
|
// Parse line |
225 |
|
if (strncmp(line, dev_name, strlen(dev_name)) == 0) { |
226 |
|
mount_name[0] = 0; |
227 |
< |
char dummy[256]; |
228 |
< |
sscanf(line, "%s %s", dummy, mount_name); |
227 |
> |
char *dummy; |
228 |
> |
sscanf(line, "%as %s", &dummy, mount_name); |
229 |
> |
free(dummy); |
230 |
|
fclose(f); |
231 |
|
return true; |
232 |
|
} |
245 |
|
void *Sys_open(const char *name, bool read_only) |
246 |
|
{ |
247 |
|
bool is_file = strncmp(name, "/dev/", 5) != 0; |
248 |
< |
#ifdef __FreeBSD__ |
248 |
> |
#if defined(__FreeBSD__) |
249 |
|
// SCSI IDE |
250 |
|
bool is_cdrom = strncmp(name, "/dev/cd", 7) == 0 || strncmp(name, "/dev/acd", 8) == 0; |
251 |
|
#else |
273 |
|
} |
274 |
|
|
275 |
|
// Open file/device |
276 |
< |
#ifdef __linux__ |
276 |
> |
#if defined(__linux__) |
277 |
|
int fd = open(name, (read_only ? O_RDONLY : O_RDWR) | (is_cdrom ? O_NONBLOCK : 0)); |
278 |
|
#else |
279 |
|
int fd = open(name, read_only ? O_RDONLY : O_RDWR); |
295 |
|
if (fh->is_file) { |
296 |
|
// Detect disk image file layout |
297 |
|
loff_t size = 0; |
298 |
< |
#ifdef __linux__ |
298 |
> |
#if defined(__linux__) |
299 |
|
_llseek(fh->fd, 0, 0, &size, SEEK_END); |
300 |
|
#else |
301 |
|
size = lseek(fd, 0, SEEK_END); |
330 |
|
#else |
331 |
|
fh->cdrom_cap = 0; |
332 |
|
#endif |
333 |
+ |
#elif defined(__NetBSD__) |
334 |
+ |
fh->is_floppy = ((st.st_rdev >> 16) == 2); |
335 |
|
#endif |
336 |
|
} |
337 |
|
} |
375 |
|
return 0; |
376 |
|
|
377 |
|
// Seek to position |
378 |
< |
#ifdef __linux__ |
378 |
> |
#if defined(__linux__) |
379 |
|
loff_t pos = offset + fh->start_byte, res; |
380 |
|
if (_llseek(fh->fd, pos >> 32, pos, &res, SEEK_SET) < 0) |
381 |
|
return 0; |
401 |
|
return 0; |
402 |
|
|
403 |
|
// Seek to position |
404 |
< |
#ifdef __linux__ |
404 |
> |
#if defined(__linux__) |
405 |
|
loff_t pos = offset + fh->start_byte, res; |
406 |
|
if (_llseek(fh->fd, pos >> 32, pos, &res, SEEK_SET) < 0) |
407 |
|
return 0; |
428 |
|
if (fh->is_file) |
429 |
|
return fh->file_size; |
430 |
|
else { |
431 |
< |
#ifdef __linux__ |
432 |
< |
loff_t pos = 0; |
433 |
< |
_llseek(fh->fd, 0, 0, &pos, SEEK_END); |
434 |
< |
return pos - fh->start_byte; |
431 |
> |
#if defined(__linux__) |
432 |
> |
long blocks; |
433 |
> |
if (ioctl(fh->fd, BLKGETSIZE, &blocks) < 0) |
434 |
> |
return 0; |
435 |
> |
D(bug(" BLKGETSIZE returns %d blocks\n", blocks)); |
436 |
> |
return (loff_t)blocks * 512; |
437 |
|
#else |
438 |
|
return lseek(fh->fd, 0, SEEK_END) - fh->start_byte; |
439 |
|
#endif |
461 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
462 |
|
fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK); |
463 |
|
} |
464 |
< |
#elif defined(__FreeBSD__) |
464 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
465 |
|
if (fh->is_floppy) { |
466 |
|
fsync(fh->fd); |
467 |
|
//ioctl(fh->fd, FDFLUSH); |
500 |
|
if (!fh) |
501 |
|
return true; |
502 |
|
|
503 |
< |
#ifdef __linux__ |
503 |
> |
#if defined(__linux__) |
504 |
|
if (fh->is_floppy) { |
505 |
|
struct floppy_drive_struct stat; |
506 |
|
ioctl(fh->fd, FDGETDRVSTAT, &stat); |
556 |
|
#endif |
557 |
|
cdrom_tochdr header; |
558 |
|
return ioctl(fh->fd, CDROMREADTOCHDR, &header) == 0; |
559 |
< |
#elif defined(__FreeBSD__) |
559 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
560 |
|
} else if (fh->is_floppy) { |
561 |
|
return false; //!! |
562 |
|
} else if (fh->is_cdrom) { |
596 |
|
if (!fh) |
597 |
|
return; |
598 |
|
|
599 |
< |
#ifdef defined(__linux__) && defined(CDROM_LOCKDOOR) |
599 |
> |
#if defined(__linux__) && defined(CDROM_LOCKDOOR) |
600 |
|
if (fh->is_cdrom) |
601 |
|
ioctl(fh->fd, CDROM_LOCKDOOR, 0); |
602 |
|
#endif |
706 |
|
*toc++ = toc_size >> 8; |
707 |
|
*toc++ = toc_size & 0xff; |
708 |
|
return true; |
709 |
+ |
#elif defined(__NetBSD__) |
710 |
+ |
uint8 *p = toc + 2; |
711 |
+ |
|
712 |
+ |
// Header |
713 |
+ |
struct ioc_toc_header header; |
714 |
+ |
if (ioctl(fh->fd, CDIOREADTOCHEADER, &header) < 0) |
715 |
+ |
return false; |
716 |
+ |
*p++ = header.starting_track; |
717 |
+ |
*p++ = header.ending_track; |
718 |
+ |
|
719 |
+ |
// Tracks (this is nice... :-) |
720 |
+ |
struct ioc_read_toc_entry entries; |
721 |
+ |
entries.address_format = CD_MSF_FORMAT; |
722 |
+ |
entries.starting_track = 1; |
723 |
+ |
entries.data_len = 800; |
724 |
+ |
entries.data = (cd_toc_entry *)p; |
725 |
+ |
if (ioctl(fh->fd, CDIOREADTOCENTRIES, &entries) < 0) |
726 |
+ |
return false; |
727 |
+ |
|
728 |
+ |
// TOC size |
729 |
+ |
int toc_size = p - toc; |
730 |
+ |
*toc++ = toc_size >> 8; |
731 |
+ |
*toc++ = toc_size & 0xff; |
732 |
+ |
return true; |
733 |
|
#endif |
734 |
|
} else |
735 |
|
return false; |
769 |
|
*pos++ = chan.cdsc_reladdr.msf.second; |
770 |
|
*pos++ = chan.cdsc_reladdr.msf.frame; |
771 |
|
return true; |
772 |
< |
#elif defined(__FreeBSD__) |
772 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
773 |
|
struct ioc_read_subchannel chan; |
774 |
|
chan.data_format = CD_MSF_FORMAT; |
775 |
|
chan.address_format = CD_MSF_FORMAT; |
819 |
|
play.cdmsf_sec1 = end_s; |
820 |
|
play.cdmsf_frame1 = end_f; |
821 |
|
return ioctl(fh->fd, CDROMPLAYMSF, &play) == 0; |
822 |
< |
#elif defined(__FreeBSD__) |
822 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
823 |
|
struct ioc_play_msf play; |
824 |
|
play.start_m = start_m; |
825 |
|
play.start_s = start_s; |
847 |
|
if (fh->is_cdrom) { |
848 |
|
#if defined(__linux__) |
849 |
|
return ioctl(fh->fd, CDROMPAUSE) == 0; |
850 |
< |
#elif defined(__FreeBSD__) |
850 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
851 |
|
return ioctl(fh->fd, CDIOCPAUSE) == 0; |
852 |
|
#endif |
853 |
|
} else |
868 |
|
if (fh->is_cdrom) { |
869 |
|
#if defined(__linux__) |
870 |
|
return ioctl(fh->fd, CDROMRESUME) == 0; |
871 |
< |
#elif defined(__FreeBSD__) |
871 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
872 |
|
return ioctl(fh->fd, CDIOCRESUME) == 0; |
873 |
|
#endif |
874 |
|
} else |
889 |
|
if (fh->is_cdrom) { |
890 |
|
#if defined(__linux__) |
891 |
|
return ioctl(fh->fd, CDROMSTOP) == 0; |
892 |
< |
#elif defined(__FreeBSD__) |
892 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
893 |
|
return ioctl(fh->fd, CDIOCSTOP) == 0; |
894 |
|
#endif |
895 |
|
} else |
928 |
|
vol.channel0 = vol.channel2 = left; |
929 |
|
vol.channel1 = vol.channel3 = right; |
930 |
|
ioctl(fh->fd, CDROMVOLCTRL, &vol); |
931 |
< |
#elif defined(__FreeBSD__) |
931 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
932 |
|
struct ioc_vol vol; |
933 |
|
vol.vol[0] = vol.vol[2] = left; |
934 |
|
vol.vol[1] = vol.vol[3] = right; |
955 |
|
ioctl(fh->fd, CDROMVOLREAD, &vol); |
956 |
|
left = vol.channel0; |
957 |
|
right = vol.channel1; |
958 |
< |
#elif defined(__FreeBSD__) |
958 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
959 |
|
struct ioc_vol vol; |
960 |
|
ioctl(fh->fd, CDIOCGETVOL, &vol); |
961 |
|
left = vol.vol[0]; |