获取磁盘/集群号上的文件偏移量

axe*_*axe 5 windows file-io winapi ntfs

我需要获取有关文件在 NTFS 磁盘上物理位置的任何信息。绝对偏移量,集群 ID .. 任何东西。我需要扫描磁盘两次,一次获取分配的文件,另一次我需要直接在 RAW 模式下打开分区并尝试找到其余数据(来自已删除的文件)。我需要一种方法来理解我找到的数据与我之前作为文件处理的数据相同。当我以原始模式扫描磁盘时,我发现的数据的偏移量可以以某种方式转换为文件的偏移量(包含有关磁盘几何结构的信息)。有没有办法做到这一点?其他解决方案也被接受。现在我正在玩 FSCTL_GET_NTFS_FILE_RECORD,但目前无法使其工作,我不确定它会有所帮助。

更新

我发现以下函数 http://msdn.microsoft.com/en-us/library/windows/desktop/aa364952(v=vs.85).aspx 它返回包含 nFileIndexHigh 和 nFileIndexLow 变量的结构。文档说

The identifier that is stored in the nFileIndexHigh and nFileIndexLow members is called the file ID. Support for file IDs is file system-specific. File IDs are not guaranteed to be unique over time, because file systems are free to reuse them. In some cases, the file ID for a file can change over time.

我真的不明白这是什么。我无法将它连接到文件的物理位置。以后是否可以从 MFT 中提取此文件 ID?

更新

发现这个: This identifier and the volume serial number uniquely identify a file. This number can change when the system is restarted or when the file is opened.

这不能满足我的要求,因为我要打开文件,而 ID 可能会更改的事实并不让我高兴。

有任何想法吗?

Ray*_*hen 6

使用碎片整理 IOCTL。例如,FSCTL_GET_RETRIEVAL_POINTERS会告诉您包含文件数据的范围。