[comp.sources.bugs] bdf program bug?

larry@jc3b21.UUCP (Lawrence F. Strickland) (02/04/88)

Back in January, Paul Vixie posted a pd df command similar to the Berkely
df.  In it, he said:

 *	Paul Vixie, paul%vixie@uunet.uu.net
 *
 * Known to work on INTERACTIVE 386/ix, and should therefore work perfectly
 * on Microport/386 and whatever the AT&T 6386 calls its OS.  Should work okay
 * on 3B's.  Should work, in fact, anywhere where the output of 'df -t' is
 * the same as 'System V/386', which may or may not be all SysV.[23] systems.

Having a 3b2, I figured that there was no way that anything written for
another machine would work correctly on a 3b2!  I was right.  The 3b2 has a
SLIGHTLY different output for df -t (or maybe its a difference in fscanf,
it is a bit hard to tell).  It caused a core dump of the original program.
After fixing that, the columns no longer lined up properly, so I fixed that.

Anyway, THANKS PAUL for a nice program.  The changes are very trivial, and
should not (famous last words :-) affect the program on *386* machines
(Sorry, but I can't test it).  Here are the diffs: (apply with patch)

*** bdf.c	Wed Feb  3 12:32:32 1988
--- bdf.c.new	Wed Feb  3 14:40:40 1988
***************
*** 70,76
  	if (iflag) header_part2();
  	header_part3();
  
! 	while (EOF != fscanf(df, "%s (%s ): %d blocks %d i-nodes",
  				filesys, device, &fblocks, &finodes)) {
  		if (EOF == fscanf(df, " total: %d blocks %d i-nodes",
  				&tblocks, &tinodes)) {

--- 70,76 -----
  	if (iflag) header_part2();
  	header_part3();
  
! 	while (EOF != fscanf(df, "%s (%[^ )] ): %d blocks %d i-nodes",
  				filesys, device, &fblocks, &finodes)) {
  		if (EOF == fscanf(df, " total: %d blocks %d i-nodes",
  				&tblocks, &tinodes)) {
***************
*** 92,98
  
  static void
  header_part1() {
! 	printf("Filesystem    kbytes    used   avail capacity");
  }
  static void
  header_part2() {

--- 92,98 -----
  
  static void
  header_part1() {
! 	printf("Filesystem      kbytes    used  avail capacity");
  }
  static void
  header_part2() {
***************
*** 96,102
  }
  static void
  header_part2() {
! 	printf(" iused   ifree  %%iused");
  }
  static void
  header_part3() {

--- 96,102 -----
  }
  static void
  header_part2() {
! 	printf(" iused  ifree  %%iused");
  }
  static void
  header_part3() {
***************
*** 100,106
  }
  static void
  header_part3() {
! 	printf("  Mounted on\n");
  }
  
  static void

--- 100,106 -----
  }
  static void
  header_part3() {
! 	printf("   Mounted on\n");
  }
  
  static void
***************
*** 111,117
  	int used_kb = total_kb - free_kb;
  	int capacity = (100 * used_kb) / total_kb;
  
! 	printf("%12s %7d %7d %7d   %3d%%  ",
  		device, total_kb, used_kb, free_kb, capacity);
  }
  

--- 111,117 -----
  	int used_kb = total_kb - free_kb;
  	int capacity = (100 * used_kb) / total_kb;
  
! 	printf("%12s %6d %7d%7d   %3d%%   ",
  		device, total_kb, used_kb, free_kb, capacity);
  }
  
***************
*** 122,128
  	int used_inodes = total_inodes - free_inodes;
  	int percent_used = (100 * used_inodes) / total_inodes;
  
! 	printf("%6d  %6d   %3d%% ", used_inodes, free_inodes, percent_used);
  }
  
  static void

--- 122,128 -----
  	int used_inodes = total_inodes - free_inodes;
  	int percent_used = (100 * used_inodes) / total_inodes;
  
! 	printf("%5d  %5d    %3d%% ", used_inodes, free_inodes, percent_used);
  }
  
  static void
-- 
+--------------------------------------+-- St. Petersburg Junior College --+
|        Lawrence F. Strickland        |   P.O. Box 13489                  |
| ...gatech!codas!usfvax2!jc3b21!larry |   St. Petersburg, FL 33733        |
+-(or) ...gatech!usfvax2!jc3b21!larry -+-- Phone: +1 813 341 4705 ---------+

paul@vixie.UUCP (Paul Vixie Esq) (02/05/88)

In article <288@jc3b21.UUCP> larry@jc3b21.UUCP (Lawrence F. Strickland) writes:
>Back in January, Paul Vixie posted a pd df command similar to the Berkely
>df. [...] The 3b2 has a
>SLIGHTLY different output for df -t (or maybe its a difference in fscanf,
>it is a bit hard to tell).  It caused a core dump of the original program.
>After fixing that, the columns no longer lined up properly, so I fixed that.

Several people reported this bug.  I also fixed some things for the 3B15/20,
and someone yet else sent in a fix for RFS systems (df output has "*"'s in it
for RFS file systems...)

I'm presently testing the version with all these fixes applied.  I'll repost
to comp.sources.misc some time after Uniforum... If anyone has any more bugs
to report, please mail them to me so the next version can be "definitive."

If someone wants to write a man page and makefile, I'll post it to .unix...
-- 
Paul A Vixie Esq
paul%vixie@uunet.uu.net
{uunet,ptsfa,hoptoad}!vixie!paul
San Francisco, (415) 647-7023