Hard links to directories: why not?

John F. Haugh II jfh at rpp386.cactus.org
Mon Jul 23 07:37:08 AEST 1990


In article <1990Jul22.111334.9996 at jarvis.csri.toronto.edu> flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
>Suppose your filesystem is on /mnt.
>Do this:
>
>	mkdir /mnt/a
>	ln /mnt/a /mnt/b
>	mkdir /mnt/a/c
>	ln /mnt/a /mnt/b/c/d
>
>Now /mnt/a/c/d and /mnt/a are the same.  So you can refer to
>/mnt/a/c/d/c/d/c/d/c/d/c/d, etc.

Your example is correct - unless /mnt/b/c resolves to /mnt/a/c,
the test will fail.  This can happen because the order of entries
in the directory affects the outcome of the conversion to an
absolute pathname.

The conversion of /mnt/a and /mnt/b/c/d to absolute pathnames
need only recognize that /mnt/a and /mnt/b are identical to know
that a loop is being created.  If "/mnt/a" is resolved either
"/mnt/a" or "/mnt/b" should be produced.  Performing the same
test on "/mnt/b/c" will produce the same prefix since the
resolution of "/mnt/b" and "/mnt/a" can implemented in such a
way as to produce the same result.

It is quite possible to detect the creation of loops in the
filesystem, but the expense and risk doesn't seem worth the
questionable benefit of being able to create randomly shaped
directory trees.
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh at rpp386.cactus.org



More information about the Comp.unix.wizards mailing list