Hard Link

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
dc0d32
Member
Member
Posts: 69
Joined: Thu Jun 09, 2005 11:00 pm
Location: Right here

Hard Link

Post 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.)
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post 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?
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
dc0d32
Member
Member
Posts: 69
Joined: Thu Jun 09, 2005 11:00 pm
Location: Right here

Post by dc0d32 »

It's clear now. Thanks. :D
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Post 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 :P

(more about it in Tanenbaum books)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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.
User avatar
dc0d32
Member
Member
Posts: 69
Joined: Thu Jun 09, 2005 11:00 pm
Location: Right here

Post 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?
Post Reply