PRB: GetVolumeNameForVolumeMountPoint API may return Incorrect Name for Volumes with Multiple Names

Article translations Article translations
Close Close
Article ID: 959573 - View products that this article applies to.
Expand all | Collapse all
Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Symptom

On Windows, every volume is assigned a unique volume name in the format \\Volume\{GUID}\, where the GUID uniquely identifies that volume.  Under certain circumstances described in the "More Information" section, it is possible for a volume to be assigned multiple unique volume names and thus be assigned multiple GUIDs.  When this happens, the GetVolumeNameForVolumeMountPoint() Win32 API function will return one of the assigned names, but it may return a name which cannot be used.

Cause



This problem is caused by a bug in the GetVolumeNameForVolumeMountPoint Win32 API function on the products listed in the "Applies to" section of this article.  It occurs only for volumes that have been assigned multiple unique volume names (GUIDs).

The problem has been corrected in the following products:
  • Windows Server 2008  -- All versions
  • Windows Vista Service Pack 1


 

Resolution



Applications that must run on the affected products can work around this bug in one of two ways.  The first is to open the volume with the CreateFile Win32 function and then calling the DeviceIoControl function to issue the IOCTL_MOUNTMGR_QUERY_POINTS command. 

The second way is by calling GetVolumeNameForVolumeMountPoint twice.  In the first call, pass the target volume name as documented (usually as a the drive letter in the format X:\) in the lpszVolumeMountPoint parameter.  This call will return one of the assigned unique volume names in the lpszVolumeName parameter.  In the second call, pass the volume name returned by the first call in the lpszVolumeMountPoint parameter.  This will cause GetVolumeNameForVolumeMountPoint to return the expected volume name.

The sample below to see how you might call GetVolumeNameForVolumeMountPoint() twice to get the expected results. 

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

int _tmain(int argc, TCHAR* argv[])
{

    TCHAR szGUID1 [MAX_PATH];
    TCHAR szGUID2 [MAX_PATH];

    if (argc != 2)
    {
        wprintf(L"%s <x:\\> \n\n", argv[0]);
        return 0;
    }

    _tprintf(TEXT("Calling GetVolumeNameForVolumeMountPoint for %s\n"), argv[1]);

    // On the first call to GetVolumeNameForVolumeMountPoint
    // pass in whatever you would normally pass in
    if (GetVolumeNameForVolumeMountPoint(argv[1], szGUID1, MAX_PATH))
    {
        _tprintf(TEXT(" GUID1: %s\n\n"), szGUID1);
    }

    // On the second call, pass in the Volume Name received from the first
    // call to GetVolumeNameForVolumeMountPoint
    if (GetVolumeNameForVolumeMountPoint(szGUID1, szGUID2, MAX_PATH))
    {
        _tprintf(TEXT(" GUID2: %s\n\n"), szGUID2);
    }
    return 0;
}

CreateFile, DeviceIoControl, and IOCTL_MOUNTMGR_QUERY_POINTS are documented in the MSDN Library on http://msdn.microsoft.com.

More Information



A volume can be multiple unique volume names (and thus multiple GUIDs) when it is used by multiple running installations of Windows.  This could happen in the following scenarios and in similar scenarios where multiple installations of Windows have accessed the volume:
  • Dual booting two or more copies of Windows which access the drive.
  • Using a volume on a shared disk in a cluster where multiple nodes have accessed the volume.
  • Moving the disk which hosts the volume from one computer to another.
  • In a SAN environment where the volume was assigned to multiple instances of Windows.


In these situations, each running instance of Windows will assign its own GUID to the volume.  Furthermore, each instance will enumerate all of the volume names and mount points assigned to the volume and thus will see multiple GUIDs.  However, not all GUIDs may be used by the specific instance of Windows that is currently running.  This is why the volume name returned by GetVolumeNameForVolumeMountPoint may be "incorrect."

The MOUNTVOL.EXE tool always returns the correct volume name.

 

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

Properties

Article ID: 959573 - Last Review: November 4, 2008 - Revision: 1.0
APPLIES TO
  • Microsoft Windows Server 2003 Service Pack 1
  • Microsoft Windows Server 2003 Service Pack 2
  • Windows Vista Ultimate
  • Windows Vista Home Premium
  • Windows Vista Enterprise
  • Windows Vista Business
Keywords: 
kbnomt kbrapidpub KB959573

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com