Why hard links are not allowed for directories on UNIX / Linux

I read in text books that UNIX / Linux does not allow hard links to directories, but soft links? Is it because when we have loops, and if we create hard links, will this point to some garbage values?

If loops were the only reason for refusing hard links, then why are program links allowed directories?

+7
source share
1 answer

Hard links are not allowed because they lead to loops. After you allow the creation of loops, you must perform garbage collection with a label and a scan to find out when the final deleted directory loops (no longer available from the root) can be deleted - this is very expensive on disk.

Linked links do not cause this problem because they do not raise the reference count of the target directory; so you can still get off the link count (with a maximum of one link :).

Another problem is that for programs that traverse the file system (for example, find ), loops should be avoided. They could do this by remembering every inode number they saw, but it’s expensive - if they can distinguish between links that can lead to loops (i.e., Program links) and links that won't lead to loops (regular entries in directory), and skip the program links, they no longer need to keep track of index numbers.

+12
source

All Articles