46 |
|
#endif |
47 |
|
#endif |
48 |
|
|
49 |
< |
#ifdef __FreeBSD__ |
49 |
> |
#if defined(__FreeBSD__) || defined(__NetBSD__) |
50 |
|
#include <sys/cdio.h> |
51 |
|
#endif |
52 |
|
|
121 |
|
#if defined(__linux__) |
122 |
|
PrefsAddString("floppy", "/dev/fd0H1440"); |
123 |
|
PrefsAddString("floppy", "/dev/fd1H1440"); |
124 |
+ |
#elif defined(__NetBSD__) |
125 |
+ |
PrefsAddString("floppy", "/dev/fd0a"); |
126 |
+ |
PrefsAddString("floppy", "/dev/fd1a"); |
127 |
|
#else |
128 |
|
PrefsAddString("floppy", "/dev/fd0"); |
129 |
|
PrefsAddString("floppy", "/dev/fd1"); |
151 |
|
|
152 |
|
// Parse line |
153 |
|
char *dev, *mnt_point, *fstype; |
154 |
< |
if (sscanf(line, "%s %s %s", &dev, &mnt_point, &fstype) == 3) { |
154 |
> |
if (sscanf(line, "%as %as %as", &dev, &mnt_point, &fstype) == 3) { |
155 |
|
if (strcmp(fstype, "hfs") == 0) |
156 |
|
PrefsAddString("disk", dev); |
157 |
|
} |
158 |
+ |
free(dev); free(mnt_point); free(fstype); |
159 |
|
} |
160 |
|
fclose(f); |
161 |
|
} |
178 |
|
PrefsAddString("cdrom", "/dev/cdrom"); |
179 |
|
#elif defined(__FreeBSD__) |
180 |
|
PrefsAddString("cdrom", "/dev/cd0c"); |
181 |
+ |
#elif defined(__NetBSD__) |
182 |
+ |
PrefsAddString("cdrom", "/dev/cd0d"); |
183 |
|
#endif |
184 |
|
} |
185 |
|
|
196 |
|
#elif defined(__FreeBSD__) |
197 |
|
PrefsAddString("seriala", "/dev/cuaa0"); |
198 |
|
PrefsAddString("serialb", "/dev/cuaa1"); |
199 |
+ |
#elif defined(__NetBSD__) |
200 |
+ |
PrefsAddString("seriala", "/dev/tty00"); |
201 |
+ |
PrefsAddString("serialb", "/dev/tty01"); |
202 |
|
#endif |
203 |
|
} |
204 |
|
|
223 |
|
// Parse line |
224 |
|
if (strncmp(line, dev_name, strlen(dev_name)) == 0) { |
225 |
|
mount_name[0] = 0; |
226 |
< |
char dummy[256]; |
227 |
< |
sscanf(line, "%s %s", dummy, mount_name); |
226 |
> |
char *dummy; |
227 |
> |
sscanf(line, "%as %s", &dummy, mount_name); |
228 |
> |
free(dummy); |
229 |
|
fclose(f); |
230 |
|
return true; |
231 |
|
} |
244 |
|
void *Sys_open(const char *name, bool read_only) |
245 |
|
{ |
246 |
|
bool is_file = strncmp(name, "/dev/", 5) != 0; |
247 |
< |
#ifdef __FreeBSD__ |
247 |
> |
#if defined(__FreeBSD__) |
248 |
|
// SCSI IDE |
249 |
|
bool is_cdrom = strncmp(name, "/dev/cd", 7) == 0 || strncmp(name, "/dev/acd", 8) == 0; |
250 |
|
#else |
272 |
|
} |
273 |
|
|
274 |
|
// Open file/device |
275 |
< |
#ifdef __linux__ |
275 |
> |
#if defined(__linux__) |
276 |
|
int fd = open(name, (read_only ? O_RDONLY : O_RDWR) | (is_cdrom ? O_NONBLOCK : 0)); |
277 |
|
#else |
278 |
|
int fd = open(name, read_only ? O_RDONLY : O_RDWR); |
294 |
|
if (fh->is_file) { |
295 |
|
// Detect disk image file layout |
296 |
|
loff_t size = 0; |
297 |
< |
#ifdef __linux__ |
297 |
> |
#if defined(__linux__) |
298 |
|
_llseek(fh->fd, 0, 0, &size, SEEK_END); |
299 |
|
#else |
300 |
|
size = lseek(fd, 0, SEEK_END); |
319 |
|
#else |
320 |
|
fh->cdrom_cap = 0; |
321 |
|
#endif |
322 |
< |
#elif defined(__FreeBSD__) |
322 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
323 |
|
fh->is_floppy = ((st.st_rdev >> 16) == 2); |
324 |
|
#ifdef CDIOCCAPABILITY |
325 |
|
if (is_cdrom) { |
372 |
|
return 0; |
373 |
|
|
374 |
|
// Seek to position |
375 |
< |
#ifdef __linux__ |
375 |
> |
#if defined(__linux__) |
376 |
|
loff_t pos = offset + fh->start_byte, res; |
377 |
|
if (_llseek(fh->fd, pos >> 32, pos, &res, SEEK_SET) < 0) |
378 |
|
return 0; |
398 |
|
return 0; |
399 |
|
|
400 |
|
// Seek to position |
401 |
< |
#ifdef __linux__ |
401 |
> |
#if defined(__linux__) |
402 |
|
loff_t pos = offset + fh->start_byte, res; |
403 |
|
if (_llseek(fh->fd, pos >> 32, pos, &res, SEEK_SET) < 0) |
404 |
|
return 0; |
425 |
|
if (fh->is_file) |
426 |
|
return fh->file_size; |
427 |
|
else { |
428 |
< |
#ifdef __linux__ |
428 |
> |
#if defined(__linux__) |
429 |
|
loff_t pos = 0; |
430 |
|
_llseek(fh->fd, 0, 0, &pos, SEEK_END); |
431 |
|
return pos - fh->start_byte; |
456 |
|
close(fh->fd); // Close and reopen so the driver will see the media change |
457 |
|
fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK); |
458 |
|
} |
459 |
< |
#elif defined(__FreeBSD__) |
459 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
460 |
|
if (fh->is_floppy) { |
461 |
|
fsync(fh->fd); |
462 |
|
//ioctl(fh->fd, FDFLUSH); |
495 |
|
if (!fh) |
496 |
|
return true; |
497 |
|
|
498 |
< |
#ifdef __linux__ |
498 |
> |
#if defined(__linux__) |
499 |
|
if (fh->is_floppy) { |
500 |
|
struct floppy_drive_struct stat; |
501 |
|
ioctl(fh->fd, FDGETDRVSTAT, &stat); |
551 |
|
#endif |
552 |
|
cdrom_tochdr header; |
553 |
|
return ioctl(fh->fd, CDROMREADTOCHDR, &header) == 0; |
554 |
< |
#elif defined(__FreeBSD__) |
554 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
555 |
|
} else if (fh->is_floppy) { |
556 |
|
return false; //!! |
557 |
|
} else if (fh->is_cdrom) { |
655 |
|
*toc++ = toc_size >> 8; |
656 |
|
*toc++ = toc_size & 0xff; |
657 |
|
return true; |
658 |
< |
#elif defined(__FreeBSD__) |
658 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
659 |
|
uint8 *p = toc + 2; |
660 |
|
|
661 |
|
// Header |
740 |
|
*pos++ = chan.cdsc_reladdr.msf.second; |
741 |
|
*pos++ = chan.cdsc_reladdr.msf.frame; |
742 |
|
return true; |
743 |
< |
#elif defined(__FreeBSD__) |
743 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
744 |
|
struct ioc_read_subchannel chan; |
745 |
|
chan.data_format = CD_MSF_FORMAT; |
746 |
|
chan.address_format = CD_MSF_FORMAT; |
790 |
|
play.cdmsf_sec1 = end_s; |
791 |
|
play.cdmsf_frame1 = end_f; |
792 |
|
return ioctl(fh->fd, CDROMPLAYMSF, &play) == 0; |
793 |
< |
#elif defined(__FreeBSD__) |
793 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
794 |
|
struct ioc_play_msf play; |
795 |
|
play.start_m = start_m; |
796 |
|
play.start_s = start_s; |
818 |
|
if (fh->is_cdrom) { |
819 |
|
#if defined(__linux__) |
820 |
|
return ioctl(fh->fd, CDROMPAUSE) == 0; |
821 |
< |
#elif defined(__FreeBSD__) |
821 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
822 |
|
return ioctl(fh->fd, CDIOCPAUSE) == 0; |
823 |
|
#endif |
824 |
|
} else |
839 |
|
if (fh->is_cdrom) { |
840 |
|
#if defined(__linux__) |
841 |
|
return ioctl(fh->fd, CDROMRESUME) == 0; |
842 |
< |
#elif defined(__FreeBSD__) |
842 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
843 |
|
return ioctl(fh->fd, CDIOCRESUME) == 0; |
844 |
|
#endif |
845 |
|
} else |
860 |
|
if (fh->is_cdrom) { |
861 |
|
#if defined(__linux__) |
862 |
|
return ioctl(fh->fd, CDROMSTOP) == 0; |
863 |
< |
#elif defined(__FreeBSD__) |
863 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
864 |
|
return ioctl(fh->fd, CDIOCSTOP) == 0; |
865 |
|
#endif |
866 |
|
} else |
899 |
|
vol.channel0 = vol.channel2 = left; |
900 |
|
vol.channel1 = vol.channel3 = right; |
901 |
|
ioctl(fh->fd, CDROMVOLCTRL, &vol); |
902 |
< |
#elif defined(__FreeBSD__) |
902 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
903 |
|
struct ioc_vol vol; |
904 |
|
vol.vol[0] = vol.vol[2] = left; |
905 |
|
vol.vol[1] = vol.vol[3] = right; |
926 |
|
ioctl(fh->fd, CDROMVOLREAD, &vol); |
927 |
|
left = vol.channel0; |
928 |
|
right = vol.channel1; |
929 |
< |
#elif defined(__FreeBSD__) |
929 |
> |
#elif defined(__FreeBSD__) || defined(__NetBSD__) |
930 |
|
struct ioc_vol vol; |
931 |
|
ioctl(fh->fd, CDIOCGETVOL, &vol); |
932 |
|
left = vol.vol[0]; |