NetBSD Problem Report #22405
Received: (qmail 18944 invoked by uid 605); 8 Aug 2003 14:20:41 -0000
Message-Id: <20030808142040.6DDE911152@narn.netbsd.org>
Date: Fri, 8 Aug 2003 14:20:40 +0000 (UTC)
From: jonathan@perkin.org.uk
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: jonathan@perkin.org.uk
To: gnats-bugs@gnats.NetBSD.org
Subject: inode support for du(1)
X-Send-Pr-Version: www-1.0
>Number: 22405
>Category: bin
>Synopsis: inode support for du(1)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Fri Aug 08 14:21:00 +0000 2003
>Closed-Date: Sun Mar 11 17:20:41 +0000 2012
>Last-Modified: Sun Mar 11 17:20:41 +0000 2012
>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:
From: Christian Biere <christianbiere@gmx.de>
To: jonathan@perkin.org.uk
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/22405: inode support for du(1)
Date: Fri, 8 Aug 2003 23:33:35 +0200
jonathan@perkin.org.uk wrote:
> >Synopsis: inode support for du(1)
> @@ -227,6 +233,11 @@
> void
> prstat(const char *fname, int64_t blocks)
> {
> + if (iflag) {
> + (void)printf("%lld\t%s\n", blocks, fname);
You better use PRId64 instead of "%lld". <sys/inttypes.h> must be
included to make it available.
--
Christian
From: Jonathan Perkin <jonathan@perkin.org.uk>
To: Christian Biere <christianbiere@gmx.de>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: bin/22405: inode support for du(1)
Date: Mon, 11 Aug 2003 09:51:16 +0100
* On 2003-08-08 at 22:57 BST, Christian Biere wrote:
> You better use PRId64 instead of "%lld". <sys/inttypes.h> must
> be included to make it available.
Ah yes, thanks. New patch up at the URL, with an added change
to the existing "lld" (apologies for the extra fuzz).
--
Jonathan Perkin <jonathan@perkin.org.uk>
BBC Internet Services http://www.perkin.org.uk/jonathan/
From: "Sergey Svishchev" <shattered@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/22405 CVS commit: src/usr.bin/du
Date: Sun, 11 Mar 2012 11:23:20 +0000
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.
State-Changed-From-To: open->closed
State-Changed-By: shattered@NetBSD.org
State-Changed-When: Sun, 11 Mar 2012 17:20:41 +0000
State-Changed-Why:
Patch committed, thanks!
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.