Hardlinks are not permitted because they would lead to cycles. Once you allow cycles to form, you must perform a mark-and-sweep garbage collection to detect when isolated cycles of directories (no longer reachable from the root) can be finally deleted - this is extremely expensive on disk.
Soft links do not cause this problem because they do not raise the reference count of the targeted directory; thus you can still get away with reference counting (with a maximum of one reference :).
The other issue is that programs which traverse the file system (eg, find) need to avoid cycles. They could do this by remembering every inode number they've seen, but this is expensive - if they can distinguish between links which could lead to cycles (ie, softlinks) and links which will not lead to cycles (normal directory entries), and skip the softlinks, they don't need to track inode numbers anymore.
发布评论
评论(1)
不允许使用硬链接,因为它们会导致循环。一旦允许循环形成,您必须执行标记和清除垃圾收集,以检测何时可以最终删除目录的孤立循环(不再可从根访问) - 这在磁盘上非常昂贵。
软链接不会导致这个问题,因为它们不会增加目标目录的引用计数;因此,您仍然可以摆脱引用计数(最多一个引用:)。
另一个问题是遍历文件系统的程序(例如,
find
)需要避免循环。他们可以通过记住他们见过的每个索引节点号来做到这一点,但这很昂贵 - 如果他们能够区分可能导致循环的链接(即软链接)和不会导致循环的链接(普通目录条目),并跳过软链接,它们不再需要跟踪 inode 编号。Hardlinks are not permitted because they would lead to cycles. Once you allow cycles to form, you must perform a mark-and-sweep garbage collection to detect when isolated cycles of directories (no longer reachable from the root) can be finally deleted - this is extremely expensive on disk.
Soft links do not cause this problem because they do not raise the reference count of the targeted directory; thus you can still get away with reference counting (with a maximum of one reference :).
The other issue is that programs which traverse the file system (eg,
find
) need to avoid cycles. They could do this by remembering every inode number they've seen, but this is expensive - if they can distinguish between links which could lead to cycles (ie, softlinks) and links which will not lead to cycles (normal directory entries), and skip the softlinks, they don't need to track inode numbers anymore.