NetBSD Problem Report #36541

From woods@building.weird.com  Sat Jun 23 23:27:25 2007
Return-Path: <woods@building.weird.com>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 7D57163B882
	for <gnats-bugs@gnats.netbsd.org>; Sat, 23 Jun 2007 23:27:25 +0000 (UTC)
Message-Id: <m1I2F0m-002IwcC@building.weird.com>
Date: Sat, 23 Jun 2007 19:27:24 -0400 (EDT)
From: "Greg A. Woods" <woods@planix.com>
Sender: "Greg A. Woods" <woods@building.weird.com>
Reply-To: "Greg A. Woods" <woods@planix.com>
To: gnats-bugs@NetBSD.org
Subject: cleaner df(1) output, and another output format option
X-Send-Pr-Version: 3.95

>Number:         36541
>Category:       bin
>Synopsis:       cleaner df(1) output, and another output format option
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 23 23:30:00 +0000 2007
>Closed-Date:    
>Last-Modified:  Sun Jul 15 22:25:01 +0000 2007
>Originator:     Greg A. Woods
>Release:        netbsd-current 2007/06/22
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:


System: NetBSD
>Description:

	there's way too much space wasted in the current "df" output

	a "-g" option to mimic the SysVr4 and SunOS-5 options is also
	offered

	the "-P" output was also not standards-conforming

>How-To-Repeat:

>Fix:

cvs diff: Diffing bin/df
Index: bin/df/df.1
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/df/df.1,v
retrieving revision 1.40
diff -u -r1.40 df.1
--- bin/df/df.1	28 Jan 2007 09:56:13 -0000	1.40
+++ bin/df/df.1	12 Feb 2007 20:28:38 -0000
@@ -37,7 +37,8 @@
 .Nd display free disk space
 .Sh SYNOPSIS
 .Nm
-.Op Fl aghiklmnP
+.Op Fl aGklmn
+.Op Fl g | Fl i | Fl P
 .Op Fl t Ar type
 .Op Ar file | Ar file_system ...
 .Sh DESCRIPTION
@@ -71,11 +72,27 @@
 including those that were mounted with the
 .Dv MNT_IGNORE
 flag.
-.It Fl g
+.It Fl G
 The
-.Fl g
+.Fl G
 option causes the numbers to be reported in gigabytes (1024*1024*1024
 bytes).
+.It Fl g
+Display all the fields of the structure(s) returned by
+.Xr statvfs 2 .
+This option cannot be used with the
+.Fl i
+or
+.Fl P
+options.
+This option will override the
+.Fl G ,
+.Fl h ,
+.Fl k ,
+and
+.Fl m
+options, as well as any setting of
+.Ev BLOCKSIZE .
 .It Fl h
 "Human-readable" output.
 Use unit suffixes: Byte, Kilobyte, Megabyte,
@@ -136,6 +153,11 @@
     \*[Lt]space used\*[Gt], \*[Lt]space free\*[Gt], \*[Lt]percentage used\*[Gt],
     \*[Lt]file system root\*[Gt]
 .Ed
+.Pp
+Note that the
+.Fl i
+option may not be specified with
+.Fl P .
 .It Fl t Ar type
 Is used to indicate the actions should only be taken on
 filesystems of the specified type.
@@ -155,7 +177,7 @@
 If the environment variable
 .Ev BLOCKSIZE
 is set, and the
-.Fl g ,
+.Fl G ,
 .Fl h ,
 .Fl k
 and
Index: bin/df/df.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/df/df.c,v
retrieving revision 1.72
diff -u -r1.72 df.c
--- bin/df/df.c	4 Sep 2006 16:32:57 -0000	1.72
+++ bin/df/df.c	12 Feb 2007 20:14:37 -0000
@@ -77,7 +77,7 @@
 const char *
 	strpct64(uint64_t, uint64_t, u_int);

-int	aflag, hflag, iflag, lflag, nflag, Pflag;
+int	aflag, gflag, hflag, iflag, lflag, nflag, Pflag;
 long 	usize = 0;
 char	**typelist = NULL;

@@ -90,15 +90,18 @@
 	int ch, i, maxwidth, width;
 	char *mntpt;

-	while ((ch = getopt(argc, argv, "aghiklmnPt:")) != -1)
+	while ((ch = getopt(argc, argv, "aGghiklmnPt:")) != -1)
 		switch (ch) {
 		case 'a':
 			aflag = 1;
 			break;
-		case 'g':
+		case 'G':
 			hflag = 0;
 			usize = 1024 * 1024 * 1024;
 			break;
+		case 'g':
+			gflag = 1;
+			break;
 		case 'h':
 			hflag = 1;
 			usize = 0;
@@ -132,6 +135,12 @@
 		default:
 			usage();
 		}
+
+	if (gflag && (Pflag || iflag))
+		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");
+
 	argc -= optind;
 	argv += optind;

@@ -343,8 +352,55 @@
 	int64_t used, availblks, inodes;
 	int64_t bavail;

-	if (maxwidth < 11)
-		maxwidth = 11;
+	if (gflag) {
+		/*
+		 * From SunOS-5.6:
+		 *
+		 * /var               (/dev/dsk/c0t0d0s3 ):         8192 block size          1024 frag size  
+		 *   984242 total blocks     860692 free blocks   859708 available         249984 total files
+		 *   248691 free files      8388611 filesys id  
+		 *      ufs fstype       0x00000004 flag             255 filename length
+		 *
+		 */
+		(void) printf("%10s (%-12s): %7ld block size %12ld frag size\n",
+			      sfsp->f_mntonname,
+			      sfsp->f_mntfromname,
+			      sfsp->f_iosize,	/* On UFS/FFS systems this is
+						 * also called the "optimal
+						 * transfer block size" but it
+						 * is of course the file
+						 * system's block size too.
+						 */
+			      sfsp->f_bsize);	/* not so surprisingly the
+						 * "fundamental file system
+						 * block size" is the frag
+						 * size.
+						 */
+		(void) printf("%10" PRId64 " total blocks %10" PRId64 " 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 " 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 length\n",
+			      sfsp->f_fstypename,
+			      sfsp->f_flag,
+			      sfsp->f_namemax);
+		(void) printf("%10lu owner %17" PRId64 " syncwrites %12" PRId64 " asyncwrites\n\n",
+			      (unsigned long) sfsp->f_owner,
+			      sfsp->f_syncwrites,
+			      sfsp->f_asyncwrites);
+
+		/*
+		 * a consession by the structured programming police to the
+		 * indentation police....
+		 */
+		return;
+	}
+	if (maxwidth < 12)
+		maxwidth = 12;
 	if (++timesthrough == 1) {
 		switch (blocksize = usize) {
 		case 1024:
@@ -367,38 +423,67 @@
 				header = getbsize(&headerlen, &blocksize);
 			break;
 		}
-		(void)printf("%-*.*s %s      Used %9s Capacity",
-		    maxwidth, maxwidth, "Filesystem", header,
-		    Pflag ? "Available" : "Avail");
-		if (iflag)
-			(void)printf("  iused    ifree  %%iused");
-		(void)printf("  Mounted on\n");
+		if (Pflag) {
+			/* "Filesystem 1024-blocks Used Available Capacity Mounted on\n" */
+			/* "Filesystem 512-blocks Used Available Capacity Mounted on\n" */
+			(void) printf("Filesystem %s Used Available Capacity Mounted on\n", header);
+		} else {
+			(void) printf("%-*.*s %s       Used      Avail %%Cap",
+				      maxwidth - (headerlen - 9),
+				      maxwidth - (headerlen - 9),
+				      "Filesystem", header);
+			if (iflag)
+				(void) printf("    iUsed  iAvail %%iCap");
+			(void) printf(" Mounted on\n");
+		}
 	}
-	(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
 	used = sfsp->f_blocks - sfsp->f_bfree;
 	bavail = sfsp->f_bfree - sfsp->f_bresvd;
 	availblks = bavail + used;
+	if (Pflag) {
+		/*
+		 * "%s %d %d %d %s %s\n", <file system name>, <total space>,                    
+		 * <space used>, <space free>, <percentage used>, <file system root>              
+		 */
+		(void) printf("%s %" PRId64 " %" PRId64 " %" PRId64 " %s %s\n",
+			      sfsp->f_mntfromname,
+			      fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
+			      fsbtoblk(used, sfsp->f_bsize, blocksize),
+			      fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize),
+			      availblks == 0 ? full : strpct64((uint64_t) used,
+							       (uint64_t) availblks, 0),
+			      sfsp->f_mntonname);
+		/*
+		 * another consession by the structured programming police to
+		 * the indentation police....
+		 *
+		 * Note iflag cannot be set when Pflag is set.
+		 */
+		return;
+	}
+
+	(void) printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
+
 	if (hflag)
 		prthuman(sfsp, used, bavail);
 	else
-		(void)printf(" %*" PRId64 " %9" PRId64 " %9" PRId64, headerlen,
+		(void) printf("%10" PRId64 " %10" PRId64 " %10" PRId64,
 		    fsbtoblk(sfsp->f_blocks, sfsp->f_frsize, blocksize),
 		    fsbtoblk(used, sfsp->f_frsize, blocksize),
 		    fsbtoblk(bavail, sfsp->f_frsize, blocksize));
-	(void)printf("%7s",
+	(void)printf(" %4s",
 	    availblks == 0 ? full :
 	    /* We know that these values are never negative */
 	    strpct64((uint64_t)used, (uint64_t)availblks, 0));
 	if (iflag) {
 		inodes = sfsp->f_files;
 		used = inodes - sfsp->f_ffree;
-		(void)printf(" %8ld %8ld %6s ",
+		(void) printf(" %8ld %8ld %4s",
 		    (u_long)used, (u_long)sfsp->f_ffree,
 		    inodes == 0 ? (used == 0 ? empty : full) :
 		    strpct64((uint64_t)used, (uint64_t)inodes, 0));
-	} else
-		(void)printf("  ");
-	(void)printf("  %s\n", sfsp->f_mntonname);
+	}
+	(void)printf(" %s\n", sfsp->f_mntonname);
 }

 void
@@ -406,7 +491,7 @@
 {

 	(void)fprintf(stderr,
-	    "usage: %s [-aghiklmnP] [-t type] [file | file_system ...]\n",
+	    "usage: %s [-aGghklmn] [-i|-p] [-t type] [file | file_system ...]\n",
 	    getprogname());
 	exit(1);
 	/* NOTREACHED */

>Release-Note:

>Audit-Trail:
From: Christos Zoulas <christos@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: PR/36541 CVS commit: src/bin/df
Date: Sun, 24 Jun 2007 01:52:46 +0000 (UTC)

 Module Name:	src
 Committed By:	christos
 Date:		Sun Jun 24 01:52:46 UTC 2007

 Modified Files:
 	src/bin/df: df.1 df.c

 Log Message:
 PR/36541: Greg A. Woods: fix -P option, and add solaris -g option.


 To generate a diff of this commit:
 cvs rdiff -r1.40 -r1.41 src/bin/df/df.1
 cvs rdiff -r1.72 -r1.73 src/bin/df/df.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: christos@netbsd.org
State-Changed-When: Sun, 24 Jun 2007 13:52:52 -0400
State-Changed-Why:
patch applied. some of the fields in -g are not aligned too well.


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!


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--

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.