Subject: Re: du -n - ignore "nodump" files
To: Simon Burge <simonb@wasabisystems.com>
From: Greg Troxel <gdt@ir.bbn.com>
List: tech-userlevel
Date: 02/27/2003 13:25:19
For what it's worth, I implemented this a few weeks ago for the exact
same reason, and chose '-n' as well. So it's intuitive to me.
Here's my patch in case it is at all useful.
Index: du.1
===================================================================
RCS file: /QUIST-CVS/netbsd/src/usr.bin/du/du.1,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- du.1 2001/12/01 19:03:31 1.1.1.2
+++ du.1 2003/02/13 13:59:46 1.2
@@ -43,7 +43,7 @@
.Nm
.Op Fl H | Fl L | Fl P
.Op Fl a | Fl s
-.Op Fl ckmrx
+.Op Fl ckmnrx
.Op Ar file ...
.Sh DESCRIPTION
The
@@ -75,6 +75,11 @@
.Fl k
flag is specified, the number displayed is the number of kilobyte
(1024 bytes) blocks. Partial numbers of blocks are rounded up.
+.It Fl n
+Files and directories with the nodump flag set are treated as if they
+were zero size. Directories with the nodump flag set are not
+traversed. This is intended to mimic the behavior of
+.Xr dump 8 .
.It Fl m
If the
.Fl m
Index: du.c
===================================================================
RCS file: /QUIST-CVS/netbsd/src/usr.bin/du/du.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -u -r1.1.1.2 -r1.2
--- du.c 2001/01/04 23:05:54 1.1.1.2
+++ du.c 2003/02/13 13:59:46 1.2
@@ -76,13 +76,15 @@
long blocksize, totalblocks;
int ftsoptions, listdirs, listfiles;
int Hflag, Lflag, Pflag, aflag, ch, cflag, kmflag, notused, rval, sflag;
+ int nflag;
char **save;
save = argv;
Hflag = Lflag = Pflag = aflag = cflag = kmflag = sflag = 0;
+ nflag = 0;
totalblocks = 0;
ftsoptions = FTS_PHYSICAL;
- while ((ch = getopt(argc, argv, "HLPackmrsx")) != -1)
+ while ((ch = getopt(argc, argv, "HLPackmnrsx")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -110,6 +112,9 @@
blocksize = 1024 * 1024;
kmflag = 1;
break;
+ case 'n':
+ nflag = 1;
+ break;
case 'r':
break;
case 's':
@@ -171,8 +176,16 @@
for (rval = 0; (p = fts_read(fts)) != NULL;)
switch (p->fts_info) {
case FTS_D: /* Ignore. */
+ /* Ignore anything with nodump set. */
+ if (nflag && (p->fts_statp->st_flags & UF_NODUMP))
+ fts_set(fts, p, FTS_SKIP);
break;
+
case FTS_DP:
+ /* Treat files with nodump set as zero sized. */
+ if (nflag && (p->fts_statp->st_flags & UF_NODUMP))
+ p->fts_statp->st_blocks = 0;
+
p->fts_parent->fts_number +=
p->fts_number += p->fts_statp->st_blocks;
if (cflag)
@@ -196,6 +209,9 @@
rval = 1;
break;
default:
+ if (nflag && (p->fts_statp->st_flags & UF_NODUMP))
+ p->fts_statp->st_blocks = 0;
+
if (p->fts_statp->st_nlink > 1 && linkchk(p))
break;
/*