cdosdjgpp

Non-interactive drive listing in DOS


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.


Solution

  • 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);
    }