From 3e58028cb14cdcbd2d2798055c1e863ed663e693 Mon Sep 17 00:00:00 2001 From: cebix <> Date: Sat, 23 Feb 2002 17:54:24 +0000 Subject: [PATCH] fixed floppy disk change detection problems under Linux --- BasiliskII/ChangeLog | 1 + BasiliskII/src/Unix/sys_unix.cpp | 14 ++++++++++---- BasiliskII/src/sony.cpp | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/BasiliskII/ChangeLog b/BasiliskII/ChangeLog index 81c56df8..dc944ca7 100644 --- a/BasiliskII/ChangeLog +++ b/BasiliskII/ChangeLog @@ -2,6 +2,7 @@ V1.0 (snapshot) - - fixed the problem with Ticks getting incremented on every interrupt, not just 60Hz (e.g. moving the mouse made the caret blink faster) - Unix: cleaned up pthread attributes [Brian Johnson] + - Unix: fixed floppy problems under Linux V1.0 (snapshot) - 15.Jan.2002 - added support for on-the-fly video resolution and depth switching, and diff --git a/BasiliskII/src/Unix/sys_unix.cpp b/BasiliskII/src/Unix/sys_unix.cpp index 12e248c3..cc6a58b4 100644 --- a/BasiliskII/src/Unix/sys_unix.cpp +++ b/BasiliskII/src/Unix/sys_unix.cpp @@ -456,6 +456,8 @@ void SysEject(void *arg) fsync(fh->fd); ioctl(fh->fd, FDFLUSH); ioctl(fh->fd, FDEJECT); + close(fh->fd); // Close and reopen so the driver will see the media change + fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR); } else if (fh->is_cdrom) { ioctl(fh->fd, CDROMEJECT); close(fh->fd); // Close and reopen so the driver will see the media change @@ -464,8 +466,6 @@ void SysEject(void *arg) #elif defined(__FreeBSD__) || defined(__NetBSD__) if (fh->is_floppy) { fsync(fh->fd); - //ioctl(fh->fd, FDFLUSH); - //ioctl(fh->fd, FDEJECT); } else if (fh->is_cdrom) { ioctl(fh->fd, CDIOCEJECT); close(fh->fd); // Close and reopen so the driver will see the media change @@ -547,12 +547,18 @@ bool SysIsDiskInserted(void *arg) } else if (fh->is_floppy) { char block[512]; lseek(fh->fd, 0, SEEK_SET); - return read(fh->fd, block, 512) == 512; + ssize_t actual = read(fh->fd, block, 512); + if (actual < 0) { + close(fh->fd); // Close and reopen so the driver will see the media change + fh->fd = open(fh->name, fh->read_only ? O_RDONLY : O_RDWR); + actual = read(fh->fd, block, 512); + } + return actual == 512; } else if (fh->is_cdrom) { #ifdef CDROM_MEDIA_CHANGED if (fh->cdrom_cap & CDC_MEDIA_CHANGED) { // If we don't do this, all attempts to read from a disc fail - // once the tray has been open (altough the TOC reads fine). + // once the tray has been opened (altough the TOC reads fine). // Can somebody explain this to me? if (ioctl(fh->fd, CDROM_MEDIA_CHANGED) == 1) { close(fh->fd); diff --git a/BasiliskII/src/sony.cpp b/BasiliskII/src/sony.cpp index 8ba4aef7..6e0ff029 100644 --- a/BasiliskII/src/sony.cpp +++ b/BasiliskII/src/sony.cpp @@ -195,10 +195,12 @@ bool SonyMountVolume(void *fh) while (info != end && info->fh != fh) ++info; if (info != end) { + D(bug("Looking for disk in drive %d\n", info->num)); if (SysIsDiskInserted(info->fh)) { info->read_only = SysIsReadOnly(info->fh); WriteMacInt8(info->status + dsDiskInPlace, 1); // Inserted removable disk WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0xff : 0); + D(bug(" disk inserted, mounting\n")); info->to_be_mounted = true; } return true; @@ -219,7 +221,7 @@ static void mount_mountable_volumes(void) #if DISK_INSERT_CHECK // Disk in drive? - if (!ReadMacInt8(info->status + dsDiskInPlace)) { + if (ReadMacInt8(info->status + dsDiskInPlace) == 0) { // No, check if disk was inserted if (SysIsDiskInserted(info->fh)) @@ -246,6 +248,7 @@ static void mount_mountable_volumes(void) static int16 set_dsk_err(int16 err) { + D(bug("set_dsk_err(%d)\n", err)); WriteMacInt16(0x142, err); return err; } @@ -307,6 +310,7 @@ int16 SonyOpen(uint32 pb, uint32 dce) if (SysIsDiskInserted(info->fh)) { WriteMacInt8(info->status + dsDiskInPlace, 1); // Inserted removable disk WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0xff : 0); + D(bug(" disk inserted, flagging for mount\n")); info->to_be_mounted = true; }