fixed floppy disk change detection problems under Linux

This commit is contained in:
cebix 2002-02-23 17:54:24 +00:00
parent 5ac532edfd
commit 3e58028cb1
3 changed files with 16 additions and 5 deletions

View File

@ -2,6 +2,7 @@ V1.0 (snapshot) - <date>
- 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

View File

@ -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);

View File

@ -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;
}