[comp.sys.sun] Hard Links to directories.

eric@nosun.west.sun.com (Eric Hanchrow) (12/02/89)

SunOS 4.0.3, Sun4/260

A while ago, out of curiosity, I made a hard link to one of my
directories.  After I got bored with it, I decided to get rid of one of
the links... and couldn't.  I tried `\rm -f', `unlink', and `rmdir'.
Curiously, `rmdir' reported that the directory was not empty, even though
it was.  Is it possible that `rmdir' looks at the number of links to a
directory, and if that number is > 2, it assumes that the directory is not
empty?

Anyhow, I never could get rid of either of the links, so I swept them
under the rug by putting them in /tmp, giving them funny names, changing
their owners to `nobody', and changing their permissions to 0.

Any brilliant commentary explaining this odd behavior would be
appreciated.

|Eric Hanchrow          yamada-sun!eric@nosun.west.sun.com              |
|Phase III Logic, Inc.  ...!{tektronix, sun}!nosun!yamada-sun!eric      |

mike@park.bu.edu (11/27/90)

Sun OS 4.0 has a provision to allow hard links to directories.  Hard
linked directory paths appear to work appropriately, fsck -n works
appropriately.  I have discoved however the following problem with their
use.  Suppose one wants to delete two hard linked directories.  Presumably
one attempts to remove the contents of the directory.  Attempts to rmdir
either of the pair of hard linked directories fails because of the link
count of the directory is bumped.  Rmdir fails it appears on either of the
links because it interpets the directory as non-empty.  The link count on
these directories have been bumped.  A rm -r fails because the directory
cannot be removed unless it's link is removed The only way I could find to
remove a pair of hard linked directories is to run fsck on the
directories.  FSCK complains about extraneous link file which it now knows
how to remove.  Is there any way to remove hard linked directories under
Sun OS 4.0 other than by running fsck?  -mike