2

I want a very simple example of how can a hard link break the file system structure.

I saw somewhere that people say it's because of loops, however, I can make a loop with a soft link and so I still want to know what makes hard link break the file system?

  • 1
    Please ask one question per question. I chose to answer the first question in your post. If you want, ask the second question in a separate post. But don't just repost it, you need to explain what you want better: have you read the Wikipedia article? Which part don't you understand? – Gilles Jan 22 '15 at 0:05
3

It's hard links to directories that can break the filesystem structure. Hard links to other types of files aren't a problem. For example:

mkdir foo
ln foo foo/self
rmdir foo

rmdir foo doesn't actually remove the directory since it has a remaining link — the self entry inside foo itself. foo has become detached from the filesystem; it can't be reached anymore, but it still exists. Forbidding hard links to directories prevents this problem. There are garbage-collected filesystems where a detached directory tree is automatically reclaimed, but they've never really taken (it's a significant effort for hardly any benefit).

Another problem is with tools that traverse a directory tree. If hard links to directories are allowed, then these tools would have to remember all previously-seen directories and skip them, or else they would loop forever when encountering a directory which is a subdirectory of itself (or of a child of itself, etc.).

Loops with symbolic links aren't a problem. If the target of the symbolic link is removed, the existence of the symlink doesn't matter. In recursive traversals, symlinks aren't followed (unless explicitly requested).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.