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.12 by cebix, 2002-02-07T16:10:55Z vs.
Revision 1.17 by gbeauche, 2002-03-29T16:24:18Z

# Line 31 | Line 31
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, unsigned int, fd, unsigned long, hi, unsigned long, lo, loff_t *, res, unsigned int, wh);
# Line 120 | Line 121 | void SysMountFirstFloppy(void)
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");
# Line 176 | Line 192 | void SysAddCDROMPrefs(void)
192                  return;
193  
194   #if defined(__linux__)
195 <        PrefsAddString("cdrom", "/dev/cdrom");
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__)
212          PrefsAddString("cdrom", "/dev/cd0c");
213   #elif defined(__NetBSD__)
# Line 192 | Line 223 | void SysAddCDROMPrefs(void)
223   void SysAddSerialPrefs(void)
224   {
225   #if defined(__linux__)
226 <        PrefsAddString("seriala", "/dev/ttyS0");
227 <        PrefsAddString("serialb", "/dev/ttyS1");
226 >        if (access("/dev/.devfsd", F_OK) < 0) {
227 >                PrefsAddString("seriala", "/dev/ttyS0");
228 >                PrefsAddString("serialb", "/dev/ttyS1");
229 >        } else {
230 >                PrefsAddString("seriala", "/dev/tts/0");
231 >                PrefsAddString("serialb", "/dev/tts/1");
232 >        }
233   #elif defined(__FreeBSD__)
234          PrefsAddString("seriala", "/dev/cuaa0");
235          PrefsAddString("serialb", "/dev/cuaa1");
# Line 456 | Line 492 | void SysEject(void *arg)
492                  fsync(fh->fd);
493                  ioctl(fh->fd, FDFLUSH);
494                  ioctl(fh->fd, FDEJECT);
495 +                close(fh->fd);  // Close and reopen so the driver will see the media change
496 +                fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR);
497          } else if (fh->is_cdrom) {
498                  ioctl(fh->fd, CDROMEJECT);
499                  close(fh->fd);  // Close and reopen so the driver will see the media change
# Line 464 | Line 502 | void SysEject(void *arg)
502   #elif defined(__FreeBSD__) || defined(__NetBSD__)
503          if (fh->is_floppy) {
504                  fsync(fh->fd);
467                //ioctl(fh->fd, FDFLUSH);
468                //ioctl(fh->fd, FDEJECT);
505          } else if (fh->is_cdrom) {
506                  ioctl(fh->fd, CDIOCEJECT);
507                  close(fh->fd);  // Close and reopen so the driver will see the media change
# Line 547 | Line 583 | bool SysIsDiskInserted(void *arg)
583          } else if (fh->is_floppy) {
584                  char block[512];
585                  lseek(fh->fd, 0, SEEK_SET);
586 <                return read(fh->fd, block, 512) == 512;
586 >                ssize_t actual = read(fh->fd, block, 512);
587 >                if (actual < 0) {
588 >                        close(fh->fd);  // Close and reopen so the driver will see the media change
589 >                        fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR);
590 >                        actual = read(fh->fd, block, 512);
591 >                }
592 >                return actual == 512;
593          } else if (fh->is_cdrom) {
594   #ifdef CDROM_MEDIA_CHANGED
595                  if (fh->cdrom_cap & CDC_MEDIA_CHANGED) {
596                          // If we don't do this, all attempts to read from a disc fail
597 <                        // once the tray has been open (altough the TOC reads fine).
597 >                        // once the tray has been opened (altough the TOC reads fine).
598                          // Can somebody explain this to me?
599                          if (ioctl(fh->fd, CDROM_MEDIA_CHANGED) == 1) {
600                                  close(fh->fd);
# Line 741 | Line 783 | bool SysCDReadTOC(void *arg, uint8 *toc)
783                  *toc++ = toc_size >> 8;
784                  *toc++ = toc_size & 0xff;
785                  return true;
786 + #else
787 +                return false;
788   #endif
789          } else
790                  return false;
# Line 804 | Line 848 | bool SysCDGetPosition(void *arg, uint8 *
848                  *pos++ = chan.data->what.position.reladdr.msf.second;
849                  *pos++ = chan.data->what.position.reladdr.msf.frame;
850                  return true;
851 + #else
852 +                return false;
853   #endif
854          } else
855                  return false;
# Line 839 | Line 885 | bool SysCDPlay(void *arg, uint8 start_m,
885                  play.end_s = end_s;
886                  play.end_f = end_f;
887                  return ioctl(fh->fd, CDIOCPLAYMSF, &play) == 0;
888 + #else
889 +                return false;
890   #endif
891          } else
892                  return false;
# Line 860 | Line 908 | bool SysCDPause(void *arg)
908                  return ioctl(fh->fd, CDROMPAUSE) == 0;
909   #elif defined(__FreeBSD__) || defined(__NetBSD__)
910                  return ioctl(fh->fd, CDIOCPAUSE) == 0;
911 + #else
912 +                return false;
913   #endif
914          } else
915                  return false;
# Line 881 | Line 931 | bool SysCDResume(void *arg)
931                  return ioctl(fh->fd, CDROMRESUME) == 0;
932   #elif defined(__FreeBSD__) || defined(__NetBSD__)
933                  return ioctl(fh->fd, CDIOCRESUME) == 0;
934 + #else
935 +                return false;
936   #endif
937          } else
938                  return false;
# Line 902 | Line 954 | bool SysCDStop(void *arg, uint8 lead_out
954                  return ioctl(fh->fd, CDROMSTOP) == 0;
955   #elif defined(__FreeBSD__) || defined(__NetBSD__)
956                  return ioctl(fh->fd, CDIOCSTOP) == 0;
957 + #else
958 +                return false;
959   #endif
960          } else
961                  return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines