2

I'm trying to get a list of all available drives from a C program in DOS (and I don't mean the Windows command prompt, I mean actual DOS 6.0) using the DJGPP C compiler.

I can't find an API to do this directly, so I'm just looping through the drives A through Z and trying to test if they're there. I've tried doing this test using opendir, access and statfs, but in all 3 I get messages like this:

Insert diskette for drive B: and press any key when ready

Is there any way I can find out whether I can read from a drive entirely non-interactively? If there's a drive present without a disk loaded, I just want to be able to behave as if that drive didn't exist and carry on.

Daisy Leigh Brenecki
  • 7,571
  • 6
  • 28
  • 43

2 Answers2

1

So, just shortly after posting this, I discovered that there is actually an API to do what I want to do directly, using setmntent and getmntent.

Here's a code sample:

FILE *mntentptr = setmntent(NULL, NULL); // this won't segfault as DJGPP ignores both pointers
struct mntent *fsdetails;
while (fsdetails = getmntent(mntentptr)){
    printf("Drive %s is present", fsdetails->mnt_dir);
}
Daisy Leigh Brenecki
  • 7,571
  • 6
  • 28
  • 43
0

You need to use IOCTL Query Logical Drive Map to check which logical drive it is associated with. I'm not familar with how that maps to standard C library calls, but you should be able to do it via the INT call directly in DOS.

Dwayne Towell
  • 8,154
  • 4
  • 36
  • 49