Subject: Re: bin/36541 (cleaner df(1) output, and another output format option)
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,>
From: Greg A. Woods <woods@planix.com>
List: netbsd-bugs
Date: 07/15/2007 22:25:02
The following reply was made to PR bin/36541; it has been noted by GNATS.

From: "Greg A. Woods" <woods@planix.com>
To: NetBSD GNATS <gnats-bugs@NetBSD.org>
Cc: <gnats-admin@netbsd.org>, jmmv@netbsd.org
Subject: Re: bin/36541 (cleaner df(1) output, and another output format option)
Date: Sun, 15 Jul 2007 18:24:32 -0400

 --pgp-sign-Multipart_Sun_Jul_15_18:24:31_2007-1
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: quoted-printable
 
 At Sun, 15 Jul 2007 09:43:07 +0000 (UTC), jmmv@netbsd.org wrote:
 Subject: Re: bin/36541 (cleaner df(1) output, and another output format opt=
 ion)
 >=20
 > Synopsis: cleaner df(1) output, and another output format option
 >=20
 > State-Changed-From-To: closed->open
 > State-Changed-By: jmmv@netbsd.org
 > State-Changed-When: Sun, 15 Jul 2007 09:43:06 +0000
 > State-Changed-Why:
 > This change makes '-Ph' segfault.  Based on what I see in the manual page,
 > -Ph should spit an error just like -Pi does, but as I'm not sure I'll let
 > you explain which is the correct way to go.  Patches welcome!
 
 Oops!  Sorry about that!  (my excuse is that support for '-h' didn't yet
 exist in the code when I made the original modifications :-))
 
 Yes, a usage error would be the safest fix.  '-P' has a standardized
 and fixed definition for the magnitudes of the output values for only
 the default 512-byte blocks and with '-k' for 1024-byte blocks.
 
 My original thoughts about '-P' with other block sizes was that this
 would be a fair extension to the standard given that the block size is
 printed in the header, though I'm not so sure about that with '-h', and
 I don't think it's fair to require a portable application which might
 use "df" to clear the environment (BLOCKSIZE is not defined in the
 standard).  I'd be much happier if '-P' only displayed either 512-byte
 blocks by default, or with '-k' 1024-byte blocks, and that BLOCKSIZE
 always be ignored when '-P' is in effect.  That limits the output to
 exactly what's specified in the standard and leaves nothing to doubt.
 
 The attached patch also fixes some problems caused by over-zealous
 re-tabification too (some was already fixed in 1.74 I see).  The
 ugliness of the -g output in the committed version was also a direct
 result of replacing tabs with spaces in the wrong places.  Perhaps this
 was done by whatever tool was used to view and copy from my original PR.
 Please be very careful with the spaces and tabs in this PR!  If you'd
 like I can resend it without the quoted-printable encoding, or with some
 even more robust encoding such as base64.
 
 The NetBSD style of casts without spaces and ugly indentation of
 continued lines makes correcting the problems here VERY difficult!
 
 It would also really help a HUGE amount if patches were applied and
 committed verbatim and then adjusted to the committer's whims with a
 secondary commit.
 
 --=20
 						Greg A. Woods
 
 H:+1 416 218-0098 W:+1 416 489-5852 x122 VE3TCP RoboHack <woods@robohack.ca>
 Planix, Inc. <woods@planix.com>       Secrets of the Weird <woods@weird.com>
 
 Index: bin/df/df.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /cvs/master/m-NetBSD/main/src/bin/df/df.c,v
 retrieving revision 1.74
 diff -u -r1.74 df.c
 --- bin/df/df.c	3 Jul 2007 14:39:47 -0000	1.74
 +++ bin/df/df.c	15 Jul 2007 22:16:43 -0000
 @@ -53,6 +53,7 @@
  #include <sys/stat.h>
  #include <sys/mount.h>
 =20
 +#include <assert.h>
  #include <err.h>
  #include <errno.h>
  #include <fcntl.h>
 @@ -140,6 +141,8 @@
  		errx(1, "only one of -g and -P or -i may be specified");
  	if (Pflag && iflag)
  		errx(1, "only one of -P and -i may be specified");
 +	if (Pflag && (hflag || (usize !=3D 1024 && usize !=3D 512)))
 +		errx(1, "non-standard block size incompatible with -P");
 =20
  	argc -=3D optind;
  	argv +=3D optind;
 @@ -356,10 +359,10 @@
  		/*
  		 * From SunOS-5.6:
  		 *
 -		 * /var		      (/dev/dsk/c0t0d0s3 ):	    8192 block size	     1024 frag =
 size =20
 -		 *   984242 total blocks     860692 free blocks	  859708 available	   24=
 9984 total files
 -		 *   248691 free files	    8388611 filesys id=09
 -		 *	ufs fstype	 0x00000004 flag	     255 filename length
 +		 * /var               (/dev/dsk/c0t0d0s3 ):         8192 block size     =
      1024 frag size =20
 +		 *   984242 total blocks     860692 free blocks   859708 available      =
    249984 total files
 +		 *   248691 free files      8388611 filesys id =20
 +		 *      ufs fstype       0x00000004 flag             255 filename length
  		 *
  		 */
  		(void)printf("%10s (%-12s): %7ld block size %12ld frag size\n",
 @@ -379,11 +382,11 @@
  		    " free blocks  %10" PRId64 " available\n",
  		    (uint64_t)sfsp->f_blocks, (uint64_t)sfsp->f_bfree,
  		    (uint64_t)sfsp->f_bavail);
 -		(void)printf("%10" PRId64 " total files	 %10" PRId64
 +		(void)printf("%10" PRId64 " total files  %10" PRId64
  		    " free files %12lx filesys id\n",
  		    (uint64_t)sfsp->f_ffree, (uint64_t)sfsp->f_files,
  		    sfsp->f_fsid);
 -		(void)printf("%10s fstype  %#15lx flag	%17ld filename "
 +		(void)printf("%10s fstype  %#15lx flag  %17ld filename "
  		    "length\n", sfsp->f_fstypename, sfsp->f_flag,
  		    sfsp->f_namemax);
  		(void)printf("%10lu owner %17" PRId64 " syncwrites %12" PRId64
 @@ -405,16 +408,16 @@
  			headerlen =3D strlen(header);
  			break;
  		case 1024 * 1024:
 -			header =3D Pflag ? "1048576-blocks" : "1M-blocks";
 +			header =3D "1M-blocks";
  			headerlen =3D strlen(header);
  			break;
  		case 1024 * 1024 * 1024:
 -			header =3D Pflag ? "1073741824-blocks" : "1G-blocks";
 +			header =3D "1G-blocks";
  			headerlen =3D strlen(header);
  			break;
  		default:
  			if (hflag) {
 -				header =3D "  Size";
 +				header =3D "Size";
  				headerlen =3D strlen(header);
  			} else
  				header =3D getbsize(&headerlen, &blocksize);
 @@ -422,8 +425,10 @@
  		}
  		if (Pflag) {
  			/*
 -			 * "Filesystem {1024,512}-blocks Used Available=20
 -			 * Capacity Mounted on\n"
 +			 * either:
 +			 *  "Filesystem 1024-blocks Used Available Capacity Mounted on\n"
 +			 * or:
 +			 *  "Filesystem 512-blocks Used Available Capacity Mounted on\n"
  			 */
  			(void)printf("Filesystem %s Used Available Capacity "
  			    "Mounted on\n", header);
 @@ -441,6 +446,8 @@
  	bavail =3D sfsp->f_bfree - sfsp->f_bresvd;
  	availblks =3D bavail + used;
  	if (Pflag) {
 +		assert(hflag =3D=3D 0);
 +		assert(blocksize > 0);
  		/*
  		 * "%s %d %d %d %s %s\n", <file system name>, <total space>,
  		 * <space used>, <space free>, <percentage used>,
 @@ -491,7 +498,7 @@
  {
 =20
  	(void)fprintf(stderr,
 -	    "Usage: %s [-aGghklmn] [-i|-p] [-t type] [file | "
 +	    "Usage: %s [-aGgln] [-hkm|-ihkm|-Pk] [-t type] [file | "
  	    "file_system ...]\n",
  	    getprogname());
  	exit(1);
 
 --pgp-sign-Multipart_Sun_Jul_15_18:24:31_2007-1
 Content-Type: application/pgp-signature
 Content-Transfer-Encoding: 7bit
 
 -----BEGIN PGP SIGNATURE-----
 Version: PGPfreeware 5.0i for non-commercial use
 MessageID: 5Ot5lID1UbH/VVjaPilLwK0YI7nWpOE0
 
 iQA/AwUBRpqen2Z9cbd4v/R/EQIFFACfR1rZkz/7SjS3Mpk7u6bdvYoPQ60AoJkG
 tTYoRs2TzJ7pfQ5bK5NFSV5k
 =pLh6
 -----END PGP SIGNATURE-----
 
 --pgp-sign-Multipart_Sun_Jul_15_18:24:31_2007-1--