Subject: bin/314: df overflows on filesystems greater than 4 Gig
To: None <gnats-admin>
From: Simon Burge <simonb@melb.cpr.itg.telecom.com.au>
List: netbsd-bugs
Date: 07/01/1994 15:50:06
>Number:         314
>Category:       bin
>Synopsis:       df overflows on filesystems greater than 4 Gig
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul  1 15:50:03 1994
>Originator:     Simon Burge
>Organization:
"	Telecom Australia"
>Release:        0.9B
>Environment:
System: NetBSD dodo.melb.cpr.itg.telecom.com.au 0.9B NetBSD 0.9B (THOREAU) #0: Wed Jun 1 16:24:20 EST 1994 root@karybdis:/Src/src/sys/arch/i386/compile/THOREAU i386


>Description:
	The output of any block value (total blocks, used, avail) overflows
	at 4 Gigabytes.
>How-To-Repeat:
	Mount a filesystem (I used an NFS filesystem) greater than 4
	Gigabytes and type "df".
>Fix:
	This patch for /usr/src/bin/df.c is for 0.9B, but the incorrect code
	still exists in -current.  This patch is based on the 4.4 Lite df.

*** df.c.orig	1994/07/01 22:43:23
--- df.c	1994/07/01 22:43:31
***************
*** 178,183 ****
--- 178,191 ----
  }
  
  /*
+  * Convert statfs returned filesystem size into BLOCKSIZE units.
+  * Attempts to avoid overflow for large filesystems.
+  */
+ #define fsbtoblk(num, fsbs, bs) \
+ 	(((fsbs) != 0 && (fsbs) < (bs)) ? \
+ 		(num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
+ 
+ /*
   * Print out status about a filesystem.
   */
  void
***************
*** 207,215 ****
  	used = sfsp->f_blocks - sfsp->f_bfree;
  	availblks = sfsp->f_bavail + used;
  	(void)printf(" %*ld %7ld %7ld", headerlen,
! 	    sfsp->f_blocks * sfsp->f_bsize / blocksize,
! 	    used * sfsp->f_bsize / blocksize,
! 	    sfsp->f_bavail * sfsp->f_bsize / blocksize);
  	(void)printf(" %5.0f%%",
  	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
  	if (iflag) {
--- 215,223 ----
  	used = sfsp->f_blocks - sfsp->f_bfree;
  	availblks = sfsp->f_bavail + used;
  	(void)printf(" %*ld %7ld %7ld", headerlen,
! 	    fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
! 	    fsbtoblk(used, sfsp->f_bsize, blocksize),
! 	    fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize));
  	(void)printf(" %5.0f%%",
  	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
  	if (iflag) {
>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------