Hard Links and Symbolic Links

A hard link is an additional directory entry naming the same file identity where supported. A symbolic link stores a path reference interpreted during resolution.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two views
  2. Check scope
  3. Change one name and observe another reference
  4. Check cross-filesystem and type policies

Trace two views

Removing one hard-link name can leave the other name accessing the same file. Removing the original target of a symbolic link can leave an unresolved link. Open handles and names distinguish identity from resolving a path.

Check scope

Filesystem rules can restrict which targets may have hard links or whether a link spans a filesystem boundary. Directory entries explain why an enumeration can contain links and ordinary files together.[1]

Change one name and observe another reference

A hard link can give one file object two names. Removing one name leaves the other link to the file. A symbolic link usually stores a path to resolve, so removing or moving that target can leave the link dangling. See open handles and paths.

Hard links a,b refer to X
Remove a → b still resolves X
Symbolic link c points to path a
After removing a, c can be dangling

Check cross-filesystem and type policies

Systems restrict where hard links can be made, especially for directories. A symbolic link can target a name outside the current directory. Test inspecting a link itself separately from following its target.

References

  1. Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces ↩