ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/sys_unix.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/sys_unix.cpp (file contents):
Revision 1.6 by cebix, 2000-02-21T20:04:17Z vs.
Revision 1.15 by cebix, 2002-03-20T19:03:41Z

# Line 1 | Line 1
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
# Line 33 | Line 33
33   #include <linux/unistd.h>
34  
35   #ifdef __NR__llseek
36 < _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, loff_t *, res, uint, wh);
36 > _syscall5(int, _llseek, unsigned int, fd, unsigned long, hi, unsigned long, lo, loff_t *, res, unsigned int, wh);
37   #else
38 < static int _llseek(uint fd, ulong hi, ulong lo, loff_t *res, uint wh)
38 > static int _llseek(unsigned int fd, unsigned long hi, unsigned long lo, loff_t *res, unsigned int wh)
39   {
40          if (hi)
41                  return -1;
# Line 120 | Line 120 | void SysMountFirstFloppy(void)
120   void SysAddFloppyPrefs(void)
121   {
122   #if defined(__linux__)
123 <        PrefsAddString("floppy", "/dev/fd0H1440");
124 <        PrefsAddString("floppy", "/dev/fd1H1440");
123 >        PrefsAddString("floppy", "/dev/fd0u1440");
124 >        PrefsAddString("floppy", "/dev/fd1u1440");
125   #elif defined(__NetBSD__)
126          PrefsAddString("floppy", "/dev/fd0a");
127          PrefsAddString("floppy", "/dev/fd1a");
# Line 146 | Line 146 | void SysAddDiskPrefs(void)
146                  while(fgets(line, 255, f)) {
147                          // Read line
148                          int len = strlen(line);
149 <                        if (len == 0)
149 >                        if (len == 0 || line[0] == '#')
150                                  continue;
151                          line[len-1] = 0;
152  
# Line 273 | Line 273 | void *Sys_open(const char *name, bool re
273          }
274  
275          // Open file/device
276 < #if defined(__linux__)
276 > #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
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);
# Line 456 | Line 456 | void SysEject(void *arg)
456                  fsync(fh->fd);
457                  ioctl(fh->fd, FDFLUSH);
458                  ioctl(fh->fd, FDEJECT);
459 +                close(fh->fd);  // Close and reopen so the driver will see the media change
460 +                fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR);
461          } else if (fh->is_cdrom) {
462                  ioctl(fh->fd, CDROMEJECT);
463                  close(fh->fd);  // Close and reopen so the driver will see the media change
# Line 464 | Line 466 | void SysEject(void *arg)
466   #elif defined(__FreeBSD__) || defined(__NetBSD__)
467          if (fh->is_floppy) {
468                  fsync(fh->fd);
467                //ioctl(fh->fd, FDFLUSH);
468                //ioctl(fh->fd, FDEJECT);
469          } else if (fh->is_cdrom) {
470                  ioctl(fh->fd, CDIOCEJECT);
471                  close(fh->fd);  // Close and reopen so the driver will see the media change
# Line 547 | Line 547 | bool SysIsDiskInserted(void *arg)
547          } else if (fh->is_floppy) {
548                  char block[512];
549                  lseek(fh->fd, 0, SEEK_SET);
550 <                return read(fh->fd, block, 512) == 512;
550 >                ssize_t actual = read(fh->fd, block, 512);
551 >                if (actual < 0) {
552 >                        close(fh->fd);  // Close and reopen so the driver will see the media change
553 >                        fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR);
554 >                        actual = read(fh->fd, block, 512);
555 >                }
556 >                return actual == 512;
557          } else if (fh->is_cdrom) {
558 + #ifdef CDROM_MEDIA_CHANGED
559 +                if (fh->cdrom_cap & CDC_MEDIA_CHANGED) {
560 +                        // If we don't do this, all attempts to read from a disc fail
561 +                        // once the tray has been opened (altough the TOC reads fine).
562 +                        // Can somebody explain this to me?
563 +                        if (ioctl(fh->fd, CDROM_MEDIA_CHANGED) == 1) {
564 +                                close(fh->fd);
565 +                                fh->fd = open(fh->name, O_RDONLY | O_NONBLOCK);
566 +                        }
567 +                }
568 + #endif
569   #ifdef CDROM_DRIVE_STATUS
570                  if (fh->cdrom_cap & CDC_DRIVE_STATUS) {
571                          return ioctl(fh->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) == CDS_DISC_OK;
# Line 730 | Line 747 | bool SysCDReadTOC(void *arg, uint8 *toc)
747                  *toc++ = toc_size >> 8;
748                  *toc++ = toc_size & 0xff;
749                  return true;
750 + #else
751 +                return false;
752   #endif
753          } else
754                  return false;
# Line 793 | Line 812 | bool SysCDGetPosition(void *arg, uint8 *
812                  *pos++ = chan.data->what.position.reladdr.msf.second;
813                  *pos++ = chan.data->what.position.reladdr.msf.frame;
814                  return true;
815 + #else
816 +                return false;
817   #endif
818          } else
819                  return false;
# Line 828 | Line 849 | bool SysCDPlay(void *arg, uint8 start_m,
849                  play.end_s = end_s;
850                  play.end_f = end_f;
851                  return ioctl(fh->fd, CDIOCPLAYMSF, &play) == 0;
852 + #else
853 +                return false;
854   #endif
855          } else
856                  return false;
# Line 849 | Line 872 | bool SysCDPause(void *arg)
872                  return ioctl(fh->fd, CDROMPAUSE) == 0;
873   #elif defined(__FreeBSD__) || defined(__NetBSD__)
874                  return ioctl(fh->fd, CDIOCPAUSE) == 0;
875 + #else
876 +                return false;
877   #endif
878          } else
879                  return false;
# Line 870 | Line 895 | bool SysCDResume(void *arg)
895                  return ioctl(fh->fd, CDROMRESUME) == 0;
896   #elif defined(__FreeBSD__) || defined(__NetBSD__)
897                  return ioctl(fh->fd, CDIOCRESUME) == 0;
898 + #else
899 +                return false;
900   #endif
901          } else
902                  return false;
# Line 891 | Line 918 | bool SysCDStop(void *arg, uint8 lead_out
918                  return ioctl(fh->fd, CDROMSTOP) == 0;
919   #elif defined(__FreeBSD__) || defined(__NetBSD__)
920                  return ioctl(fh->fd, CDIOCSTOP) == 0;
921 + #else
922 +                return false;
923   #endif
924          } else
925                  return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines