Date: Thu, 25 Jul 2002 15:35:14 +0200 (CEST) From: Klaus Weber <fbsd-bugs@unix-admin.de> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/40980: du(1)'s -h and -k options interact confusingly Message-ID: <20020725133514.A818D425C3C@kw.mega-access.com>
next in thread | raw e-mail | index | archive | help
>Number: 40980
>Category: bin
>Synopsis: du(1)'s -h and -k options interact confusingly
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Jul 25 06:40:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: fbsd-bugs@unix-admin.de (Klaus Weber)
>Release: FreeBSD 4.6-RELEASE i386
>Organization:
>Environment:
System: FreeBSD 4.6-RELEASE FreeBSD 4.6-RELEASE #0
src/usr.bin/du/du.c,v 1.17.2.3 2001/07/12 08:46:53 roam Exp
>Description:
du's -h switch (human-readable output) interacts badly with the -k switch
(1-k blocks). If both are used, du's output depends on the order in which
the switches are used (see example).
>How-To-Repeat:
~> mkdir /tmp/testdir
~> dd if=/dev/zero of=/tmp/testdir/testfile bs=1k count=100
100+0 records in
100+0 records out
102400 bytes transferred in 0.002161 secs (47384900 bytes/sec)
~> du -sh /tmp/testdir
113K /tmp/testdir
~> du -shk /tmp/testdir
56K /tmp/testdir
~> du -skh /tmp/testdir
113K /tmp/testdir
(Note that du gives different results depending on the order in which
the switches are given. The result for "-shk" is wrong.)
>Fix:
Possible patch for du follows, which adds a blocksize parameter to the
prthumanval() routine and uses it.
--- du.c.orig Thu Jul 25 14:59:25 2002
+++ du.c Thu Jul 25 15:20:12 2002
@@ -98,7 +98,7 @@
int linkchk __P((FTSENT *));
static void usage __P((void));
-void prthumanval __P((double));
+void prthumanval __P((double, long));
unit_t unit_adjust __P((double *));
void ignoreadd __P((const char *));
void ignoreclean __P((void));
@@ -251,7 +251,7 @@
if (p->fts_level <= depth) {
if (hflag) {
- (void) prthumanval(howmany(p->fts_number, blocksize));
+ (void) prthumanval(howmany(p->fts_number, blocksize), blocksize);
(void) printf("\t%s\n", p->fts_path);
} else {
(void) printf("%ld\t%s\n",
@@ -278,7 +278,7 @@
if (listall || p->fts_level == 0) {
if (hflag) {
(void) prthumanval(howmany(p->fts_statp->st_blocks,
- blocksize));
+ blocksize), blocksize);
(void) printf("\t%s\n", p->fts_path);
} else {
(void) printf("%qd\t%s\n",
@@ -297,7 +297,7 @@
if (cflag) {
if (hflag) {
- (void) prthumanval(howmany(savednumber, blocksize));
+ (void) prthumanval(howmany(savednumber, blocksize), blocksize);
(void) printf("\ttotal\n");
} else {
(void) printf("%ld\ttotal\n", howmany(savednumber, blocksize));
@@ -370,12 +370,13 @@
}
void
-prthumanval(bytes)
+prthumanval(bytes, blocksize)
double bytes;
+ long blocksize;
{
unit_t unit;
- bytes *= 512;
+ bytes *= (512*blocksize);
unit = unit_adjust(&bytes);
if (bytes == 0)
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020725133514.A818D425C3C>
