Link to home
Start Free TrialLog in
Avatar of grmbl
grmbl

asked on

How do i detect a floppy disk change?

Is there a way to check wheter the floppy a new floppy has been inserted in the diskdrive? I want my linuxbox to automaticly mount floppies. I can offcourse mount a microswitch on my diskdrive and read poll that via my joystickport or something like that. But if there is a software way to do it, thats much nicer. What i don't want is my drive motor to switch on. Is there a way to check these things?  What i found out is that my writeprotect-switch consists of 2 pins of which one gets pressed if write-protect and the other gets pressed when write enable. So OR-ing those switches means a disk detection. How can i read the state of these switches?

I hope that you can help me. Marc.
Avatar of alexo
alexo
Flag of Antarctica image

Good ol' INT13 comes to the rescue:

-----------------------------------------------------------
 INT 13 - GET DISK TYPE (PC/AT ONLY)
     REG AH = 15H
         DL = DRIVE ID
     ON RETURN:
        REG AH = DISK TYPE
                 0 = DISK NOT THERE
                 1 = DISKETTE, NO CHANGE DETECTION PRESENT
                 2 = DISKETTE, CHANGE DETECTION PRESENT
                 3 = FIXED DISK
            CX,DX = NUMBER OF 512-BYTE SECTORS WHEN AH = 3
 -----------------------------------------------------------
 INT 13 - CHANGE OF DISK STATUS (PC/AT ONLY)
     REG AH = 16H
     ON RETURN:
        REG DL = DRIVE THAT HAD DISK CHANGE
            AH = DISK CHANGE STATUS
                 00 = NO DISK CHANGE
                 01 = DISK CHANGED
 -----------------------------------------------------------
 
Also, you can access the change-detect line by port 0x3F7 (bit 7), but it only useful if the drive motor is on.  Normally you'd use interupt 13h, ah=16h but if the system is also accessing the drive you stand to miss the diskette change.
Avatar of grmbl
grmbl

ASKER

I read that INT 13 specification too. But unfortunately i've never coded hardware interupts before. (I did a bit with asembly but not much). So can you please give me a clue where i can get info on how to program that sort of things under linux?

Do i have to place the code in the kernel? Or in a suid program? Or make a module? I haven't got any experience with that sort of coding so please consider me a newbie :-) I took a look at floppy.c but i couln't find something usefull there.

Marc
Sorry, not familiar with Linux.  Why don't you put a zero-point pointer to your question in the "Linux" and "Unix" areas?  Call it something like "Reference to detect a floppy disk change" and put the URL of this question (https://www.experts-exchange.com/Q.10048457) inside.
I don't think the OS can tell if the floppy haas changed or not. What I would do is make a timer something keeps checking to see if the floppy is the same of differnt.
Avatar of grmbl

ASKER

Yes but i want to check that without switching on the drive motor. Grepped through the kernel sources and the headerfiles but im not experienced enough to know what registers to read from.
ASKER CERTIFIED SOLUTION
Avatar of rbr
rbr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial