Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking for disk media

0 views
Skip to first unread message

Brian Dude

unread,
Jun 22, 2009, 3:39:04 PM6/22/09
to
Hello, I've been working on a text mode "open file" dialog box (just for
myself, so that I don't have to hardwire a file path). It's similar in
nature to the one in the Microsoft "Edit" program.
I'm using the ancient Borland C 4.52 compiler, and my file and directory
lists are built using findfirst()/findnext(). I just finished the drive
change portion, but if there are no files (like accessing the CD-ROM
drive with no disk) I get the default OS error message:

Not ready reading drive X:
Abort, Retry, Fail?

I can't seem to find any functions in the libraries that simply let me
check what's on disk (if anything) ahead of time so that I can issue my
own message. Any suggestions?

TIA,
Brian Dude

Sjouke Burry

unread,
Jun 22, 2009, 3:48:01 PM6/22/09
to
system("dir /b/s > listoffiles.txt");

should give you a list of filenames?

Brian Dude

unread,
Jun 22, 2009, 5:49:07 PM6/22/09
to

Well, it's not building the list that's difficult; it's looking to
suppress the "Not ready reading drive X:" message. I'm looking to
somehow find out what's on a drive, and if there's nothing, skip the
call to findfirst(). Because somewhere in that call is where the message
comes up, but thank you for the response.

Ted Davis

unread,
Jun 22, 2009, 8:08:42 PM6/22/09
to

This might work

system("if not exist x: exit 1")

It should work in newer OSs - it really helps to know which one you are
programming for. If you don't identify the OS, we can only assume you
want code for the OS you posted from, if that can be determined from the
message headers.

--

T.E.D. (tda...@mst.edu) MST (Missouri University of Science and Technology)
used to be UMR (University of Missouri - Rolla).

pe...@nospam.demon.co.uk

unread,
Jun 23, 2009, 1:09:52 AM6/23/09
to
In article <t5R%l.10322$cz1....@newsfe17.iad>
aa...@hotSPAM.com "Brian Dude" writes:

> Hello, I've been working on a text mode "open file" dialog box (just for
> myself, so that I don't have to hardwire a file path). It's similar in
> nature to the one in the Microsoft "Edit" program.
> I'm using the ancient Borland C 4.52 compiler, and my file and directory
> lists are built using findfirst()/findnext(). I just finished the drive
> change portion, but if there are no files (like accessing the CD-ROM
> drive with no disk) I get the default OS error message:
>
> Not ready reading drive X:
> Abort, Retry, Fail?
>
> I can't seem to find any functions in the libraries that simply let me
> check what's on disk (if anything) ahead of time so that I can issue my
> own message. Any suggestions?

Judging by the version of BC you're using, this code is for real
DOS, so what you need to do is to intercept the Critical Error
vector (0x24) and set AX = 0 there if/when its handler gets
called when calling a DOS service that could invoke it.

Something like:

get CritErr vector (DOS service 0x3524) and save for later
install your own handler (DOS service 0x2524) that consists
simply of two lines MOV AX,0 ; IRET ;
call DOS "get drive space" service (AH = 0x36, DL = drive)
and save the return value (0xFFFF == failure)
reset the CritErr vector back to its original value

If the drive space call failed, there was no media present, so
skip the findfirst()/next() calls for this drive.

I think I have some ASM code for this somewhere, but with BC's
interrupt support and int86()/intdos() you should figure it out
quickly. RBIL might help too.

Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."

Benjamin David Lunt

unread,
Jun 23, 2009, 12:46:12 PM6/23/09
to

"Brian Dude" <aa...@hotSPAM.com> wrote in message
news:t5R%l.10322$cz1....@newsfe17.iad...

Something like
http://www.frontiernet.net/~fys/getdrvs.htm
or
http://www.frontiernet.net/~fys/chkdsk.htm

might be useful.

Ben

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Forever Young Software
http://www.frontiernet.net/~fys/index.htm
http://www.frontiernet.net/~fys/collections.htm
To reply by email, please remove the zzzzzz's

Batteries not included, some assembly required.


Alex Russell

unread,
Jun 23, 2009, 8:49:00 PM6/23/09
to


The basic idea is to make a lower level bios call, not a dos call, tp
check if the disk is ready. For example, read one sector from track
zero, head zero, cylinder zero.


This code has some inline asm, but you could fix it up to use int86()
calls most likely. This is REAL old code that assumes if c and d exist
they must be ready! After all, only a floppy could not be read.

Written using Borland c/c++ 3.01

/* ---------------------- disk_exist() ----------------- January 31,1992 */
int disk_exist(int drive_letter)
{
unsigned char drive_number, w;
int old_drive, ok;

drive_number=drive_letter - 'A';
if ( drive_number < 2 )
{
geninterrupt(0x11);
w=_AX;
w&=192; /* mask off all bits except 6 & 7 which indicate the
number of floppies installed */
if ( drive_number == 1 && w == 0 )
ok=0;
else
ok=1;

}
else
{
old_drive=getdisk();

setdisk(drive_number);

if ( getdisk() == drive_number )
ok=1;
else
ok=0;

setdisk(old_drive);
}

return(ok);
}


/* ---------------------- disk_ready() ----------------- January 31,1992 */
int disk_ready(int drive_letter)
{
int ok, i, j;
union REGS in, out;
unsigned char drive_number;
char *t1;

if ( disk_exist(drive_letter) )
{
drive_number=(unsigned char)(drive_letter - 'A');
if ( drive_number > 1 )
{
drive_number-=2;
drive_number+=0x80;
}

if ( drive_number < 2 ) /* floppy only */
{
ok=0;
t1=malloc(2048);
for ( j=0; j < 2 && !ok; j++ )
{
ok=1;
i=0;
while ( ok && i < 2 )
{
/* read 1 sectors thru bios */
_AH=0x02;
_AL=1;
_DL=drive_number;
_DH=0;
_CH=0;
_CL=1;
_ES=FP_SEG(t1);
_BX=FP_OFF(t1);

geninterrupt(0x13);

if ( _FLAGS & 1 ) /* carry set */
ok=0;
else
ok=1;

i++;
}

/* reset disk */
in.h.ah=0x00;
in.h.dl=drive_number;

int86(0x13, &in, &out);
in.h.ah=0x00;
in.h.dl=drive_number;

int86(0x13, &in, &out);
}

free(t1);
}
else
{
ok=1; /* C: and D: are always ready */
}
}
else
{
ok=0;
}

return(ok);

}

// CD's appear as remote
/* ---------------------- is_remote_drive() ---------- December 26,1995 */
int is_remote_drive(int drive_letter)
{
int is_remote=0;
union REGS in, out;

in.h.ah=0x44;
in.h.al=0x9; // local / remote test
in.h.bl=drive_letter - 'A' + 1;

int86(0x21, &in, &out);

if ( out.x.cflag )
{
is_remote=-1;
}
else
{
if ( out.x.dx & 4096 )
is_remote=1;
}

return(is_remote);
}

Alex R

Brian Dude

unread,
Jun 23, 2009, 9:05:04 PM6/23/09
to

Ahh! Intercepting the Critical Error vector seems to do the trick. I
haven't had time to implement it how I want, but I threw together a
quick program to try it out. It looks promising!

Thank you!

Richard Bonner

unread,
Jul 9, 2009, 8:09:20 PM7/9/09
to
Brian Dude (aa...@hotSPAM.com) wrote:
> Sjouke Burry wrote:

> > Brian Dude wrote:
> >> Hello, I've been working on a text mode "open file" dialog box (just
> >> for myself, so that I don't have to hardwire a file path).

(Snip)

> >> I just
> >> finished the drive change portion, but if there are no files (like
> >> accessing the CD-ROM drive with no disk) I get the default OS error
> >> message:
> >>
> >> Not ready reading drive X:
> >> Abort, Retry, Fail?
> >>
> >> I can't seem to find any functions in the libraries that simply let me
> >> check what's on disk (if anything) ahead of time so that I can issue
> >> my own message. Any suggestions?
> >>

> >> Brian Dude

> > system("dir /b/s > listoffiles.txt");
> >
> > should give you a list of filenames?

> Well, it's not building the list that's difficult; it's looking to
> suppress the "Not ready reading drive X:" message. I'm looking to
> somehow find out what's on a drive, and if there's nothing, skip the
> call to findfirst(). Because somewhere in that call is where the message
> comes up, but thank you for the response.

*** I'm not a programmer so I may be off base here, but Marc Stern may
have done what you want in his "XSET" program. It has a "DRIVETEST"
feature. His site is at:

http://xset.tripod.com/

Perhaps he might have a suggestion.


Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

0 new messages