bin/127034: Add option to count apparent size to du

Daniel O'Connor doconnor at gsoft.com.au
Tue Sep 2 01:20:03 UTC 2008


>Number:         127034
>Category:       bin
>Synopsis:       Add option to count apparent size to du
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 02 01:20:02 UTC 2008
>Closed-Date:
>Last-Modified:
>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 at 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:
>Unformatted:


More information about the freebsd-bugs mailing list