找出两个句柄是否是到同一文件的硬链接 [英] Find Out If Two HANDLEs are Hardlinks to the Same File

查看:198
本文介绍了找出两个句柄是否是到同一文件的硬链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(此问题是个棘手的问题,它可能需要了解NTFS和/或使用NT本机API;应予以警告.):)

(This question is a toughie... it might require knowledge of NTFS and/or the use of NT Native APIs; be warned.) :)

如果我给两个文件两个HANDLE,我如何确定性地(不仅很有可能)找出两个HANDLE是否完全属于同一文件并流到磁盘上?

If I'm given two HANDLEs to two files, how can I definitively (not just with high probability) find out if the two HANDLEs belong to the exact same file and stream on the disk?

这意味着,例如,仅检查8字节的NTFS文件ID是不够的,因为具有相同文件ID的两个HANDLE可以指向同一文件的不同数据流,因此我需要查找如果两个流确实相同并且仅在名称(硬链接)上有所不同,则显示出来.

This means, for example, checking the 8-byte NTFS file IDs isn't enough, because two HANDLEs with the same file ID can be pointing to different data streams of the same file, and I need to find out if the two streams are really the same and only differ by the name (hardlink).

(有什么用?这样,如果我要对文件夹内的所有文件执行操作,就不会对具有不同名称的同一数据流执行两次该操作.)

(What's the use? This way, if I want to perform an operation on all files inside a folder, I don't do the operation twice on the same data stream with different names.)

推荐答案

这需要 GetFileInformationByHandleEx (),询问FileStreamInfo.返回流名称.

This requires GetFileInformationByHandleEx(), asking for FileStreamInfo. That returns the stream name.

应注意SDK文档中的此警告:

This warning in the SDK docs should be noted:

某些文件信息类 在行为上略有不同 不同的操作系统版本. 这些类由 基础驱动程序,以及任何 他们返回的信息受制于 在操作系统之间切换 发布.

Certain file information classes behave slightly differently on different operating system releases. These classes are supported by the underlying drivers, and any information they return is subject to change between operating system releases.

避免依赖恢复程序中已经(或应该)容易获得的信息.

Avoid relying on recovering info that is (or should be) readily available in your program.

这篇关于找出两个句柄是否是到同一文件的硬链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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