Question

Some programming languages have the ability to distinguish strongly referenced objects from weakly referenced objects such that weak ones are candidates for garbage collection after all the strong references disappear.

Is there a similar concept for hard links on a filesystem? Here's a theoretical API:

 $ touch A
 $ ln --weak A A_hardlink   # create a 'weakly referenced' hard link
 $ rm A
 $ stat A_hardlink          # no such file or directory

Sym links kind of give you this, except the sym link for A would still appear on disk (even though its underlying file is gone), plus I want to take advantage of pointing to the same inode directly (for tracking moves, renames of the main file, etc). Do any filesystems actually support this, or something like it?

Was it helpful?

Solution

No (unless you create your own filesystem that has this feature). All links from directory entries to inodes in all file systems that I know of are strong links. It would be a challenge to implement weak links in most filesystems because the inode doesn't "remember" where the directory entries are that point to it, yet it would have to find them all in order to delete them once all of the strong links to the inode were gone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top