Subject: Re: bin/32785 [dM] du not terabyte-clean
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: netbsd-bugs
Date: 07/24/2006 18:05:04
The following reply was made to PR bin/32785; it has been noted by GNATS.

From: der Mouse <mouse@Rodents.Montreal.QC.CA>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/32785 [dM] du not terabyte-clean
Date: Mon, 24 Jul 2006 13:56:56 -0400 (EDT)

 This happens because du blindly uses fts_number to accumulate directory
 data-used values, even though fts_number is too small for the purpose.
 
 This fixes it for me.  It's possible it may be suboptimal in some
 respect.
 
 This patch is relative to
 
 /*      $NetBSD: du.c,v 1.26 2005/02/17 17:40:59 xtraeme Exp $  */
 
 --- du.c=	2006-07-24 13:26:08.000000000 -0400
 +++ du.c	2006-07-24 13:52:37.000000000 -0400
 @@ -190,12 +190,15 @@
  				}
  			}
  		}
 +#define BIGVAL(p) (*(unsigned long long int *)p->fts_pointer)
  		switch (p->fts_info) {
 -		case FTS_D:			/* Ignore. */
 +		case FTS_D:
 +			p->fts_pointer = malloc(sizeof(unsigned long long int));
 +			BIGVAL(p) = 0;
  			break;
  		case FTS_DP:
 -			p->fts_parent->fts_number += 
 -			    p->fts_number += p->fts_statp->st_blocks;
 +			BIGVAL(p) += p->fts_statp->st_blocks;
 +			if (p->fts_parent->fts_pointer) BIGVAL(p->fts_parent) += BIGVAL(p);
  			if (cflag)
  				totalblocks += p->fts_statp->st_blocks;
  			/*
 @@ -204,7 +207,9 @@
  			 * root of a traversal, display the total.
  			 */
  			if (listdirs || (!listfiles && !p->fts_level))
 -				prstat(p->fts_path, p->fts_number);
 +				prstat(p->fts_path, BIGVAL(p));
 +			free(p->fts_pointer);
 +			p->fts_pointer = 0;
  			break;
  		case FTS_DC:			/* Ignore. */
  			break;
 @@ -224,10 +229,11 @@
  			 */
  			if (listfiles || !p->fts_level)
  				prstat(p->fts_path, p->fts_statp->st_blocks);
 -			p->fts_parent->fts_number += p->fts_statp->st_blocks;
 +			if (p->fts_parent->fts_pointer) BIGVAL(p->fts_parent) += p->fts_statp->st_blocks;
  			if (cflag)
  				totalblocks += p->fts_statp->st_blocks;
  		}
 +#undef BIGVAL
  	}
  	if (errno)
  		err(1, "fts_read");
 
 /~\ The ASCII				der Mouse
 \ / Ribbon Campaign
  X  Against HTML	       mouse@rodents.montreal.qc.ca
 / \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B