[英]How to determine whether a drive supports hard links in Windows XP?
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. 但是,根据MSDN,在Windows Server 2008 R2和Windows 7之前不支持标志
FILE_SUPPORTS_HARD_LINKS
。
I also thought about using CreateHardLink()
in order to try to create a dummy hard link. 我还考虑过使用
CreateHardLink()
来尝试创建虚拟硬链接。 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? 有没有人知道如何确定驱动器是否支持Windows XP中的硬链接而无需对该驱动器进行写访问?
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:
此解决方案也适用于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).
}
}
}
The nice thing about this solution is that GetVolumeInformation()
provides all required information. 这个解决方案的
GetVolumeInformation()
是GetVolumeInformation()
提供了所有必需的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.