Index: du/du.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/du/du.1,v retrieving revision 1.33 diff -u -r1.33 du.1 --- du/du.1 25 Feb 2008 19:06:43 -0000 1.33 +++ du/du.1 11 Apr 2008 06:56:02 -0000 @@ -44,7 +44,7 @@ .Op Fl a | s | d Ar depth .Op Fl c .Op Fl l -.Op Fl h | k | m +.Op Fl h | k | m | i .Op Fl n .Op Fl x .Op Fl I Ar mask @@ -52,10 +52,10 @@ .Sh DESCRIPTION The .Nm -utility displays the file system block usage for each file argument +utility displays the file system block or inode 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 +If no file is specified, the block or inode usage of the hierarchy rooted in the current directory is displayed. .Pp The options are as follows: @@ -77,6 +77,8 @@ "Human-readable" output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte. +.It Fl i +Display inode usage instead of block usage. .It Fl r Generate messages about directories that cannot be read, files that cannot be opened, and so on. Index: du/du.c =================================================================== RCS file: /home/ncvs/src/usr.bin/du/du.c,v retrieving revision 1.45 diff -u -r1.45 du.c --- du/du.c 25 Feb 2008 19:06:43 -0000 1.45 +++ du/du.c 11 Apr 2008 06:56:02 -0000 @@ -65,6 +65,9 @@ #include #include +/* Count inodes or file size */ +#define COUNT (iflag ? 1 : p->fts_statp->st_blocks) + SLIST_HEAD(ignhead, ignentry) ignores; struct ignentry { char *mask; @@ -91,21 +94,21 @@ int listall; int depth; int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag; - int hflag, lflag, ch, notused, rval; + int hflag, iflag, lflag, ch, notused, rval; char **save; static char dot[] = "."; setlocale(LC_ALL, ""); Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = - lflag = 0; + iflag = lflag = 0; save = argv; ftsoptions = 0; depth = INT_MAX; SLIST_INIT(&ignores); - while ((ch = getopt(argc, argv, "HI:LPasd:chklmnrx")) != -1) + while ((ch = getopt(argc, argv, "HI:LPasd:chiklmnrx")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -147,6 +150,9 @@ "setenv: cannot set BLOCKSIZE=512"); hflag = 1; break; + case 'i': + iflag = 1; + break; case 'k': hflag = 0; if (setenv("BLOCKSIZE", "1024", 1) == -1) @@ -241,10 +247,14 @@ break; p->fts_parent->fts_bignum += - p->fts_bignum += p->fts_statp->st_blocks; + p->fts_bignum += COUNT; if (p->fts_level <= depth) { - if (hflag) { + if (iflag) { + (void) printf("%jd\t%s\n", + (intmax_t)p->fts_bignum, + p->fts_path); + } else if (hflag) { (void) prthumanval(howmany(p->fts_bignum, blocksize)); (void) printf("\t%s\n", p->fts_path); } else { @@ -271,18 +281,22 @@ break; if (listall || p->fts_level == 0) { - if (hflag) { - (void) prthumanval(howmany(p->fts_statp->st_blocks, + if (iflag) { + (void) printf("%jd\t%s\n", + (intmax_t)COUNT, + p->fts_path); + } else if (hflag) { + (void) prthumanval(howmany(COUNT, blocksize)); (void) printf("\t%s\n", p->fts_path); } else { (void) printf("%jd\t%s\n", - (intmax_t)howmany(p->fts_statp->st_blocks, blocksize), + (intmax_t)howmany(COUNT, blocksize), p->fts_path); } } - p->fts_parent->fts_bignum += p->fts_statp->st_blocks; + p->fts_parent->fts_bignum += COUNT; } savednumber = p->fts_parent->fts_bignum; } @@ -291,7 +305,9 @@ err(1, "fts_read"); if (cflag) { - if (hflag) { + if (iflag) { + (void) printf("%jd\ttotal\n", (intmax_t)savednumber); + } else if (hflag) { (void) prthumanval(howmany(savednumber, blocksize)); (void) printf("\ttotal\n"); } else { @@ -454,7 +470,7 @@ { (void)fprintf(stderr, "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] " - "[-l] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n"); + "[-l] [-h | -k | -m | -i] [-n] [-x] [-I mask] [file ...]\n"); exit(EX_USAGE); }