On ext file system in Linux, why can't we create hard links to directories?
What could be the reason?
thanks.
(Haven't tried with other FS or maybe it is with *NIX. No idea.)
Hard Link
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Hard links can have multiple "parents". If you're in a hard linked directory and type "cd ..", where should the new current directory be?
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Even if that "cd .." is managed (e.g. you keep the full path somewhere in the kernel), hard links to directories turn your filesystem (usually a tree) into a graph -- which may contain cycles.
/home: mkdir foo
/home/foo: ln /home bar
/home: find -type d
/home
/home/foo
/home/foo/bar
/home/foo/bar/foo
/home/foo/bar/foo/bar ...
that would break most directory-crawling software existing. Generally speaking, allowing hard links to directories while preventing cycles to appear require something looking like a mark-and-sweep garbage collector ... not the kind of thing you'll love to have in the kernel FS driver
(more about it in Tanenbaum books)
/home: mkdir foo
/home/foo: ln /home bar
/home: find -type d
/home
/home/foo
/home/foo/bar
/home/foo/bar/foo
/home/foo/bar/foo/bar ...
that would break most directory-crawling software existing. Generally speaking, allowing hard links to directories while preventing cycles to appear require something looking like a mark-and-sweep garbage collector ... not the kind of thing you'll love to have in the kernel FS driver
(more about it in Tanenbaum books)