From nobody@FreeBSD.org  Mon May  5 14:17:40 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C76B3106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  5 May 2008 14:17:40 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id B132F8FC1C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  5 May 2008 14:17:40 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m45EGo9j068571
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 5 May 2008 14:16:50 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m45EGofJ068570;
	Mon, 5 May 2008 14:16:50 GMT
	(envelope-from nobody)
Message-Id: <200805051416.m45EGofJ068570@www.freebsd.org>
Date: Mon, 5 May 2008 14:16:50 GMT
From: Robert Woolley <freebsd-pr08@mlists.homeunix.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] Add -g (Gbyte) option to du(1) + manpage cleanup
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         123418
>Category:       bin
>Synopsis:       [patch] du(1): add -g (Gbyte) option to du(1) + manpage cleanup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 05 14:20:01 UTC 2008
>Closed-Date:    
>Last-Modified:  Tue Nov 13 20:55:09 UTC 2012
>Originator:     Robert Woolley
>Release:        7.0 with du.1 and du.c from CURRENT
>Organization:
>Environment:
FreeBSD gumby.homeunix.com 7.0-RELEASE-p1 FreeBSD 7.0-RELEASE-p1 #0: Mon May  5 14:19:07 BST 2008     root@gumby.homeunix.com:/usr/obj/usr/src/sys/MUSTARD  i386

>Description:
Patch adds a GByte blocksize option to du(1), bringing it into line with df(1). I find GB units to be preferable for seeing at-a-glance which directories are using significant space.

In adding the -g option to the manpage, I also reordered the options into alphabetical order, since they were in a bit of a mess.
>How-To-Repeat:

>Fix:

Note that the patch is against CURRENT. The changes to du.c from 7.0 to current are self-contained, so I copied du.c and du.1 from CVS into 7.0.



Patch attached with submission follows:

--- usr.bin/du/du.c.orig	2008-04-29 21:38:35.000000000 +0100
+++ usr.bin/du/du.c	2008-04-29 21:42:54.000000000 +0100
@@ -105,7 +105,7 @@
 	depth = INT_MAX;
 	SLIST_INIT(&ignores);
 
-	while ((ch = getopt(argc, argv, "HI:LPasd:chklmnrx")) != -1)
+	while ((ch = getopt(argc, argv, "HI:LPasd:cghklmnrx")) != -1)
 		switch (ch) {
 			case 'H':
 				Hflag = 1;
@@ -141,6 +141,11 @@
 			case 'c':
 				cflag = 1;
 				break;
+                        case 'g':
+                                hflag = 0;
+                                if (setenv("BLOCKSIZE", "1073741824", 1) == -1)
+                                        warn("setenv: cannot set BLOCKSIZE=1073741824");
+                                break;
 			case 'h':
 				if (setenv("BLOCKSIZE", "512", 1) == -1)
 					warn(
@@ -454,7 +459,7 @@
 {
 	(void)fprintf(stderr,
 		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] "
-		"[-l] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
+		"[-l] [-h | -k | -m | -g] [-n] [-x] [-I mask] [file ...]\n");
 	exit(EX_USAGE);
 }
 
--- usr.bin/du/du.1.orig	2008-04-29 21:38:22.000000000 +0100
+++ usr.bin/du/du.1	2008-05-05 12:57:47.000000000 +0100
@@ -60,41 +60,30 @@
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl a
+Display an entry for each file in a file hierarchy.
+.It Fl c
+Display a grand total.
+.It Fl d Ar depth
+Display an entry for all files and directories
+.Ar depth
+directories deep.
+.It Fl g
+Display block counts in 1073741824-byte (1-Gbyte) blocks.
 .It Fl H
 Symbolic links on the command line are followed, symbolic links in file
 hierarchies are not followed.
-.It Fl L
-Symbolic links on the command line and in file hierarchies are followed.
-.It Fl I Ar mask
-Ignore files and directories matching the specified
-.Ar mask .
-.It Fl P
-No symbolic links are followed.
-This is the default.
-.It Fl a
-Display an entry for each file in a file hierarchy.
 .It Fl h
 "Human-readable" output.
 Use unit suffixes: Byte, Kilobyte, Megabyte,
 Gigabyte, Terabyte and Petabyte.
-.It Fl r
-Generate messages about directories that cannot be read, files
-that cannot be opened, and so on.
-This is the default case.
-This option exists solely for conformance with
-.St -xpg4 .
-.It Fl s
-Display an entry for each specified file.
-(Equivalent to
-.Fl d Li 0 )
-.It Fl d Ar depth
-Display an entry for all files and directories
-.Ar depth
-directories deep.
-.It Fl c
-Display a grand total.
+.It Fl I Ar mask
+Ignore files and directories matching the specified
+.Ar mask .
 .It Fl k
 Display block counts in 1024-byte (1-Kbyte) blocks.
+.It Fl L
+Symbolic links on the command line and in file hierarchies are followed.
 .It Fl l
 If a file has multiple hard links, count its size many times.
 The default behavior of
@@ -112,6 +101,19 @@
 flag
 .Pq Dv UF_NODUMP
 set.
+.It Fl P
+No symbolic links are followed.
+This is the default.
+.It Fl r
+Generate messages about directories that cannot be read, files
+that cannot be opened, and so on.
+This is the default case.
+This option exists solely for conformance with
+.St -xpg4 .
+.It Fl s
+Display an entry for each specified file.
+(Equivalent to
+.Fl d Li 0 )
 .It Fl x
 File system mount points are not traversed.
 .El


>Release-Note:
>Audit-Trail:

From: Yoshihiro Ota <ota@j.email.ne.jp>
To: bug-followup@FreeBSD.org
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/123418: [patch] Add -g (Gbyte) option to du(1) + manpage
 cleanup
Date: Tue, 6 May 2008 03:44:56 -0400

 Isn't it better to use expand_number(3), instead?
 It will not only support Gbyte but more.
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Sat Dec 3 23:38:47 UTC 2011 
State-Changed-Why:  
Note that feedback was requested, but over a year ago :-/ 

To submitter: are you still interested in this PR? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123418 
State-Changed-From-To: feedback->open 
State-Changed-By: eadler 
State-Changed-When: Tue Nov 13 20:55:08 UTC 2012 
State-Changed-Why:  
no feedback provided, but the patch & request provides a starting point 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123418 
>Unformatted:
