- NOT A COMPLETE FIX!

now floppy.cc no longer crashes if you try to open a write-protected
  disk or read-only disk image.  Instead, it tries a second time to
  open the image read-only and only panics if this also fails.  If the
  image is opened read-only, a readonly flag is set
  (bx_floppy.s.media[drive].read_only).  If you try to write the floppy
  when this flag is set, the write silently fails except for some messages
  into the log.  Instead of failing silently we should learn what the
  floppy controller would really do in this situation and emulate it.
This commit is contained in:
Bryce Denney 2001-06-13 00:30:34 +00:00
parent d243a4d6cd
commit 6ecd58beb9
2 changed files with 26 additions and 3 deletions

View File

@ -898,6 +898,11 @@ bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
}
else { // TO_FLOPPY
if (BX_FD_THIS s.media[drive].read_only) {
BX_ERROR (("tried to write to a write-protected disk"));
BX_ERROR (("FIXME: This should send some sort of abort or error message to the floppy controller, but instead it silently fails!"));
return;
}
#ifdef macintosh
if (!strcmp(bx_options.floppya.path, SuperDrive))
ret = fd_write((char *) buffer, offset, bytes);
@ -906,8 +911,8 @@ bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
ret = ::write(BX_FD_THIS s.media[drive].fd, (bx_ptr_t) buffer, bytes);
if (ret < int(bytes)) {
BX_PANIC(("could not perform write() on floppy image file"));
}
}
}
}
@ -1165,6 +1170,7 @@ bx_floppy_ctrl_c::evaluate_media(unsigned type, char *path, floppy_t *media)
return(0);
// open media file (image file or device)
media->read_only = 0;
#ifdef macintosh
media->fd = 0;
if (strcmp(bx_options.floppya.path, SuperDrive))
@ -1176,9 +1182,25 @@ bx_floppy_ctrl_c::evaluate_media(unsigned type, char *path, floppy_t *media)
);
if (media->fd < 0) {
BX_INFO(( "floppy open of %s:",path,strerror(errno) ));
return(0);
BX_INFO(( "tried to open %s read/write: %s",path,strerror(errno) ));
// try opening the file read-only
media->read_only = 1;
#ifdef macintosh
media->fd = 0;
if (strcmp(bx_options.floppya.path, SuperDrive))
#endif
media->fd = open(path, O_RDONLY
#ifdef O_BINARY
| O_BINARY
#endif
);
if (media->fd < 0) {
// failed to open read-only too
BX_INFO(( "tried to open %s read only: %s",path,strerror(errno) ));
return(0);
}
}
BX_INFO(("opened %s with readonly=%d\n", path, media->read_only));
#if BX_WITH_MACOS
if (!strcmp(bx_options.floppya.path, SuperDrive))

View File

@ -41,6 +41,7 @@ typedef struct {
unsigned tracks; /* number of tracks */
unsigned heads; /* number of heads */
unsigned type;
unsigned read_only;
} floppy_t;
class bx_floppy_ctrl_c : public logfunctions {