且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取带有boost :: filesystem的inode?

更新时间:2023-11-11 23:05:46

stat 的Windows CRT实现始终为inode使用零,因此您必须自己滚动。这是因为在Windows上 FindFirstfile GetFileInformationByHandle 更快,因此 stat 使用 FindFirstFile ,它不包括inode信息。如果你不需要inode,那是伟大的,性能胜利。

The Windows CRT implementation of stat always uses zero for the inode, so you will have to roll your own. This is because on Windows FindFirstfile is faster than GetFileInformationByHandle, so stat uses FindFirstFile, which does not include the inode information. If you don't need the inode, that's great, performance win. But if you do, the following will help.

相当于INODE的NTFS是MFT记录号,也称为文件ID。它有稍微不同的属性,但在一个误差范围内可以用于与INODE相同的目的,即标识两个路径是否指向同一个文件。

The NTFS equivalent to the INODE is the MFT Record Number, otherwise known as the file ID. It has slightly different properties, but to within a margin of error can be used for the same purposes as the INODE, i.e. identifying whether two paths point to the same file.

您可以使用 GetFileInformationByHandle GetFileInformationByHandleEx 检索此信息。您将首先调用 CreateFile 以获取文件句柄。

You can use GetFileInformationByHandle or GetFileInformationByHandleEx to retrieve this information. You will first have to call CreateFile to obtain the file handle.


  • 您需要 FILE_READ_ATTRIBUTES 权限才能获取文件ID。

  • 您应指定 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE

  • c> OPEN_EXISTING 作为处置。

  • You need FILE_READ_ATTRIBUTES rights only to get the file ID.
  • You should specify FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE
  • You should specify OPEN_EXISTING as the disposition.

一旦你有句柄,使用GetFileInformation函数获取文件ID,然后关闭句柄。

Once you have the handle, use one of the GetFileInformation functions to obtain the file ID, then close the handle.

您需要的信息可在 BY_HANDLE_FILE_INFORMATION nFileIndexLow nFileIndexHigh 成员或如果使用ReFS,则可能正在使用128位文件ID。要获得此功能,您必须使用更新的功能。

This information you need is available in the BY_HANDLE_FILE_INFORMATION nFileIndexLow and nFileIndexHigh members or if ReFS is in use, then a 128 bit file ID may be in use. To obtain this you must use the updated function.