Question

I found the following solution to determine whether a drive supports hard links:

CString strDrive = _T("C:\\");
DWORD dwSysFlags;
if(GetVolumeInformation(strDrive, NULL, 0, NULL, NULL, &dwSysFlags, NULL, 0))
{
    if((dwSysFlags & FILE_SUPPORTS_HARD_LINKS) != 0)
    {
        // Hard links can be created on the specified drive.
    }
    else
    {
        // Hard links cannot be created on the specified drive.
    }
}

However, according to MSDN the flag FILE_SUPPORTS_HARD_LINKS is not supported until Windows Server 2008 R2 and Windows 7.

I also thought about using CreateHardLink() in order to try to create a dummy hard link. If the hard link is created then I know that creating hard links on the corresponding drive is possible. However, it may happen that I have no access rights to the said drive. In this case I assume that this method would fail.

Does anybody know how to determine whether a drive supports hard links in Windows XP without requiring write access to that drive?

Was it helpful?

Solution

Thanks to all the commentators. I put your suggestions together and ended up with the following solution. This solution should work for Vista as well:

CString strDrive = _T("C:\\");
DWORD dwSysFlags;

TCHAR szFileSysName[1024];
ZeroMemory(szFileSysName, 1024);

if(GetVolumeInformation(strDrive, NULL, 0, NULL, NULL, &dwSysFlags, szFileSysName, 1024))
{
    // The following check can be realized using GetVersionEx().
    if(bIsWin7OrHigher())
    {
        if((dwSysFlags & FILE_SUPPORTS_HARD_LINKS) != 0)
        {
            // Hard links can be created on the specified drive.
        }
        else
        {
            // Hard links cannot be created on the specified drive.
        }
    }
    else
    {
        if(_tcsicmp(szFileSysName, _T("NTFS")) == 0)
        {
            // Hard links can be created on the specified drive.
        }
        else
        {
            // Hard links cannot be created on the specified drive (maybe).
        }
    }
}

The nice thing about this solution is that GetVolumeInformation() provides all required information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top