如何获得与升压::文件系统索引节点? [英] How to get the inode with boost::filesystem?

查看:112
本文介绍了如何获得与升压::文件系统索引节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测是否我看见一个文件已,愿与独特的东西来标识它。在Linux下有这个inode与设备ID一起数(请参阅 STAT() FSTAT())。我想在Windows下我会找到类似的东西。

I want to detect if I saw a file already and would like to identify it with something unique. Under Linux there is the inode number together with the device id (see stat() or fstat()). I assume under Windows I would find something similar.

要启动容易,的boost ::文件系统提供便利的方法,例如我可以使用的boost ::文件系统:: recursive_directory_iterator 来遍历目录树。在 file_status 给我,如果它是一个普通的文件,但不是inode号。

To start easy, the boost::filesystem offers convenient methods, e.g. I can use boost::filesystem::recursive_directory_iterator to traverse the directory tree. The file_status gives me if it is a regular file, but not the inode number.

我发现的最接近的事情是的boost ::文件系统::当量()采取两条路径。我想这也是最便携的设计。

The closest thing I found was boost::filesystem::equivalent() taking two paths. I guess this is also the most portable design.

的事情是,我希望把inode编号到数据库中有一个快速查找。我不能用这个功能做到这一点,我会打电话给当量()与所有路径已在数据库中存在的。

The thing is that I would like to put the inode numbers into a database to have a quick lookup. I cannot do this with this function, I would have to call equivalent() with all paths already existing in the database.

我是出于运气和升压不会由于可移植性原因为我提供这样的信息?

Am I out of luck and boost will not provide me such information due to portability reasons?

(编辑)的目的是通过硬连接一个文件夹树的一次扫描过程中检测重复。 当量()正是这么做的,但我会做一个二次算法。

(edit) The intention is to detect duplicates via hardlinks during one scan of a folder tree. equivalent() does exactly that, but I would have to do a quadratic algorithm.

推荐答案

在Windows CRT实施与stat 始终使用零inode中,因此你必须滚你拥有。这是因为在Windows 用FindFirstFile GetFileInformationByHandle 更快,所以统计使用用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.

在NTFS相当于该inode的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

  • 您应该指定 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 成员或者如果裁判在使用,那么一个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.

这篇关于如何获得与升压::文件系统索引节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆