BUG: GetDriveType Returns DRIVE_NO_ROOT_DIR for the Mount Point of an Empty Removable Media

This article was previously published under Q244089
This article has been archived. It is offered "as is" and will no longer be updated.
SYMPTOMS
GetDriveType incorrectly returns DRIVE_NO_ROOT_DIR when its parameter is the mount point of an empty removable drive.
RESOLUTION
As a workaround, you can use the GetVolumeNameForVolumeMountPoint function to obtain the actual drive name for the mount point, and then call GetDriveType on that. The following sample code demonstrates this workaround:
// Compiling for Windows 2000#define _WIN32_WINNT    0x0500 #include <windows.h>#include <tchar.h>#include <stdio.h>ULONGGetMountPointDriveType(LPCTSTR lpRootPathName){    _TCHAR lpszVolumeName[_MAX_PATH];    SetLastError(ERROR_SUCCESS);    if (lpRootPathName == NULL)    {        return GetDriveType(NULL);    }     else if (!GetVolumeNameForVolumeMountPoint(lpRootPathName,         lpszVolumeName, _MAX_PATH))    {        return DRIVE_NO_ROOT_DIR;    }    return GetDriveType(lpszVolumeName);}void _tmain(int argc, _TCHAR *argv[]){    if (argc != 2)     {        _tprintf(_T("Usage: %s PATHNAME\n"), argv[0]);        return;    }    switch (GetMountPointDriveType(argv[1]))    {    case DRIVE_UNKNOWN:           _tprintf(_T("The drive type cannot be determined.\n"));       break;    case DRIVE_NO_ROOT_DIR:       _tprintf(_T("The root path is invalid.\n"));       break;    case DRIVE_REMOVABLE:         _tprintf(_T("The disk can be removed from the drive.\n"));       break;    case DRIVE_FIXED:             _tprintf(_T("The disk cannot be removed from the drive.\n"));       break;    case DRIVE_REMOTE:            _tprintf(_T("The drive is a remote (network) drive.\n"));       break;    case DRIVE_CDROM:             _tprintf(_T("The drive is a CD-ROM drive.\n"));       break;    case DRIVE_RAMDISK:           _tprintf(_T("The drive is a RAM disk.\n"));       break;    default:                      _tprintf(_T("BUG: Unrecognized drive type\n"));       break;    }}				
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
REFERENCES
For more information about mount points, see the following Web site:
Properties

Article ID: 244089 - Last Review: 02/28/2014 00:28:58 - Revision: 5.2

  • Microsoft Win32 Application Programming Interface
  • kbnosurvey kbarchive kbapi kbbug kbfileio kbkernbase kbpending KB244089
Feedback