c - NtFsControlFile 在压缩时似乎无法处理 < 728 字节的文件

标签 c api winapi filesystems

我正在使用 SDelete System Internals 提供的应用程序以安全的方式删除文件,但遇到了一些文件未删除的问题。我设法获得了 SDelete 源代码,经过一番挖掘后,我发现问题只发生在使用文件系统压缩选项压缩的文件上,并且它们小于 728 字节。出错的代码行在这里:

    startVcn = 0;
    endOfPrevRun = LLINVALID;
    fileMappings = (PGET_RETRIEVAL_DESCRIPTOR) fileMap;
    while( !(status = NtFsControlFile( FileHandle, NULL, NULL, 0, &ioStatus, FSCTL_GET_RETRIEVAL_POINTERS, &startVcn, sizeof( startVcn ),fileMappings, FILEMAPSIZE * sizeof(ULONGLONG) ) ) 
        || status == STATUS_BUFFER_OVERFLOW 
        || status == STATUS_PENDING )

如果调用此函数并提供压缩文件的文件句柄且小于 728 字节,则返回值为 3221225489:“到达文件末尾”。

当应用程序首次编写时,这可能适用于较旧的文件系统(我使用的是 Windows 7),但我认为 Windows 7 中的更改导致此失败。

目前我已经通过调用 GetCompressedFileSize 函数解决了这个问题,如果文件太小,我会用垃圾填充它,直到它超过 728 字节。虽然这有效,但我想知道是否有人可以提出更好的方法,或者是否有 Windows 7 替代 NtFsControlFile

最佳答案

来自How NTFS Works :

Clusters Per MFT Record. The size of each record. NTFS creates a file record for each file and a folder record for each folder that is created on an NTFS volume. Files and folders smaller than this size are contained within the MFT.

另外:

NTFS creates a file record for each file and a folder record for each folder created on an NTFS volume. The MFT includes a separate file record for the MFT itself. These file and folder records are 1 KB each and are stored in the MFT. The attributes of the file are written to the allocated space in the MFT. Besides file attributes, each file record contains information about the position of the file record in the MFT. The figure MFT Entry with Resident Record shows the contents of an MFT record for a small file or folder. Small files and folders (typically, 900 bytes or smaller) are entirely contained within the file’s MFT record.

我想这就是您所看到的 - 文件数据完全位于 MFT 内部,而不存在于磁盘的“文件区域”中。

关于c - NtFsControlFile 在压缩时似乎无法处理 < 728 字节的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16697810/

相关文章:

c - 为什么会出现这个段错误?

c++ - 以编程方式连接到无线网络

ruby - Watir 是否在 ruby​​ 1.9.1 下工作?

c++ - 程序在 x64 中崩溃,在 Win32 中工作正常

c - 生成存储在数组中的 160 位字符串

c - 让 scanf 在读取换行符时退出?

c - 指示MAC地址长度的标准c宏?

php - 如何从 API 调用获取 POD 图像

facebook - 外部访问 Facebook 事件

c++ - 在 MFC 组合框中设置文本而不将其添加到列表中