NTFS 和 $Object_ID 上的唯一文件标识符
从我在网上找到的文章来看,NTFS 上的文件似乎有两种形式的唯一标识符:
使用 Windows API GetFileInformationByHandle(),我们可以访问结构 BY_HANDLE_FILE_INFORMATION,其中包含卷序列号和低/高文件索引。 http://msdn.microsoft.com/en-us/库/aa363788(VS.85).aspx
$Object_ID - 文章 http://blogs.technet.com/b/askcore/archive/2010/08/25/ntfs-file-attributes.aspx 指出:
$OBJECT_ID – 这是保存 ID 的属性。该 ID 由分布式链接跟踪服务使用。如何使用它的示例可以在快捷方式中找到。在桌面上创建一个指向文件的快捷方式。然后移动该文件。该快捷方式仍然有效,因为它使用一种方法来定位源文件,而不仅仅是路径和文件名。
并非所有文件都有 $OBJECT_ID 属性。事实上,直到分配实际 ID 后,该属性才会添加到文件中。
我试图了解对象 ID 何时设置。这里有几个问题:
什么时候分配对象 ID?根据上面的文章,在一种情况下,当创建文件的快捷方式时会发生这种情况。
当一个文件引用另一个文件(例如嵌入 Visio 图表的 Word 文档)时,是否会自动分配对象 ID?
对象 ID 仅在启用/运行分布式链接跟踪时分配,还是无论分布式链接跟踪如何都存在?
如果我想跟踪文件的唯一标识符,使用对象 ID(64 字节)相对于组合卷序列号和文件索引(低/高)(12 字节)是否有任何优势合并起来。
谢谢,埃兰
From articles I have found online there appears to be two forms of unique identifiers for files on NTFS:
Using Windows API GetFileInformationByHandle(), we can get access to the struct BY_HANDLE_FILE_INFORMATION, which contains a volume serial number and a low/high file index.
http://msdn.microsoft.com/en-us/library/aa363788(VS.85).aspx$Object_ID - The article http://blogs.technet.com/b/askcore/archive/2010/08/25/ntfs-file-attributes.aspx states:
$OBJECT_ID – This is an attribute that holds an ID. This ID is used by the Distributed Link Tracking Service. An example of how it is used would be found in shortcuts. Make a shortcut on your desktop that points to a file. Then move that file. The shortcut will still function because it is using a way to tack the source file other than just the path and file name.
Not all files will have an $OBJECT_ID attribute. In fact, it isn’t until an actual ID is to be assigned that the attribute is added to the file.
I am trying to understand when the Object ID is set. Here are a few questions:
When does the Object ID get assigned? It would appear based on the above article that in one scenario this occurs when a shortcut to a file is created.
Does the Object ID get assigned automatically when a file references another file, e.g. a Word document, which embeds a Visio diagram?
Do Object IDs only get assigned when Distributed Link Tracking is enabled/running or do they exist regardless of Distributed Link Tracking?
If I wanted to track a unique identifier for a file, would there be any advantage for me to use the Object ID (64 bytes) over the combined volume serial number and file index (low/high), which are 12 bytes combined.
Thanks, Elan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这完全取决于您想要做什么。 :)
文件索引号,如文档所述,实际上只是 NTFS 中文件的一个很好的标识符(而不是 FAT),但即便如此,如果文件被删除并重新创建(想想备份/恢复),它也可能会发生变化,尽管您实际上可能会认为这是一个额外的好处,如果您我们希望区分这些。
最好不要担心与对象 ID 相关的链接跟踪服务,而是将它们视为您可以创建/设置/读取,但同样仅在 NTFS 中。
对象 ID 有一些开销,而文件 ID 则没有。对于大多数应用程序,我可能最终会选择文件参考号(即使它们可能很脆弱)。
It All Depends On What You're Trying To Do. :)
The file index number, like the documentation says, is really only a good identifier for the file in NTFS (as opposed to FAT), but even then it can change if the file is deleted and recreated (think backup/restore), though you might actually consider that a bonus if you were looking to distinguish those.
It's probably best not to worry about the link tracking service with regard to object IDs, and instead think of them as something you can create/set/read, though again only in NTFS.
Object IDs have some overhead, whereas file IDs do not. For most applications, I would probably end up picking file reference numbers (even though they are potentially fragile).
我想我会把这个放在这里,供像我这样研究 FRN 和 OBJECTID 的人使用。对于单个文件系统上的目录(文件恢复除外),这些 ID 可能是稳定的,但是当您使用许多不同的应用程序保存并关闭文件时,FRN 和 ObjectID 都会发生变化。
例如,如果您打开一个 FRN#: 1000 的 Word 文件,并且指定了 OBJECTID: 8675309,则当您进行更改时,保存并关闭它。 FRN# 将是一个新号码,并且不会有 ObjectID。
下面我做了一个简单的打开、更改段落中的文本、保存和关闭Word文件的操作。有超过52个事件,在我的程序中,我已经过滤掉了所有涉及的
~WRL*tmp
文件等。但即使在具有相同文件的同一文件系统上,FRN 也不是一个恒定的东西。我目前没有显示 ObjectID,但请相信我,当您分配一个、打开此文件并保存它时,它本质上是一个新文件。USN 日志输出示例,第一个数字是文件参考号,第二个是父文件参考号(稳定目录的 FRN)
Figured I would put this here for others like me researching
FRN
andOBJECTID
s. These IDs might be stable for directories (other than file restore) on a single file system, but both the FRN and the ObjectID will change as soon as you save and close a file with many different applications.For example, if you open a Word file with FRN#: 1000 and you have assigned OBJECTID: 8675309, when you make a change, save, and close it. The FRN# will be a new number and there will be no ObjectID.
In the following I did a simple open, make a change to text in a paragraph, save and close of a word file. There are more than 52 events, in my program, I have filtered out all the
~WRL*tmp
files, etc that are involved. But even on the same file system with the same files, FRN is not a constant thing. I do not have ObjectID showing at the moment but trust me when you assign one, open this file and save it, it is essentially a new file.Sample USN Journal output with the first number is the file reference number, the second is the Parent File Reference# (the FRN for the directory which is steady)