Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/du PR/22405 -- extend du(1) to report inode usage. ...



details:   https://anonhg.NetBSD.org/src/rev/f5f242c73c58
branches:  trunk
changeset: 777977:f5f242c73c58
user:      shattered <shattered%NetBSD.org@localhost>
date:      Sun Mar 11 11:23:20 2012 +0000

description:
PR/22405 -- extend du(1) to report inode usage.  Patch provided by
Jonathan Perkin.

OK by wiz@

diffstat:

 usr.bin/du/du.1 |  11 +++++++----
 usr.bin/du/du.c |  36 ++++++++++++++++++++++++------------
 2 files changed, 31 insertions(+), 16 deletions(-)

diffs (161 lines):

diff -r c39f8682af8f -r f5f242c73c58 usr.bin/du/du.1
--- a/usr.bin/du/du.1   Sun Mar 11 10:21:25 2012 +0000
+++ b/usr.bin/du/du.1   Sun Mar 11 11:23:20 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: du.1,v 1.21 2006/09/24 07:19:16 wiz Exp $
+.\"    $NetBSD: du.1,v 1.22 2012/03/11 11:23:20 shattered Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    @(#)du.1        8.2 (Berkeley) 4/1/94
 .\"
-.Dd September 24, 2006
+.Dd March 4, 2012
 .Dt DU 1
 .Os
 .Sh NAME
@@ -39,12 +39,12 @@
 .Nm
 .Op Fl H | Fl L | Fl P
 .Op Fl a | Fl d Ar depth | Fl s
-.Op Fl cghkmnrx
+.Op Fl cghikmnrx
 .Op Ar file ...
 .Sh DESCRIPTION
 The
 .Nm
-utility displays the file system block usage for each file argument
+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 block usage of the hierarchy rooted in
@@ -79,6 +79,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
diff -r c39f8682af8f -r f5f242c73c58 usr.bin/du/du.c
--- a/usr.bin/du/du.c   Sun Mar 11 10:21:25 2012 +0000
+++ b/usr.bin/du/du.c   Sun Mar 11 11:23:20 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: du.c,v 1.35 2011/09/01 13:37:33 joerg Exp $    */
+/*     $NetBSD: du.c,v 1.36 2012/03/11 11:23:20 shattered Exp $        */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)du.c       8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: du.c,v 1.35 2011/09/01 13:37:33 joerg Exp $");
+__RCSID("$NetBSD: du.c,v 1.36 2012/03/11 11:23:20 shattered Exp $");
 #endif
 #endif /* not lint */
 
@@ -54,6 +54,7 @@
 #include <err.h>
 #include <errno.h>
 #include <fts.h>
+#include <inttypes.h>
 #include <util.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -61,11 +62,14 @@
 #include <unistd.h>
 #include <limits.h>
 
+/* Count inodes or file size */
+#define        COUNT   (iflag ? 1 : p->fts_statp->st_blocks)
+
 static int     linkchk(dev_t, ino_t);
 static void    prstat(const char *, int64_t);
 __dead static void     usage(void);
 
-static int hflag;
+static int hflag, iflag;
 static long blocksize;
 
 int
@@ -83,7 +87,7 @@
        totalblocks = 0;
        ftsoptions = FTS_PHYSICAL;
        depth = INT_MAX;
-       while ((ch = getopt(argc, argv, "HLPacd:ghkmnrsx")) != -1)
+       while ((ch = getopt(argc, argv, "HLPacd:ghikmnrsx")) != -1)
                switch (ch) {
                case 'H':
                        Hflag = 1;
@@ -118,6 +122,9 @@
                case 'h':
                        hflag = 1;
                        break;
+               case 'i':
+                       iflag = 1;
+                       break;
                case 'k':
                        blocksize = 1024;
                        gkmflag = 1;
@@ -206,9 +213,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
@@ -235,10 +242,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)
@@ -251,6 +258,11 @@
 static void
 prstat(const char *fname, int64_t blocks)
 {
+       if (iflag) {
+               (void)printf("%" PRId64 "\t%s\n", blocks, fname);
+               return;
+       }
+
        if (hflag) {
                char buf[5];
                int64_t sz = blocks * 512;
@@ -260,8 +272,8 @@
 
                (void)printf("%s\t%s\n", buf, fname);
        } else
-               (void)printf("%lld\t%s\n",
-                   (long long)howmany(blocks, (int64_t)blocksize),
+               (void)printf("%" PRId64 "\t%s\n",
+                   howmany(blocks, (int64_t)blocksize),
                    fname);
 }
 
@@ -345,6 +357,6 @@
 {
 
        (void)fprintf(stderr,
-               "usage: du [-H | -L | -P] [-a | -d depth | -s] [-cghkmnrx] [file ...]\n");
+               "usage: du [-H | -L | -P] [-a | -d depth | -s] [-cghikmnrx] [file ...]\n");
        exit(1);
 }



Home | Main Index | Thread Index | Old Index