[PATCH:util/lndir] Fix broken assumption where stat.st_nlink == 1

Alan Coopersmith Alan.Coopersmith at Sun.COM
Thu Oct 15 17:00:30 PDT 2009


Pushed (though I had to add a #include <limits.h> to make it build on
Solaris).

	-alan-

Yaakov (Cygwin/X) wrote:
> From: Eric Blake <ebby9 at byu.net>
> 
> Normally, any directory has a st_nlink of at least 2 (. and ..).
> On some systems, a directory's st_nlink is set to 1 where it is too
> expensive to compute the correct value (e.g. remote filesystems).
> Instead of treating this as a legitimate value (i.e. that the directory
> contains nothing to link from), special case this and force a complete
> scan of the directory's contents.
> 
> Further explanation:
> http://cygwin.com/ml/cygwin/2008-06/msg00056.html
> http://cygwin.com/ml/cygwin-apps/2008-08/msg00264.html
> 
> Signed-off-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
> ---
>  lndir.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/lndir.c b/lndir.c
> index 4d63c1c..5ca591a 100644
> --- a/lndir.c
> +++ b/lndir.c
> @@ -182,6 +182,8 @@ dodir (char *fn,		/* name of "from" directory, either absolute or
>      if (*(p - 1) != '/')
>  	*p++ = '/';
>      n_dirs = fs->st_nlink;
> +    if (n_dirs == 1)
> +	n_dirs = INT_MAX;
>      while ((dp = readdir (df))) {
>  	if (dp->d_name[strlen(dp->d_name) - 1] == '~')
>  	    continue;

-- 
	-Alan Coopersmith-           alan.coopersmith at sun.com
	 Sun Microsystems, Inc. - X Window System Engineering



More information about the xorg-devel mailing list