Subject: bin/3590: eliminate df floating point
To: None <gnats-bugs@gnats.netbsd.org>
From: Erik E. Fair <fair@atomic.clock.org>
List: netbsd-bugs
Date: 05/08/1997 12:27:21
>Number:         3590
>Category:       bin
>Synopsis:       df uses floating point and calls printf unnecessarily
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May  8 12:35:01 1997
>Last-Modified:
>Originator:     Erik E. Fair
>Organization:
International Organization of Internet Clock Watchers
>Release:        NetBSD-current, May 8, 1997
>Environment:

System: NetBSD atomic.clock.org 1.2D NetBSD 1.2D (GENERIC) #42: Wed Apr 23 08:06:27 PDT 1997 root@atomic.clock.org:/usr/src/sys/arch/sparc/compile/GENERIC sparc


>Description:
	df uses a floating point calculation of percentage disk used, and
	percentage of inodes used. This causes df to core dump on systems
	which do not have a floating point unit, and whose floating point
	arithmetic emulation is not yet complete (e.g. any mc68LC040 system).

	Calling printf to push simple strings out the door is silly.
	That's what {f,}puts(3) is for.

>How-To-Repeat:
	run df on a Macintosh with an mc68LC040 processor (e.g. PowerBook 500
	series). Also, code inspection.

>Fix:
	see pr # bin/3585 for strpct() source.

*** df.c.orig	Wed Dec 11 04:06:07 1996
--- df.c	Thu May  8 12:22:52 1997
***************
*** 64,69 ****
--- 64,71 ----
  #include <string.h>
  #include <unistd.h>
  
+ extern char * strpct __P((u_long num, u_long denom, u_int digits));
+ 
  int	 bread __P((off_t, void *, int));
  char	*getmntpt __P((char *));
  void	 prtstat __P((struct statfs *, int));
***************
*** 312,317 ****
--- 314,320 ----
  	static int headerlen, timesthrough;
  	static char *header;
  	long used, availblks, inodes;
+ 	static char	*full = "100%";
  
  	if (maxwidth < 11)
  		maxwidth = 11;
***************
*** 325,332 ****
  		(void)printf("%-*.*s %s     Used    Avail Capacity",
  		    maxwidth, maxwidth, "Filesystem", header);
  		if (iflag)
! 			(void)printf(" iused   ifree  %%iused");
! 		(void)printf("  Mounted on\n");
  	}
  	(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
  	used = sfsp->f_blocks - sfsp->f_bfree;
--- 328,335 ----
  		(void)printf("%-*.*s %s     Used    Avail Capacity",
  		    maxwidth, maxwidth, "Filesystem", header);
  		if (iflag)
! 			(void)fputs(" iused   ifree  %iused", stdout);
! 		(void)puts("  Mounted on");
  	}
  	(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
  	used = sfsp->f_blocks - sfsp->f_bfree;
***************
*** 335,350 ****
  	    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) {
  		inodes = sfsp->f_files;
  		used = inodes - sfsp->f_ffree;
! 		(void)printf(" %7ld %7ld %5.0f%% ", used, sfsp->f_ffree,
! 		   inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0);
! 	} else 
! 		(void)printf("  ");
! 	(void)printf("  %s\n", sfsp->f_mntonname);
  }
  
  /*
--- 338,355 ----
  	    fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
  	    fsbtoblk(used, sfsp->f_bsize, blocksize),
  	    fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize));
! 	(void)printf(" %6s",
! 	    availblks == 0 ? full : strpct((ulong)used, (ulong)availblks, 0));
  	if (iflag) {
  		inodes = sfsp->f_files;
  		used = inodes - sfsp->f_ffree;
! 		(void)printf(" %7ld %7ld %6s ", used, sfsp->f_ffree,
! 		   inodes == 0 ? full : strpct((ulong)used, (ulong)inodes, 0));
! 	} else {
! 		(void)fputs("  ", stdout);
! 	}
! 	(void)fputs("  ", stdout);
! 	(void)puts(sfsp->f_mntonname);
  }
  
  /*
>Audit-Trail:
>Unformatted: