From pdp@nl.demon.net  Tue Apr 15 03:22:38 2003
Return-Path: <pdp@nl.demon.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id A404537B401
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 15 Apr 2003 03:22:38 -0700 (PDT)
Received: from hermes.mail.nl.demon.net (hermes.mail.nl.demon.net [194.159.72.197])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A02C143FAF
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 15 Apr 2003 03:22:37 -0700 (PDT)
	(envelope-from pdp@nl.demon.net)
Received: from samhain.noc.nl.demon.net ([194.159.72.214])
	by hermes.mail.nl.demon.net with esmtp (Exim 3.36 #1)
	id 195NaG-0002GR-00
	for FreeBSD-gnats-submit@freebsd.org; Tue, 15 Apr 2003 12:22:36 +0200
Received: by samhain.noc.nl.demon.net with local 
	id 195NaD-000AfS-00; Tue, 15 Apr 2003 10:22:33 +0000
Message-Id: <E195NaD-000AfS-00@samhain.noc.nl.demon.net>
Date: Tue, 15 Apr 2003 10:22:33 +0000
From: Phil Pennock <pdp@nl.demon.net>
Reply-To: Phil Pennock <pdp@nl.demon.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: du(1) doesn't understand UF_NODUMP flag
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         50971
>Category:       bin
>Synopsis:       du(1) doesn't understand UF_NODUMP flag
>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 Apr 15 03:30:11 PDT 2003
>Closed-Date:    Sun May 07 09:31:51 GMT 2006
>Last-Modified:  Sun May 07 09:31:51 GMT 2006
>Originator:     Phil Pennock
>Release:        FreeBSD 4.7-RELEASE-p6 i386
>Organization:
THUS Plc (Demon Internet Netherlands)
>Environment:
System: FreeBSD samhain.noc.nl.demon.net 4.7-RELEASE-p6 FreeBSD 4.7-RELEASE-p6 #0: Mon Feb 24 13:28:19 GMT 2003 root@samhain.noc.nl.demon.net:/usr/src/sys/compile/SAMHAIN i386


>Description:
FreeBSD supports the user-flag "nodump" on files, to indicate to tools such
as dump(8) that the file should not be backed up and, in recent FreeBSD, if
set on a directory to indicate that the tree should be pruned at that point.

There's no way to emulate this with du(1), which makes estimates of backup
usage more tricky.

This patch adds a -D flag to du(1) to honour UF_NODUMP and documents this
in the man-page.  du.c was 1.17.2.3
>How-To-Repeat:
Take a directory tree, put some largish files in it, mark some nodump with
chflags(1).  Compare size with normal du(1) output, and output from this
du(1) with and without the -D flag.
>Fix:
diff -Pru /usr/src/usr.bin/du/du.1 ./du.1
--- /usr/src/usr.bin/du/du.1	Tue Nov 12 18:43:18 2002
+++ ./du.1	Tue Apr 15 11:59:04 2003
@@ -65,6 +65,15 @@
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl D
+Honor the user
+.Dq nodump
+flag, so that output is closer to figures for
+.Xr dump 8
+usage; presence of the
+.Pq Dv UF_NODUMP
+flag on a directory truncates directory traversal, and on a file causes
+the file size to not be included in the usage figures.
 .It Fl H
 Symbolic links on the command line are followed, symbolic links in file
 hierarchies are not followed.
diff -Pru /usr/src/usr.bin/du/du.c ./du.c
--- /usr/src/usr.bin/du/du.c	Thu Jul 12 10:46:53 2001
+++ ./du.c	Tue Apr 15 12:04:07 2003
@@ -115,18 +115,21 @@
 	int		ftsoptions;
 	int		listall;
 	int		depth;
-	int		Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval;
+	int		Dflag, Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval;
 	char 		**save;
 
-	Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0;
+	Dflag = Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0;
 	
 	save = argv;
 	ftsoptions = 0;
 	depth = INT_MAX;
 	SLIST_INIT(&ignores);
 	
-	while ((ch = getopt(argc, argv, "HI:LPasd:chkrx")) != -1)
+	while ((ch = getopt(argc, argv, "DHI:LPasd:chkrx")) != -1)
 		switch (ch) {
+			case 'D':
+				Dflag = 1;
+				break;
 			case 'H':
 				Hflag = 1;
 				break;
@@ -241,11 +244,18 @@
 			case FTS_D:			/* Ignore. */
 				if (ignorep(p))
 					fts_set(fts, p, FTS_SKIP);
+				if (Dflag &&
+				    (p->fts_statp->st_flags & UF_NODUMP))
+					fts_set(fts, p, FTS_SKIP);
 				break;
 			case FTS_DP:
 				if (ignorep(p))
 					break;
 
+				if (Dflag &&
+				    (p->fts_statp->st_flags & UF_NODUMP))
+					break;
+
 				p->fts_parent->fts_number +=
 				    p->fts_number += p->fts_statp->st_blocks;
 				
@@ -270,6 +280,10 @@
 				break;
 			default:
 				if (ignorep(p))
+					break;
+
+				if (Dflag &&
+				    (p->fts_statp->st_flags & UF_NODUMP))
 					break;
 
 				if (p->fts_statp->st_nlink > 1 && linkchk(p))
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Sun May 7 09:29:17 UTC 2006 
State-Changed-Why:  
Phil, I didn't noticed your PR and committed a sligthly different 
code with the same functionality from bin/96864 to HEAD.  Sorry 
it took so long and thanks for the contribution. 

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