gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:29:57 26 4
gpt4 key购买 nike

我找到了以下解决方案来确定驱动器是否支持硬链接(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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com