Page 1 of 1

Floppy Driver Query

Posted: Sat Feb 01, 2025 6:38 pm
by robertapengelly
Hey guys,

I've come across https://wiki.osdev.org/Floppy_Disk_Cont ... ting_Media and it says:

Detecting Media

The user can swap media out of a floppy drive at any moment. If your driver sends a command to the drive, and the
command fails -- this may be the reason why.

Turn the drive motor bit on.

Read DIR. If the "Disk Change" bitflag is set to "true", then the floppy drive door was opened, so the OS needs to test if a
new disk is in the drive.

I've tried looking around online but I can't find anything related to "Disk Change" bitflag. Is it something I would have to keep track of or can it be read from the floppy controller? If it's the latter can you either provide an example of how you would get it or if possible refer me to somewhere that has a little bit of information about it.

Re: Floppy Driver Query

Posted: Sat Feb 01, 2025 10:33 pm
by JackScott
Further up that same page is this section: https://wiki.osdev.org/Floppy_Disk_Cont ... Change_bit

You're looking to read bit 7 of the DIR register (0x3F7).

Re: Floppy Driver Query

Posted: Sat Feb 01, 2025 10:50 pm
by robertapengelly
Thanks for that I completely skipped passed it. I have a new query now, it says "If Disk Change is set and there was media, the OS should get a signal that the previous media was ejected.", so how does the OS get the signal? I've tried implementing IRQ6 but the only thing that seems to trigger it is reading the device. I found viewtopic.php?t=11774 but it doesn't exactly help.

Re: Floppy Driver Query

Posted: Sat Feb 01, 2025 11:20 pm
by nullplan
I think this is supposed to be for your OS internally. You've then seen that the disk was ejected, so you need to forcefully unmount the file system, tell the disk cache to discard everything it still had queued for the drive (because now there is a different medium in there and you'd be writing to the wrong thing), maybe tell applications that the files are no longer available. E.g. on UNIX, you could set all file descriptors pointing to the medium into a state where every interaction just returns EIO.

Although I don't see where it tests if the new medium is maybe even the same as the old one (maybe the user hit the eject button by mistake and put the disk right back in). But I also don't know how to tell reliably.

Re: Floppy Driver Query

Posted: Sat Feb 01, 2025 11:26 pm
by robertapengelly
That makes sense.
nullplan wrote: Sat Feb 01, 2025 11:20 pm Although I don't see where it tests if the new medium is maybe even the same as the old one (maybe the user hit the eject button by mistake and put the disk right back in). But I also don't know how to tell reliably.
Could have some sort of serial number (e.g. fat volume id) and test if it's the same when a new read starts or something before unmounting things maybe.