New rename(2) function

Eric Blake
Wed Aug 8 12:16:00 GMT 2007

According to Igor Peshansky on 8/7/2007 7:48 AM:
> On Tue, 7 Aug 2007, Eric Blake wrote:
>> Also, the check for link count >= 2 might also be optimized to skip
>> directories (whose link count is always > 1, but since directories can't
>> be hard-linked, it is not worth looking up their id).
> Does POSIX mandate that directories cannot be hard-linked?  I think NTFS
> can create hard links to directories, and reparse points can be used as
> hard links.

POSIX mandates that it is implementation-defined whether directories can
be hard linked, and that given that definition, the rest of the behavior
is well-defined.  Some platforms, like Linux, forbid it (after all, if you
allow directory hard links, it is easy to create circular hierarchies
and/or detach entire hierarchies, to the point where only an fsck could
repair the damage).  Some, like Solaris 10, permit it, but only for users
with a particular privilege; what's more, if you happen to be one of those
superusers, you can voluntarily give up that privilege (and in fact,
coreutils' rm includes code that intentionally gives up the privilege,
because it is a lot easier to code recursive removal when unlink() is
guaranteed to fail with EISDIR rather than it is to delete a directory
that still has contents).  The ability to create directory hardlinks is
the only reason that both ln(1) and link(1), as well as rm(1) and
unlink(1), exist in coreutils - the first utilities provide recursion and
always behave as though directories can't be linked, while the second
utilities are merely raw wrappers that behave according to the underlying
semantics of the implementation.

My limited understanding is that Windows falls in the Linux camp.  Reparse
points are more like symbolic links - that is, if you have directory a,
and reparse point b pointing to a, what happens if you rename a to c -
does b now contain the contents in c, or is b now dangling?  But I know
for sure that cygwin's link(2) call fails on directories, so even if NTFS
does support hard linked directories, cygwin does not.

Don't work too hard, make some time for fun as well!

Eric Blake   

More information about the Cygwin-developers mailing list