Page 1 of 1
Hard Link
Posted: Wed Aug 08, 2007 12:48 am
by dc0d32
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.)
Posted: Wed Aug 08, 2007 12:51 am
by Colonel Kernel
Hard links can have multiple "parents". If you're in a hard linked directory and type "cd ..", where should the new current directory be?
Posted: Wed Aug 08, 2007 2:31 am
by dc0d32
It's clear now. Thanks.
Posted: Wed Aug 08, 2007 6:08 am
by Pype.Clicker
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)
Posted: Wed Aug 08, 2007 10:10 am
by Candy
The only requirement is to check for the entire tree link to the top of the target location whether your item is in it. If not, you're not creating a cycle.
Of course, you have to add this to the move logic too.
Posted: Wed Aug 08, 2007 10:16 pm
by dc0d32
Candy wrote:The only requirement is to check for the entire tree link to the top of the target location whether your item is in it.
Is that even deterministic?