From doconnor@cain.gsoft.com.au  Tue Sep  2 01:14:53 2008
Return-Path: <doconnor@cain.gsoft.com.au>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id BF526106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  2 Sep 2008 01:14:53 +0000 (UTC)
	(envelope-from doconnor@cain.gsoft.com.au)
Received: from cain.gsoft.com.au (cain.gsoft.com.au [203.31.81.10])
	by mx1.freebsd.org (Postfix) with ESMTP id 2A5BE8FC1E
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  2 Sep 2008 01:14:52 +0000 (UTC)
	(envelope-from doconnor@cain.gsoft.com.au)
Received: from cain.gsoft.com.au (localhost [127.0.0.1])
	by cain.gsoft.com.au (8.13.8/8.13.8) with ESMTP id m820xQXC084973
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 2 Sep 2008 10:29:26 +0930 (CST)
	(envelope-from doconnor@cain.gsoft.com.au)
Received: (from doconnor@localhost)
	by cain.gsoft.com.au (8.13.8/8.13.8/Submit) id m820xPoK084972;
	Tue, 2 Sep 2008 10:29:25 +0930 (CST)
	(envelope-from doconnor)
Message-Id: <200809020059.m820xPoK084972@cain.gsoft.com.au>
Date: Tue, 2 Sep 2008 10:29:25 +0930 (CST)
From: "Daniel O'Connor" <doconnor@gsoft.com.au>
Reply-To: "Daniel O'Connor" <doconnor@gsoft.com.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Add option to count apparent size to du
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         127034
>Category:       bin
>Synopsis:       [patch] Add option to count apparent size to du(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 02 01:20:02 UTC 2008
>Closed-Date:    Fri Oct 15 21:10:56 UTC 2010
>Last-Modified:  Fri Oct 15 21:10:56 UTC 2010
>Originator:     Daniel O'Connor
>Release:        FreeBSD 8.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD inchoate.localdomain 8.0-CURRENT FreeBSD 8.0-CURRENT #3: Thu Feb 7 15:35:09 CST 2008 root@inchoate.localdomain:/usr/src/sys/i386/compile/INCHOATE i386


>Description:
Add an option (-b) which counts the apparent file size reported by stat rather than
blocks used. This is useful when determining how much space a compressed ZFS file
will used when copied somewhere else.

>How-To-Repeat:
>Fix:
Patch is at
http://www.gsoft.com.au/~doconnor/du-apparentsize.diff

or SHAR'd below

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	/remotehome/darius/www/du-apparentsize.diff
#
echo x - /remotehome/darius/www/du-apparentsize.diff
sed 's/^X//' >/remotehome/darius/www/du-apparentsize.diff << 'END-of-/remotehome/darius/www/du-apparentsize.diff'
XIndex: du.1
X===================================================================
XRCS file: /usr/CVS-Repository/src/usr.bin/du/du.1,v
Xretrieving revision 1.32
Xdiff -u -r1.32 du.1
X--- du.1	29 Sep 2006 15:20:44 -0000	1.32
X+++ du.1	2 Sep 2008 00:55:18 -0000
X@@ -42,7 +42,7 @@
X .Nm
X .Op Fl H | L | P
X .Op Fl a | s | d Ar depth
X-.Op Fl c
X+.Op Fl b c
X .Op Fl h | k | m
X .Op Fl n
X .Op Fl x
X@@ -72,6 +72,8 @@
X This is the default.
X .It Fl a
X Display an entry for each file in a file hierarchy.
X+.It Fl b
X+Count the apparent file size (rather than blocks used)
X .It Fl h
X "Human-readable" output.
X Use unit suffixes: Byte, Kilobyte, Megabyte,
XIndex: du.c
X===================================================================
XRCS file: /usr/CVS-Repository/src/usr.bin/du/du.c,v
Xretrieving revision 1.42
Xdiff -u -r1.42 du.c
X--- du.c	4 Jul 2007 00:00:39 -0000	1.42
X+++ du.c	2 Sep 2008 00:51:13 -0000
X@@ -90,20 +90,20 @@
X 	int		ftsoptions;
X 	int		listall;
X 	int		depth;
X-	int		Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval;
X+	int		Hflag, Lflag, Pflag, aflag, bflag, sflag, dflag, cflag, hflag, ch, notused, rval;
X 	char 		**save;
X 	static char	dot[] = ".";
X 
X 	setlocale(LC_ALL, "");
X 
X-	Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0;
X+	Hflag = Lflag = Pflag = aflag = bflag = sflag = dflag = cflag = hflag = 0;
X 
X 	save = argv;
X 	ftsoptions = 0;
X 	depth = INT_MAX;
X 	SLIST_INIT(&ignores);
X 
X-	while ((ch = getopt(argc, argv, "HI:LPasd:chkmnrx")) != -1)
X+	while ((ch = getopt(argc, argv, "HI:LPabsd:chkmnrx")) != -1)
X 		switch (ch) {
X 			case 'H':
X 				Hflag = 1;
X@@ -124,6 +124,9 @@
X 			case 'a':
X 				aflag = 1;
X 				break;
X+			case 'b':
X+				bflag = 1;
X+				break;
X 			case 's':
X 				sflag = 1;
X 				break;
X@@ -231,8 +234,12 @@
X 				if (ignorep(p))
X 					break;
X 
X-				p->fts_parent->fts_bignum +=
X-				    p->fts_bignum += p->fts_statp->st_blocks;
X+				if (bflag)
X+					p->fts_parent->fts_bignum +=
X+						p->fts_bignum += p->fts_statp->st_size / 512;
X+				else
X+				    p->fts_parent->fts_bignum +=
X+				    	p->fts_bignum += p->fts_statp->st_blocks;
X 
X 				if (p->fts_level <= depth) {
X 					if (hflag) {
X@@ -262,17 +269,29 @@
X 
X 				if (listall || p->fts_level == 0) {
X 					if (hflag) {
X-						(void) prthumanval(howmany(p->fts_statp->st_blocks,
X-							blocksize));
X+						if (bflag)
X+							(void) prthumanval(howmany(p->fts_statp->st_size / 512,
X+								blocksize));
X+						else
X+							(void) prthumanval(howmany(p->fts_statp->st_blocks,
X+								blocksize));
X 						(void) printf("\t%s\n", p->fts_path);
X 					} else {
X-						(void) printf("%jd\t%s\n",
X-							(intmax_t)howmany(p->fts_statp->st_blocks, blocksize),
X-							p->fts_path);
X+						if (bflag)
X+							(void) printf("%jd\t%s\n",
X+								(intmax_t)howmany(p->fts_statp->st_size / 512,
X+									blocksize), p->fts_path);
X+						else
X+							(void) printf("%jd\t%s\n",
X+								(intmax_t)howmany(p->fts_statp->st_blocks,
X+									blocksize), p->fts_path);
X 					}
X 				}
X 
X-				p->fts_parent->fts_bignum += p->fts_statp->st_blocks;
X+				if (bflag)
X+					p->fts_parent->fts_bignum += p->fts_statp->st_size / 512;
X+				else
X+					p->fts_parent->fts_bignum += p->fts_statp->st_blocks;
X 		}
X 		savednumber = p->fts_parent->fts_bignum;
X 	}
X@@ -443,7 +462,7 @@
X usage(void)
X {
X 	(void)fprintf(stderr,
X-		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
X+		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-b] [-c] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
X 	exit(EX_USAGE);
X }
X 
END-of-/remotehome/darius/www/du-apparentsize.diff
exit


>Release-Note:
>Audit-Trail:

State-Changed-From-To: open->closed 
State-Changed-By: jilles 
State-Changed-When: Fri Oct 15 21:10:55 UTC 2010 
State-Changed-Why:  
This was added about two years ago, to 7.x, 8.x and newer. 

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