Subject: bin/22405: inode support for du(1)
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <jonathan@perkin.org.uk>
List: netbsd-bugs
Date: 08/08/2003 14:20:40
>Number:         22405
>Category:       bin
>Synopsis:       inode support for du(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 08 14:21:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Jonathan Perkin
>Release:        1.6W
>Organization:
British Broadcasting Corporation
>Environment:
NetBSD munkeh.intra.nut 1.6W NetBSD 1.6W (GENERIC) #8: Thu Aug  7 10:59:33 BST 2003  sketch@munkeh.intra.nut:/usr/obj/sys/arch/sparc64/compile/GENERIC sparc64
>Description:
With large news spools for our NNTP and forum machines, we've found
it useful at the BBC to use a small tool to do du(1) style reporting
on directories, but counting inode usage (as that's what is in short
supply) rather than block usage.

As it's a simple hack, and pretty useful, I've patched the in-tree
du to do the same.  Patch below.
>How-To-Repeat:

>Fix:
Also at http://www.perkin.org.uk/projects/netbsd/du.diff

Index: du.1
===================================================================
RCS file: /cvsroot/src/usr.bin/du/du.1,v
retrieving revision 1.16
diff -u -r1.16 du.1
--- du.1        2003/04/18 13:16:50     1.16
+++ du.1        2003/08/08 14:03:47
@@ -43,16 +43,15 @@
 .Nm
 .Op Fl H | Fl L | Fl P
 .Op Fl a | Fl s
-.Op Fl cghkmrx
+.Op Fl cghikmrx
 .Op Ar file ...
 .Sh DESCRIPTION
 The
 .Nm
-utility displays the file system block usage for each file argument
-and for each directory in the file hierarchy rooted in each directory
-argument.
-If no file is specified, the block usage of the hierarchy rooted in
-the current directory is displayed.
+utility displays the file system usage for each file argument and for
+each directory in the file hierarchy rooted in each directory argument.
+If no file is specified, the usage of the hierarchy rooted in the
+current directory is displayed.
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
@@ -79,6 +78,9 @@
 format.
 Use unit suffixes: B (Byte), K (Kilobyte), M (Megabyte), G (Gigabyte),
 T (Terabyte) and P (Petabyte).
+.It Fl i
+Output inode usage instead of blocks.
+All "human-readable" options are ignored.
 .It Fl k
 By default,
 .Nm
Index: du.c
===================================================================
RCS file: /cvsroot/src/usr.bin/du/du.c,v
retrieving revision 1.22
diff -u -r1.22 du.c
--- du.c        2003/05/30 00:17:26     1.22
+++ du.c        2003/08/08 14:03:47
@@ -63,12 +63,15 @@
 #include <string.h>
 #include <unistd.h>
 
+/* Count inodes or file size */
+#define        COUNT   (iflag ? 1 : p->fts_statp->st_blocks)
+
 int    linkchk __P((FTSENT *));
 int    main __P((int, char **));
 void   prstat __P((const char *, int64_t));
 void   usage __P((void));
 
-int hflag;
+int hflag, iflag = 0;
 long blocksize;
 
 int
@@ -86,7 +89,7 @@
        Hflag = Lflag = Pflag = aflag = cflag = gkmflag = sflag = 0;
        totalblocks = 0;
        ftsoptions = FTS_PHYSICAL;
-       while ((ch = getopt(argc, argv, "HLPacghkmrsx")) != -1)
+       while ((ch = getopt(argc, argv, "HLPacghikmrsx")) != -1)
                switch (ch) {
                case 'H':
                        Hflag = 1;
@@ -113,6 +116,9 @@
                case 'h':
                        hflag = 1;
                        break;
+               case 'i':
+                       iflag = 1;
+                       break;
                case 'k':
                        blocksize = 1024;
                        gkmflag = 1;
@@ -185,9 +191,9 @@
                        break;
                case FTS_DP:
                        p->fts_parent->fts_number += 
-                           p->fts_number += p->fts_statp->st_blocks;
+                           p->fts_number += COUNT;
                        if (cflag)
-                               totalblocks += p->fts_statp->st_blocks;
+                               totalblocks += COUNT;
                        /*
                         * If listing each directory, or not listing files
                         * or directories and this is post-order of the
@@ -212,10 +218,10 @@
                         * the root of a traversal, display the total.
                         */
                        if (listfiles || !p->fts_level)
-                               prstat(p->fts_path, p->fts_statp->st_blocks);
-                       p->fts_parent->fts_number += p->fts_statp->st_blocks;
+                               prstat(p->fts_path, COUNT);
+                       p->fts_parent->fts_number += COUNT;
                        if (cflag)
-                               totalblocks += p->fts_statp->st_blocks;
+                               totalblocks += COUNT;
                }
        if (errno)
                err(1, "fts_read");
@@ -227,6 +233,11 @@
 void
 prstat(const char *fname, int64_t blocks)
 {
+       if (iflag) {
+               (void)printf("%lld\t%s\n", blocks, fname);
+               return;
+       }
+
        if (hflag) {
                char buf[5];
                int64_t sz = blocks * 512;
>Release-Note:
>Audit-Trail:
>Unformatted: