Module Name: src
Committed By: shattered
Date: Sun Mar 11 11:23:20 UTC 2012
Modified Files:
src/usr.bin/du: du.1 du.c
Log Message:
PR/22405 -- extend du(1) to report inode usage. Patch provided by
Jonathan Perkin.
OK by wiz@
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/du/du.1
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/du/du.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/du/du.1
diff -u src/usr.bin/du/du.1:1.21 src/usr.bin/du/du.1:1.22
--- src/usr.bin/du/du.1:1.21 Sun Sep 24 07:19:16 2006
+++ src/usr.bin/du/du.1 Sun Mar 11 11:23:20 2012
@@ -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 @@ flag is specified, the numbers will be d
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: src/usr.bin/du/du.c
diff -u src/usr.bin/du/du.c:1.35 src/usr.bin/du/du.c:1.36
--- src/usr.bin/du/du.c:1.35 Thu Sep 1 13:37:33 2011
+++ src/usr.bin/du/du.c Sun Mar 11 11:23:20 2012
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
#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 @@ __RCSID("$NetBSD: du.c,v 1.35 2011/09/01
#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 @@ __RCSID("$NetBSD: du.c,v 1.35 2011/09/01
#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 @@ main(int argc, char *argv[])
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 @@ main(int argc, char *argv[])
case 'h':
hflag = 1;
break;
+ case 'i':
+ iflag = 1;
+ break;
case 'k':
blocksize = 1024;
gkmflag = 1;
@@ -206,9 +213,9 @@ main(int argc, char *argv[])
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 @@ main(int argc, char *argv[])
* 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 @@ main(int argc, char *argv[])
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 @@ prstat(const char *fname, int64_t blocks
(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 @@ usage(void)
{
(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);
}