I am trying to check does any disk is present in drive A: (after my program installs i need to ensure that computer won't boot from installation diskette). I've tried using _access method (undefined reference...), FILE* and making directory inside diskette and remove it after checking. Unfortunately DOS displays ugly piece of text about putting disk in drive (Destroying my TUI and making user think that diskette in drive is important). So how to suppress this message, or safely check does disk is present in drive?
Asked
Active
Viewed 486 times
6
-
15What year is it? – Jonathon Reinhart May 08 '17 at 14:22
-
6Now I know the time machine was invented in 80s-90s od XXs century and was based on DOS computer... – Eugene Sh. May 08 '17 at 14:22
-
Anyone has no idea how to solve it? – Kamila Szewczyk May 08 '17 at 14:45
-
9If you asked me 20 years ago I would have known it :) – Lundin May 08 '17 at 14:48
-
isn't there a retrocomputing site on SO? you may have better luck there (still on-topic on SO until they burninate MS-DOS tag though) – Jean-François Fabre May 08 '17 at 15:04
-
6Is it an 8" or 5" drive? :)) – ThingyWotsit May 08 '17 at 15:10
-
3 1/2" drive ... – Kamila Szewczyk May 08 '17 at 15:14
-
1why do you need to write a new program in DOS? in many cases https://retrocomputing.stackexchange.com/ would provide better results – phuclv May 08 '17 at 15:19
-
@LưuVĩnhPhúc If i would post same question on retrocomputing, wouldn't it be bad? – Kamila Szewczyk May 08 '17 at 15:23
-
3You'd have the same problem on USB sticks. Can you change the BIOS so that it does not boot from removable media? – cup May 08 '17 at 15:25
-
Please enlighten me how can in modify bios using C – Kamila Szewczyk May 08 '17 at 15:27
-
1@KrzysztofSzewczyk : He clearly intended "change the BIOS _configuration_, not the BIOS itself". It is probably simplest to instruct the user to remove the installation disk and expect them to do it; after all even if you detected removal, you cannot prevent reinsertion at any time after. In principle it is the user's PC; if you changed the BIOS configuration programatically I'd be very concerned if it were my PC - that is not your business. Besides such a feature is not standard - different BIOS manufacturers may implement boot sequencing differently. – Clifford May 08 '17 at 15:41
-
2I had the same problem with a punch tape reader a while back... – Paul R May 08 '17 at 15:51
2 Answers
1
Possibly BIOS INT 13H 16H: Detect Media Change - it has a status:
80H = diskette drive not ready or not installed
Which may solve your problem - I lack the antique hardware and software to test it personally.
#include <dos.h>
unsigned int DetectMediaChange()
{
union REGS regs;
regs.h.ah = 0x16; // Detect Media Change
regs.h.dl = 0; // Drive A
int86( 0x13, ®s, ®s ); // BIOS Disk I/O INT 13h
return regs.h.ah ; // Status : 00H = diskette change line not active
// 01H = invalid drive number
// 06H = either change line is not supported or
// disk change line is active (media was swapped)
// 80H = diskette drive not ready or not installed
// else= BIOS disk error code if CF is set to CY
}

Clifford
- 88,407
- 13
- 85
- 165
-
-
1@KrzysztofSzewczyk : I have added C code; but it is derived from antique code found on the Internet for other DOS/BIOS services; I have not tested it. Whether it works on a virtual machine depends entirely on the completeness of the virtualisation; since the BIOS is probably fundamental to may things working, one would imagine that it is complete and would therefore work. For you to try, not me to know. – Clifford May 08 '17 at 15:15
-
1@KrzysztofSzewczyk : What makes you think that? I would imagine `0x80` as per the comment and the link referenced. But it depends what "not ready" means I guess - it is rather poorly documented. 0x06 occurs I believe when the "door" is operated (disk insert, possibly disk eject, but you would hope 0x80 would prevail in that event). I suggest you are in the best position to try this and care more than I do. Just suck it and see! – Clifford May 08 '17 at 15:18
-
Okay. I've inserted disk and it returned 6, took disk and returned 6. Broken. – Kamila Szewczyk May 08 '17 at 15:21
-
The "changed" status is only reset to zero on a valid disk access, so insert, access, eject. However you would get that result too if you ejected and immediately reinserted. Also "change line is not supported" is an allowed option and would generate that result - not "broken", just not implemented, or does not do what you need. I had hoped for a 0x80 on no media. – Clifford May 08 '17 at 15:25
-
That's okay then, but i need real-time information about diskette is inserted, "at the moment". – Kamila Szewczyk May 08 '17 at 15:26
-
If you can, simpler perhaps to prevent diskette media booting in the BIOS configuration. – Clifford May 08 '17 at 15:27
-
from my place it's impossible. I've heard about an interrupt that can disable it. I'll check out what exactly interrupt is it – Kamila Szewczyk May 08 '17 at 15:28
-
Sorry that was by best stab and software archaeology - I have nothing more for you at present. I doubt you can disable it from an S/W interrupt since it occurs on boot up - it needs a modification of the battery backed CMOS memory containing the BIOS configuration (and may not even be supported). – Clifford May 08 '17 at 15:30
-
I think `Int 2F/4A00` relates to swapping drive A/B on a single floppy machine. I am not sure how that will solve your problem. – Clifford May 08 '17 at 15:33
-
"Called by MS-DOS 5.0+ IO.SYS just before displaying the message "Insert diskette for drive X:" on single-floppy systems" and "FFFFh to skip "Insert diskette for drive X:" message" – Kamila Szewczyk May 08 '17 at 15:35
-
Yes but it still refers to "logical" not "physical" drives. See https://blogs.msdn.microsoft.com/oldnewthing/20090402-00/?p=18643 if it could not be done in Win95, I am pretty sure it was not a feature of MS-DOS either. – Clifford May 08 '17 at 15:36
1
Okay, I've figured it out:
char far * bufptr;
union REGS inregs, outregs;
struct SREGS segregs;
char buf [1024];
avaliable(){
redo:
segread(&segregs);
bufptr = (char far *) buf;
segregs.es = FP_SEG(bufptr);
inregs.x.bx = FP_OFF(bufptr);
inregs.h.ah = 2;
inregs.h.al = 1;
inregs.h.ch = 0;
inregs.h.cl = 1;
inregs.h.dh = 0;
inregs.h.dl = 0;
int86x(0x13, &inregs, &outregs, &segregs);
return outregs.x.cflag;
}
Returns true if disk is in drive.

Kamila Szewczyk
- 1,874
- 1
- 16
- 33