Hard links to directories: why not?

Bob Goudreau goudreau at larrybud.rtp.dg.com
Tue Jul 31 01:39:49 AEST 1990


In article <N+W4:YF at xds13.ferranti.com>, peter at ficc.ferranti.com (peter
da silva) writes:
> In article <1990Jul24.200022.2265 at dg-rtp.dg.com>,
goudreau at larrybud.rtp.dg.com (Bob Goudreau) writes:
> > If you prohibit
> > non-superusers from unlinking them, then you're stuck with the unlovely
> > situation of users being unable to delete links they've created, even
> > though they have write access in the affected directory.  If you lift
> > this prohibition, then you can easily end up with directories whose
> > ".." entry points nowhere (or worse yet, points to what used to be
> > the parent inode, but has now been recycled into something completely
> > different).
> 
> (a) There still remain link counts. Just make rmdir check link counts.
>     It already checks to see if the directory is empty. Then it will
>     say "rmdir: Directory has firm links".
>
> (b) The inode won't be reused. Link counts again.

But my basic point still stands.  If you add such a restriction (based
on link counts instead of root privileges this time), then you're
still stuck with the "unlovely situation" I mentioned (see below for
example).  And if you don't add the prohibition, you're stuck with
the ".." problem.

Here's an example of the problem:

1)  I create a subdirectory named "sub".

2)  Unbeknownst to be me, Joe Schmo creates a hard link of his own
    to "sub".

3)  I try to rmdir "sub", which is empty, and find that I cannot,
    because its link count is > 2.

So now I'm stuck with a subdirectory that I own that lives in a
directory that I can write, but I can't delete it!  All I know is how
many extra links to it exist -- and I have no way of finding out
*where* those links are.  Contrast this case to the deletion of an
ordinary file with many links, and you'll see the difference.  There's
nothing preventing me unlinking the file, yet there is for the
directory.

That is the behavior I find objectionable.
 
------------------------------------------------------------------------
Bob Goudreau				+1 919 248 6231
Data General Corporation
62 Alexander Drive			goudreau at dg-rtp.dg.com
Research Triangle Park, NC  27709	...!mcnc!rti!xyzzy!goudreau
USA



More information about the Comp.unix.wizards mailing list