适用于某些类型操作的高效文件系统 API
我偶尔发现自己需要某些文件系统 API,如果文件系统支持的话,这些 API 可以非常有效地实现,但我从未听说过它们。例如:
- 在分配单元边界上从头开始截断文件 在分配单元边界
- 上将文件分成两个 在分配单元边界上
- 从文件中间插入或删除一个块
我知道的唯一方法做这样的事情就是将数据重写到一个新文件中。这样做的好处是分配单元不再相关,但与某些低级文件系统魔法相比速度非常慢。
我知道对齐要求意味着这些方法并不总是适用,但我认为它们仍然有用。例如,在用户从存档中删除文件后,文件存档器可能能够非常有效地修剪存档,即使由于对齐原因而在两侧留下少量垃圾。
这样的 API 真的不存在吗,还是我根本不知道它们?我最感兴趣的是 NTFS,但了解其他文件系统也会很有趣。
I occasionally find myself needing certain filesystem APIs which could be implemented very efficiently if supported by the filesystem, but I've never heard of them. For example:
- Truncate file from the beginning, on an allocation unit boundary
- Split file into two on an allocation unit boundary
- Insert or remove a chunk from the middle of the file, again, on an allocation unit boundary
The only way that I know of to do things like these is to rewrite the data into a new file. This has the benefit that the allocation unit is no longer relevant, but is extremely slow in comparison to some low-level filesystem magic.
I understand that the alignment requirements mean that the methods aren't always applicable, but I think they can still be useful. For example, a file archiver may be able to trim down the archive very efficiently after the user deletes a file from the archive, even if that leaves a small amount of garbage either side for alignment reasons.
Is it really the case that such APIs don't exist, or am I simply not aware of them? I am mostly interested in NTFS, but hearing about other filesystems will be interesting too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 NTFS 和 FAT 没有此类 API。显然,您可以截断文件的末尾,但不能截断开头。
由于文件系统缓存的原因,不建议这样做。
大多数时候,人们在 NTFS“之上”实现一个层来支持这一点。
For NTFS and FAT there are no such APIs. You can obvoiusly truncate the end a file but not the beginning.
Implementing this is unadvisable due to file system caching.
Most of the time people implement a layer "on top" of NTFS to support this.
Raymond Chen 基本上回答了这个问题。
他的回答是,不,这样的 API 不存在,因为对它们的需求太少了。 Raymond 还建议使用稀疏文件并通过将它们归零来取消使用块。
Raymond Chen has essentially answered this question.
His answer is that no, such APIs don't exist, because there is too little demand for them. Raymond also suggests the use of sparse files and decomitting blocks by zeroing them.