c++ - Windows XP中如何判断一个驱动器是否支持硬链接(hard link)?

标签 c++ windows mfc hardlink

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

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

然而,根据MSDN在 Windows Server 2008 R2 和 Windows 7 之前,不支持标志 FILE_SUPPORTS_HARD_LINKS

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

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

最佳答案

感谢所有评论员。我将您的建议放在一起并得出以下解决方案。此解决方案也适用于 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()提供所有必需的信息。

关于c++ - Windows XP中如何判断一个驱动器是否支持硬链接(hard link)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22878702/

相关文章:

Windows 中依赖重叠 io 的编码模式

c++ - MFC 消息队列限制

c++ - 我的日志记录模块线程安全吗?

c++ - 在 QT 中,我们可以有两个名称相同但参数不同的插槽吗?

c++ - 写入套接字时使用 write() 而不是 send() 的性能影响

C++ 错误 : trying to understand Classes and Constructors

c++ - 查找函数链以获得所需的输出

php - "get_current_user()"函数可以在 Linux/OSX 上运行吗?

c++ - winapi - 未记录的 Windows 消息 0x0313 是否稳定?

visual-studio-2008 - 从外部成员类访问 MFC 对话框元素