当链接计数为2时,有没有办法完全删除一个inode?
目前,我的数据组织在一个具有缓存目录的卷中(所有文件首先在其中创建或传输)。之后,卷上有合适的目录,其子目录中包含硬链接到缓存中的文件的文件。 这样做是为了可以在多个目录中多次硬链接同一个 inode(文件)。
现在,当尝试清理卷时,我递归地遍历目录(而不是缓存)并根据特定标准取消链接文件(这基本上将缓存条目的 inode 计数减少 1)。当我删除最后一个硬链接时(即将计数从 2 减少到 1),有没有办法直接删除缓存条目。这样我就不必手动解析整个缓存目录来清除其中的任何索引节点,这些索引节点的链接计数仅为 1。
我已经完成了取消链接/删除功能,但找不到任何特定的用途。是否有一些内部处理此问题的清除算法,然后我可以尝试实现它。
对此的任何帮助将不胜感激。期待及时答复。
Currently my data is organised in a volume which has a cache directory (where all the files are first created or transferred). After that there are suitable directories on the volume which in their subdirs, contain files hardlinked to files in the cache.
This is done so that the same inode (file) can be hardlinked multiple times in multiple directories.
Now when trying to clean up the volume, I recurively go through the dirs(not the cache) and based on certain criterion, unlink the files (which basically reduces the inode count of the cache entry by 1). Is there a way for me to delete the cache entry directly, when I am deleting the last hardlink (that is bringing down the count from 2 to 1). This way I would not have to manually parse through the whole cache directory to clear any inodes from it, which have a link count of just 1.
I have gone through unlink/remove functions, and could not find anything specific of use. Is there some purging algorithm that internally takes care of this, then I can try to implement that.
Any help on this would be highly appreciated. In anticipation of a prompt reply.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看到这个以及其他一些地方指导您如何从 shell 中删除所有硬链接(使用 find -samefile 并在每个文件上调用删除)。你可以通过系统调用它,尽管这可能会被一些人皱眉)。
I saw this and a few other places which instruct you how to delete all hardlinks from shell (use find -samefile and call remove on each file). You could call it via system although that might be frowned on by some people).
不,没有任何东西可以开箱即用地满足您的需求。
当取消链接硬链接并注意到链接计数为 1 时进行删除可能很有用,因为此时 inode 应该位于页面缓存中;这当然取决于知道缓存目录中文件的名称。
No, there isn't anything that does what you want out of the box.
It might be useful to do the deletion when unlinking the hardlink and noticing that the link count is 1, since at that point the inode should be in the page cache; this of course is dependent on knowing the name of the file in the cache directory.