Floppy Driver Query

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
robertapengelly
Posts: 17
Joined: Mon Jun 24, 2024 6:29 am
Contact:

Floppy Driver Query

Post 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.
User avatar
JackScott
Member
Member
Posts: 1036
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Re: Floppy Driver Query

Post 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).
User avatar
robertapengelly
Posts: 17
Joined: Mon Jun 24, 2024 6:29 am
Contact:

Re: Floppy Driver Query

Post 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.
nullplan
Member
Member
Posts: 1840
Joined: Wed Aug 30, 2017 8:24 am

Re: Floppy Driver Query

Post 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.
Carpe diem!
User avatar
robertapengelly
Posts: 17
Joined: Mon Jun 24, 2024 6:29 am
Contact:

Re: Floppy Driver Query

Post 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.
Post Reply