From nobody@FreeBSD.org  Fri Jul 17 08:04:02 2009
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 E211D106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 17 Jul 2009 08:04:01 +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 CF9BE8FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 17 Jul 2009 08:04:01 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n6H841dx036847
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 17 Jul 2009 08:04:01 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n6H841mH036843;
	Fri, 17 Jul 2009 08:04:01 GMT
	(envelope-from nobody)
Message-Id: <200907170804.n6H841mH036843@www.freebsd.org>
Date: Fri, 17 Jul 2009 08:04:01 GMT
From: "P.Moulin" <robert13223@caliopea.com (spamtrap)>
To: freebsd-gnats-submit@FreeBSD.org
Subject: "du" command: patch commited to permit per directory only sum (no heritage).
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         136857
>Category:       bin
>Synopsis:       [patch] du(1): permit per directory only sum (no heritage).
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    hiren
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 17 08:10:05 UTC 2009
>Closed-Date:    
>Last-Modified:  Tue May 14 23:20:00 UTC 2013
>Originator:     P.Moulin
>Release:        8.0b1
>Organization:
Calyopea
>Environment:
FreeBSD nc4000 8.0-BETA1 FreeBSD 8.0-BETA1 #0: Sat Jul  4 03:55:14 UTC 2009
root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
When using "du", no option permit only per directories files sum.
here is a patch (option -N (No heritage)) to solve this.

Warning, the mail address given below is a spamtrap. Good email is : p.moulin (at) calyopea_donotfeedanimals (dot) com  (remove _donotfeedanimals)


>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -C 5 du_ORIG/du.1 du/du.1
*** du_ORIG/du.1	Sun Mar 15 05:04:51 2009
--- du/du.1	Fri Jul 17 09:05:12 2009
***************
*** 39,50 ****
  .Nm du
  .Nd display disk usage statistics
  .Sh SYNOPSIS
  .Nm
  .Op Fl A
! .Op Fl H | L | P
! .Op Fl a | s | d Ar depth
  .Op Fl c
  .Op Fl l
  .Op Fl h | k | m | B Ar blocksize
  .Op Fl n
  .Op Fl x
--- 39,50 ----
  .Nm du
  .Nd display disk usage statistics
  .Sh SYNOPSIS
  .Nm
  .Op Fl A
! .Op Fl H | L | P 
! .Op Fl a | s | N | d Ar depth
  .Op Fl c
  .Op Fl l
  .Op Fl h | k | m | B Ar blocksize
  .Op Fl n
  .Op Fl x
***************
*** 89,98 ****
--- 89,101 ----
  Ignore files and directories matching the specified
  .Ar mask .
  .It Fl P
  No symbolic links are followed.
  This is the default.
+ .It Fl N
+ Print sum of files within directories only: do not heritate of children's 
+ directory size.
  .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,
Only in du: du.1.gz
diff -C 5 du_ORIG/du.c du/du.c
*** du_ORIG/du.c	Sun Mar 15 05:04:51 2009
--- du/du.c	Fri Jul 17 08:58:47 2009
***************
*** 89,117 ****
  	FTSENT		*p;
  	off_t		savednumber, curblocks;
  	int		ftsoptions;
  	int		listall;
  	int		depth;
! 	int		Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag;
  	int		hflag, lflag, ch, notused, rval;
  	char 		**save;
  	static char	dot[] = ".";
  
  	setlocale(LC_ALL, "");
  
  	Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag =
! 	    lflag = Aflag = 0;
  
  	save = argv;
  	ftsoptions = 0;
  	savednumber = 0;
  	cblocksize = DEV_BSIZE;
  	blocksize = 0;
  	depth = INT_MAX;
  	SLIST_INIT(&ignores);
  
! 	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrx")) != -1)
  		switch (ch) {
  		case 'A':
  			Aflag = 1;
  			break;
  		case 'B':
--- 89,117 ----
  	FTSENT		*p;
  	off_t		savednumber, curblocks;
  	int		ftsoptions;
  	int		listall;
  	int		depth;
! 	int		Hflag, Lflag, Pflag, Nflag, aflag, sflag, dflag, cflag;
  	int		hflag, lflag, ch, notused, rval;
  	char 		**save;
  	static char	dot[] = ".";
  
  	setlocale(LC_ALL, "");
  
  	Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag =
! 	    lflag = Aflag = Nflag = 0;
  
  	save = argv;
  	ftsoptions = 0;
  	savednumber = 0;
  	cblocksize = DEV_BSIZE;
  	blocksize = 0;
  	depth = INT_MAX;
  	SLIST_INIT(&ignores);
  
! 	while ((ch = getopt(argc, argv, "AB:HI:LPNasd:chklmnrx")) != -1)
  		switch (ch) {
  		case 'A':
  			Aflag = 1;
  			break;
  		case 'B':
***************
*** 137,146 ****
--- 137,149 ----
  		case 'P':
  			if (Lflag)
  				usage();
  			Pflag = 1;
  			break;
+ 		case 'N':
+ 			Nflag = 1;
+ 			break;
  		case 'a':
  			aflag = 1;
  			break;
  		case 's':
  			sflag = 1;
***************
*** 203,212 ****
--- 206,218 ----
  	 */
  
  	if (Hflag + Lflag + Pflag > 1)
  		usage();
  
+ 	if (sflag + Nflag > 1) /* meaningless */
+ 		usage();
+ 
  	if (Hflag + Lflag + Pflag == 0)
  		Pflag = 1;			/* -P (physical) is default */
  
  	if (Hflag)
  		ftsoptions |= FTS_COMFOLLOW;
***************
*** 262,274 ****
  				break;
  
  			curblocks = Aflag ?
  			    howmany(p->fts_statp->st_size, cblocksize) :
  			    howmany(p->fts_statp->st_blocks, cblocksize);
! 			p->fts_parent->fts_bignum += p->fts_bignum +=
! 			    curblocks;
! 
  			if (p->fts_level <= depth) {
  				if (hflag) {
  					prthumanval(p->fts_bignum);
  					(void)printf("\t%s\n", p->fts_path);
  				} else {
--- 268,281 ----
  				break;
  
  			curblocks = Aflag ?
  			    howmany(p->fts_statp->st_size, cblocksize) :
  			    howmany(p->fts_statp->st_blocks, cblocksize);
! 			if (!Nflag) {
! 			    p->fts_parent->fts_bignum += p->fts_bignum +=
! 				    curblocks;
! 			}
  			if (p->fts_level <= depth) {
  				if (hflag) {
  					prthumanval(p->fts_bignum);
  					(void)printf("\t%s\n", p->fts_path);
  				} else {


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->hiren 
Responsible-Changed-By: hiren 
Responsible-Changed-When: Tue May 14 23:18:50 UTC 2013 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=136857 

From: hiren panchasara <hiren@FreeBSD.org>
To: bug-followup@FreeBSD.org, p.moulin@calyopea.com
Cc:  
Subject: Re: bin/136857: [patch] du(1): permit per directory only sum (no heritage).
Date: Tue, 14 May 2013 16:18:26 -0700

 I am probably not getting what you intend to do here.
 
 Is it "du -d 0" (no hierarchy) that you are looking for?
 
 Can you please explain with an example?
 
 cheers,
 Hiren
>Unformatted:
