 Sample: Determining Drive and File System Type

Summary:

A demonstration of how the GetDriveType and
GetVolumeInformation functions determine all logical drives
on a system, their disk type (local, remote, CD-ROM, and so
on), and their file system type (FAT, HPFS, and so on) is
available in a sample file named DRIVES.

More Information:

The additional API functions, GetLogicalDrives and
GetLogicalDriveStrings, are not required to determine the
drive and file system type, but are included as an example
of how these API functions can enhance the efficiency of
disk querying API calls.

When a drive type is removable (for example, a floppy disk
drive), then additional precautions are taken before
accessing this drive. A validation check is made to see if
media exists in the drive before proceeding. A simple test
of opening any file in the root directory of the removable
media drive using the OpenFile API function determines the
media's presence. If the OpenFile call returns a handle,
then media is present and further disk querying calls are
safely made on the logical drive. If the OpenFile call
fails, then no media is present and no further attempts to
query this drive are allowed. Note: in order to eliminate an
unwanted pop-up, prompting the user to insert a disk in the
drive, from being generated by the operating system, the
error mode is temporarily adjusted, using SetErrorMode, to
allow any OpenFile errors to immediately return to the
calling routine.
