Do we really need correct st_nlink count for directories?

Igor Peshansky
Sat Apr 26 04:18:00 GMT 2008

On Fri, 25 Apr 2008, Eric Blake wrote:

> According to Igor Peshansky on 4/25/2008 2:25 PM:
> > > When link counts are accurate, every directory has a link count of at
> > > least 2 (. and ..)
> >
> > I thought leaf directories had a legitimate link count of 1.
> Two, actually: ".", but also the entry in ".." that points to the
> directory's inode.  There might be some alternative file systems where
> readdir() omits . and .. in its list, leaving a link count of 0.  But
> I've never seen a disk-based link count of 1.  And even Linux uses 1,
> not 0, as the link count of FAT directories.  A directory with a link
> count of 2 is guaranteed to be a leaf directory (no subdirs); but with a
> link count of 1 is indeterminate.

Hmm, maybe I'm especially dumb today, but shouldn't '..' point to the
*parent's* inode, and thus count towards the *parent's* link count?  So,
an empty leaf directory would have 2 *entries*, but that has nothing to do
with the link count.

However, I just realized that the two entries contributing to any
directory's link count are the '.' directory and the actual entry in the
parent that points to the directory (i.e., if we have a directory "/a/b",
then "b" has 2 links -- the 'b' entry in "/a" and the '.' entry in
"/a/b").  So the count of 1 can indeed be a trigger value.

Sorry for the noise.
      |\      _,,,---,,_ |
ZZZzz /,`.-'`'    -.  ;-;;,_		Igor Peshansky, Ph.D. (name changed!)
     |,4-  ) )-,_. ,\ (  `'-'		old name: Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"That which is hateful to you, do not do to your neighbor.  That is the whole
Torah; the rest is commentary.  Go and study it." -- Rabbi Hillel

More information about the Cygwin-developers mailing list