1

我找到了以下解决方案来确定驱动器是否支持硬链接:

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.
    }
}

但是,根据MSDNFILE_SUPPORTS_HARD_LINKS ,直到 Windows Server 2008 R2 和 Windows 7 才支持该标志。

我还考虑过使用CreateHardLink()它来尝试创建一个虚拟硬链接。如果创建了硬链接,那么我知道可以在相应的驱动器上创建硬链接。但是,我可能没有访问该驱动器的权限。在这种情况下,我假设这种方法会失败。

有谁知道如何确定驱动器是否支持 Windows XP 中的硬链接而不需要对该驱动器的写访问权限?

4

1 回答 1

3

感谢所有评论员。我将您的建议放在一起,最终得到了以下解决方案。此解决方案也适用于 Vista:

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).
        }
    }
}

这个解决方案的好处是它 GetVolumeInformation()提供了所有必需的信息。

于 2014-04-09T15:50:25.107 回答