Hard links to directories: why not?

Jonathan I. Kamens jik at athena.mit.edu
Tue Jul 24 03:37:09 AEST 1990


In article <837 at ehviea.ine.philips.nl>, leo at ehviea.ine.philips.nl (Leo
de Wit) writes:
|> As a matter of fact, there is. Normal files are just hard links,
like
|> you said, but a difference between a 'real directory' and an 'alias
|> formed by a hard link to a directory' is that the .. of the former
is
|> the natural parent (the directory you get by stripping off the last
|> path component), while the .. of the latter is not. When traversing
trees
|> it just becomes a matter of following only the natural links (just
like
|> skipping symbolic links the artificial links are skipped).

  This will only hold true as long as ".." always points to the parent
directory of the first reference created.  This is true in most
implementations of Unix, but it does not *have* to be true, and in
addition, the POSIX standard doesn't require it.  Indeed, POSIX doesn't
even require that directory entries "." and ".." actually exist in the
filesystem; all it requires is that when a program accesses "." and
"..", it will get the current and parent directories respectively.  If
the operating system chooses to interpret "parent directory" as "the one
parent directory out of the several possible ones which was taken in
this particular case to get here," it is allowed to do that.  Indeed, I
would find that interpretation more useful than "the directory in which
the child directory was first created, no matter which parent you went
through to get to it this time."

  Relying on the way most filesystems work now is not a good idea,
especially when the standard says they don't have to work that way.

|> No need for that if find only - recursively - follows those
|> subdirectories 'sub' for which the inode of 'sub/..' is the same as
|> that of '.' (I wouldn't be surprised if there was already something
of
|> the same tenor in the source of find).

  I'm fairly certain that no such special code exists in find.  The
string ".." appears only once in the source code for find, and that's
when it'd doing a chdir(".."), so I don't think there's any code to
check the inode numbers of ...

  I'd test it, but whenever I try to create a hard link to a directory
as root, my workstation hangs or crashes.  I wonder why :-)

Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.wizards mailing list