From nobody@FreeBSD.org  Mon Feb 22 01:23:49 2010
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 BD8621065768
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 22 Feb 2010 01:23:48 +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 BA3738FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 22 Feb 2010 01:23:48 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o1M1Nmg2001739
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 22 Feb 2010 01:23:48 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o1M1NmKZ001738;
	Mon, 22 Feb 2010 01:23:48 GMT
	(envelope-from nobody)
Message-Id: <201002220123.o1M1NmKZ001738@www.freebsd.org>
Date: Mon, 22 Feb 2010 01:23:48 GMT
From: Gleb Kurtsou <gk@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] support for thresholds in du(1)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         144192
>Category:       bin
>Synopsis:       [patch] support for thresholds in du(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brian
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 22 01:30:02 UTC 2010
>Closed-Date:    Sun Jul 11 22:01:36 UTC 2010
>Last-Modified:  Sun Jul 11 22:01:36 UTC 2010
>Originator:     Gleb Kurtsou
>Release:        
>Organization:
>Environment:
FreeBSD tops 9.0-CURRENT FreeBSD 9.0-CURRENT #17 r203556+e02bf32: Mon Feb 22 03:04:35 EET 2010     root@tops:/usr/obj/freebsd-src/local/sys/TOPS  amd64
>Description:
Patch has already been discussed on freebsd-hackers@:
http://lists.freebsd.org/pipermail/freebsd-hackers/2010-February/030581.html

Submitting PR so it doesn't get lost. Attached version is a bit different from original patch, I've change variable types to int64_t as suggested by Xin Li.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff --git a/usr.bin/du/du.1 b/usr.bin/du/du.1
index af2ff84..b0e1748 100644
--- a/usr.bin/du/du.1
+++ b/usr.bin/du/du.1
@@ -42,7 +42,7 @@
 .Nm
 .Op Fl A
 .Op Fl H | L | P
-.Op Fl a | s | d Ar depth
+.Op Fl a | s | d Ar depth | t Ar threshold
 .Op Fl c
 .Op Fl l
 .Op Fl h | k | m | B Ar blocksize
@@ -107,6 +107,14 @@ This option exists solely for conformance with
 Display an entry for each specified file.
 (Equivalent to
 .Fl d Li 0 )
+.It Fl t Ar threshold
+Display only entries for which size exceeds
+.Ar threshold .
+If
+.Ar threshold
+is negative, display only entries for which size is less then absolute
+value of
+.Ar threshold .
 .It Fl d Ar depth
 Display an entry for all files and directories
 .Ar depth
diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c
index 63677f5..761a1ab 100644
--- a/usr.bin/du/du.c
+++ b/usr.bin/du/du.c
@@ -90,6 +90,7 @@ main(int argc, char *argv[])
 	FTS		*fts;
 	FTSENT		*p;
 	off_t		savednumber, curblocks;
+	off_t		threshold, threshold_sign;
 	int		ftsoptions;
 	int		listall;
 	int		depth;
@@ -106,12 +107,14 @@ main(int argc, char *argv[])
 	save = argv;
 	ftsoptions = 0;
 	savednumber = 0;
+	threshold = 0;
+	threshold_sign = 1;
 	cblocksize = DEV_BSIZE;
 	blocksize = 0;
 	depth = INT_MAX;
 	SLIST_INIT(&ignores);
 
-	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrx")) != -1)
+	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrt:x")) != -1)
 		switch (ch) {
 		case 'A':
 			Aflag = 1;
@@ -179,6 +182,14 @@ main(int argc, char *argv[])
 			break;
 		case 'r':		 /* Compatibility. */
 			break;
+		case 't' :
+			if (expand_number(optarg, &threshold) != 0 ||
+			    threshold == 0) {
+				warnx("invalid threshold: %s", optarg);
+				usage();
+			} else if (threshold < 0)
+				threshold_sign = -1;
+			break;
 		case 'x':
 			ftsoptions |= FTS_XDEV;
 			break;
@@ -248,6 +259,10 @@ main(int argc, char *argv[])
 		blocksize /= DEV_BSIZE;
 	}
 
+	if (threshold != 0)
+		threshold = howmany(threshold / DEV_BSIZE * cblocksize,
+		    blocksize);
+
 	rval = 0;
 
 	(void)signal(SIGINFO, siginfo);
@@ -271,7 +286,9 @@ main(int argc, char *argv[])
 			p->fts_parent->fts_bignum += p->fts_bignum +=
 			    curblocks;
 
-			if (p->fts_level <= depth) {
+			if (p->fts_level <= depth && threshold <=
+			    threshold_sign * howmany(p->fts_bignum *
+			    cblocksize, blocksize)) {
 				if (hflag) {
 					prthumanval(p->fts_bignum);
 					(void)printf("\t%s\n", p->fts_path);


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: brian 
State-Changed-When: Sun Jun 20 08:25:50 UTC 2010 
State-Changed-Why:  
I've submitted this to head (r209362) and will MFC after 3 weeks. 

IMHO this flag is a brilliantly simple idea. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/144192: commit references a PR
Date: Sun, 20 Jun 2010 08:27:13 +0000 (UTC)

 Author: brian
 Date: Sun Jun 20 08:27:03 2010
 New Revision: 209362
 URL: http://svn.freebsd.org/changeset/base/209362
 
 Log:
   Add a -t switch for masking output that's above or below certain thresholds.
   This switch makes it a lot easier to locate problem areas when a process
   is threatening to consume all of your disk space.
   
   PR:		144192
   Submitted by:	gk
   MFC after:	3 weeks
 
 Modified:
   head/usr.bin/du/du.1
   head/usr.bin/du/du.c
 
 Modified: head/usr.bin/du/du.1
 ==============================================================================
 --- head/usr.bin/du/du.1	Sun Jun 20 08:03:06 2010	(r209361)
 +++ head/usr.bin/du/du.1	Sun Jun 20 08:27:03 2010	(r209362)
 @@ -42,7 +42,7 @@
  .Nm
  .Op Fl A
  .Op Fl H | L | P
 -.Op Fl a | s | d Ar depth
 +.Op Fl a | s | d Ar depth | Fl t Ar threshold
  .Op Fl c
  .Op Fl l
  .Op Fl h | k | m | B Ar blocksize
 @@ -107,6 +107,14 @@ This option exists solely for conformanc
  Display an entry for each specified file.
  (Equivalent to
  .Fl d Li 0 )
 +.It Fl t Ar threshold
 +Display only entries for which size exceeds
 +.Ar threshold .
 +If
 +.Ar threshold
 +is negative, display only entries for which size is less than the absolute
 +value of
 +.Ar threshold .
  .It Fl d Ar depth
  Display an entry for all files and directories
  .Ar depth
 
 Modified: head/usr.bin/du/du.c
 ==============================================================================
 --- head/usr.bin/du/du.c	Sun Jun 20 08:03:06 2010	(r209361)
 +++ head/usr.bin/du/du.c	Sun Jun 20 08:27:03 2010	(r209362)
 @@ -90,6 +90,7 @@ main(int argc, char *argv[])
  	FTS		*fts;
  	FTSENT		*p;
  	off_t		savednumber, curblocks;
 +	off_t		threshold, threshold_sign;
  	int		ftsoptions;
  	int		listall;
  	int		depth;
 @@ -106,12 +107,14 @@ main(int argc, char *argv[])
  	save = argv;
  	ftsoptions = 0;
  	savednumber = 0;
 +	threshold = 0;
 +	threshold_sign = 1;
  	cblocksize = DEV_BSIZE;
  	blocksize = 0;
  	depth = INT_MAX;
  	SLIST_INIT(&ignores);
  
 -	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrx")) != -1)
 +	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrt:x")) != -1)
  		switch (ch) {
  		case 'A':
  			Aflag = 1;
 @@ -179,6 +182,14 @@ main(int argc, char *argv[])
  			break;
  		case 'r':		 /* Compatibility. */
  			break;
 +		case 't' :
 +			if (expand_number(optarg, &threshold) != 0 ||
 +			    threshold == 0) {
 +				warnx("invalid threshold: %s", optarg);
 +				usage();
 +			} else if (threshold < 0)
 +				threshold_sign = -1;
 +			break;
  		case 'x':
  			ftsoptions |= FTS_XDEV;
  			break;
 @@ -248,6 +259,10 @@ main(int argc, char *argv[])
  		blocksize /= DEV_BSIZE;
  	}
  
 +	if (threshold != 0)
 +		threshold = howmany(threshold / DEV_BSIZE * cblocksize,
 +		    blocksize);
 +
  	rval = 0;
  
  	(void)signal(SIGINFO, siginfo);
 @@ -271,7 +286,9 @@ main(int argc, char *argv[])
  			p->fts_parent->fts_bignum += p->fts_bignum +=
  			    curblocks;
  
 -			if (p->fts_level <= depth) {
 +			if (p->fts_level <= depth && threshold <=
 +			    threshold_sign * howmany(p->fts_bignum *
 +			    cblocksize, blocksize)) {
  				if (hflag) {
  					prthumanval(p->fts_bignum);
  					(void)printf("\t%s\n", p->fts_path);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
Responsible-Changed-From-To: freebsd-bugs->brian 
Responsible-Changed-By: brian 
Responsible-Changed-When: Sun Jun 20 19:56:06 UTC 2010 
Responsible-Changed-Why:  
Take 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/144192: commit references a PR
Date: Sun, 11 Jul 2010 21:49:46 +0000 (UTC)

 Author: brian
 Date: Sun Jul 11 21:47:38 2010
 New Revision: 209911
 URL: http://svn.freebsd.org/changeset/base/209911
 
 Log:
   MFC r209362: Add a -t switch for masking output based on size.
   
   PR:		144192
   Submitted by:	gk
 
 Modified:
   stable/8/usr.bin/du/du.1
   stable/8/usr.bin/du/du.c
 Directory Properties:
   stable/8/usr.bin/du/   (props changed)
 
 Modified: stable/8/usr.bin/du/du.1
 ==============================================================================
 --- stable/8/usr.bin/du/du.1	Sun Jul 11 21:12:42 2010	(r209910)
 +++ stable/8/usr.bin/du/du.1	Sun Jul 11 21:47:38 2010	(r209911)
 @@ -42,7 +42,7 @@
  .Nm
  .Op Fl A
  .Op Fl H | L | P
 -.Op Fl a | s | d Ar depth
 +.Op Fl a | s | d Ar depth | Fl t Ar threshold
  .Op Fl c
  .Op Fl l
  .Op Fl h | k | m | B Ar blocksize
 @@ -107,6 +107,14 @@ This option exists solely for conformanc
  Display an entry for each specified file.
  (Equivalent to
  .Fl d Li 0 )
 +.It Fl t Ar threshold
 +Display only entries for which size exceeds
 +.Ar threshold .
 +If
 +.Ar threshold
 +is negative, display only entries for which size is less than the absolute
 +value of
 +.Ar threshold .
  .It Fl d Ar depth
  Display an entry for all files and directories
  .Ar depth
 
 Modified: stable/8/usr.bin/du/du.c
 ==============================================================================
 --- stable/8/usr.bin/du/du.c	Sun Jul 11 21:12:42 2010	(r209910)
 +++ stable/8/usr.bin/du/du.c	Sun Jul 11 21:47:38 2010	(r209911)
 @@ -90,6 +90,7 @@ main(int argc, char *argv[])
  	FTS		*fts;
  	FTSENT		*p;
  	off_t		savednumber, curblocks;
 +	off_t		threshold, threshold_sign;
  	int		ftsoptions;
  	int		listall;
  	int		depth;
 @@ -106,12 +107,14 @@ main(int argc, char *argv[])
  	save = argv;
  	ftsoptions = 0;
  	savednumber = 0;
 +	threshold = 0;
 +	threshold_sign = 1;
  	cblocksize = DEV_BSIZE;
  	blocksize = 0;
  	depth = INT_MAX;
  	SLIST_INIT(&ignores);
  
 -	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrx")) != -1)
 +	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrt:x")) != -1)
  		switch (ch) {
  		case 'A':
  			Aflag = 1;
 @@ -179,6 +182,14 @@ main(int argc, char *argv[])
  			break;
  		case 'r':		 /* Compatibility. */
  			break;
 +		case 't' :
 +			if (expand_number(optarg, &threshold) != 0 ||
 +			    threshold == 0) {
 +				warnx("invalid threshold: %s", optarg);
 +				usage();
 +			} else if (threshold < 0)
 +				threshold_sign = -1;
 +			break;
  		case 'x':
  			ftsoptions |= FTS_XDEV;
  			break;
 @@ -248,6 +259,10 @@ main(int argc, char *argv[])
  		blocksize /= DEV_BSIZE;
  	}
  
 +	if (threshold != 0)
 +		threshold = howmany(threshold / DEV_BSIZE * cblocksize,
 +		    blocksize);
 +
  	rval = 0;
  
  	(void)signal(SIGINFO, siginfo);
 @@ -271,7 +286,9 @@ main(int argc, char *argv[])
  			p->fts_parent->fts_bignum += p->fts_bignum +=
  			    curblocks;
  
 -			if (p->fts_level <= depth) {
 +			if (p->fts_level <= depth && threshold <=
 +			    threshold_sign * howmany(p->fts_bignum *
 +			    cblocksize, blocksize)) {
  				if (hflag) {
  					prthumanval(p->fts_bignum);
  					(void)printf("\t%s\n", p->fts_path);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: brian 
State-Changed-When: Sun Jul 11 22:00:58 UTC 2010 
State-Changed-Why:  
Merged to stable/8, r209911 

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