Nice! Two questions for me to follow up later:
- How the OS knows it can clean up an inode after a hard link is deleted? The post mentioned inodes don't see hard links
- What does it mean to have a dead/dangling soft link?
- How the OS knows it can clean up an inode after a hard link is deleted? The post mentioned inodes don't see hard links
- What does it mean to have a dead/dangling soft link?
[~] 0 $ mkdir tmp/demo
[~] 0 $ cd tmp/demo
[demo] 0 $ ln -s foo bar
[demo] 0 $ ls -l
total 1
lrwxrwxrwx 1 user users 3 Nov 15 12:14 bar -> foo
[demo] 0 $ cat bar
cat: bar: No such file or directory
[demo] 1 $ echo foo > foo
[demo] 0 $ ls -l
total 2
lrwxrwxrwx 1 user users 3 Nov 15 12:14 bar -> foo
-rw-r--r-- 1 user users 4 Nov 15 12:14 foo
[demo] 0 $ cat bar
foo
[demo] 0 $ rm foo
[demo] 0 $ cat bar
cat: bar: No such file or directory
[demo] 1 $ ls -l
total 1
lrwxrwxrwx 1 user users 3 Nov 15 12:14 bar -> foo
[demo] 0 $
What you can't see because this is flat text is that in my terminal the first and last "bar -> foo" are red because ls is warning me that that link points to a file that doesn't exist.2. A dangling soft link points to nothing valid. If you try to access it in a way that would normally give you the object it points to there will be a not found error. If a new object of the destination name appears the link will start to work again but give the new content. If relative links are moved around out of step with what they point to this can cause significant confusion. This is not filesystem level corruption that fsck can/will check for.