From owner-freebsd-bugs Thu Jul 25 6:40:18 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E4C6437B400 for ; Thu, 25 Jul 2002 06:40:03 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 87DDF43E72 for ; Thu, 25 Jul 2002 06:40:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g6PDe2JU061549 for ; Thu, 25 Jul 2002 06:40:02 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g6PDe2LH061548; Thu, 25 Jul 2002 06:40:02 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 044CB37B400 for ; Thu, 25 Jul 2002 06:35:24 -0700 (PDT) Received: from officemail.bgsk.de (officemail.bgsk.de [80.76.225.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4E9BA43E6E for ; Thu, 25 Jul 2002 06:35:23 -0700 (PDT) (envelope-from weber@eozaen.net) Received: from kw.mega-access.com (kw.mega-access.com [80.76.225.131]) by officemail.bgsk.de (Postfix) with ESMTP id E71FBAAA6 for ; Thu, 25 Jul 2002 15:35:15 +0200 (CEST) Received: by kw.mega-access.com (Postfix, from userid 666) id A818D425C3C; Thu, 25 Jul 2002 15:35:14 +0200 (CEST) Message-Id: <20020725133514.A818D425C3C@kw.mega-access.com> Date: Thu, 25 Jul 2002 15:35:14 +0200 (CEST) From: Klaus Weber To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/40980: du(1)'s -h and -k options interact confusingly Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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