From owner-freebsd-bugs@FreeBSD.ORG Mon Mar 24 09:10:02 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D0F341065672 for ; Mon, 24 Mar 2008 09:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BC8FB8FC1D for ; Mon, 24 Mar 2008 09:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m2O9A2B0077014 for ; Mon, 24 Mar 2008 09:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m2O9A2Ul077013; Mon, 24 Mar 2008 09:10:02 GMT (envelope-from gnats) Resent-Date: Mon, 24 Mar 2008 09:10:02 GMT Resent-Message-Id: <200803240910.m2O9A2Ul077013@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Drkshadow Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 591EF106566C for ; Mon, 24 Mar 2008 09:03:18 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 569958FC26 for ; Mon, 24 Mar 2008 09:03:18 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m2O938v5091161 for ; Mon, 24 Mar 2008 09:03:08 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m2O938Oi091160; Mon, 24 Mar 2008 09:03:08 GMT (envelope-from nobody) Message-Id: <200803240903.m2O938Oi091160@www.freebsd.org> Date: Mon, 24 Mar 2008 09:03:08 GMT From: Drkshadow To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/122043: du does not support byte-count-based reporting (-b argument) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Mar 2008 09:10:02 -0000 >Number: 122043 >Category: bin >Synopsis: du does not support byte-count-based reporting (-b argument) >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: Mon Mar 24 09:10:02 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Drkshadow >Release: FreeBSD 6.2-RELEASE-p10 >Organization: >Environment: FreeBSD DrkShadow.com 6.2-RELEASE-p10 FreeBSD 6.2-RELEASE-p10 #1: Mon Jan 28 06:51:11 MST 2008 root@DrkShadow.com:/usr/obj/usr/src/sys/via-c7 i386 >Description: du(1) that comes with FreeBSD does not understand the -b argument, and these is no way to achieve such functionality using the BLOCKSIZE environment variable. As far as I know, this option is not required by POSIX, but it's trivially implemented using a different member of the stat(2) structure and an if to separate block counts from byte counts. The only issue that I can see is for filesystems containing files that sum up to more than 8 exabytes in size -- in this case, the 64-bit integer used to store the byte count will overflow. Multiply this by 512 for the maximum size for block-based counting. If it becomes an issue, a check can be put in to compare the addition and, if the result is less than the additive value, throw an error. >How-To-Repeat: >Fix: Patch attached with submission follows: Only in a/usr.bin/du: Makefile diff -u -r a/usr.bin/du/du.1 b/usr.bin/du/du.1 --- a/usr.bin/du/du.1 Mon Mar 24 02:56:25 2008 +++ b/usr.bin/du/du.1 Mon Mar 24 02:59:40 2008 @@ -43,7 +43,7 @@ .Op Fl H | L | P .Op Fl a | s | d Ar depth .Op Fl c -.Op Fl h | k | m +.Op Fl h | b | k | m .Op Fl n .Op Fl x .Op Fl I Ar mask @@ -92,6 +92,8 @@ directories deep. .It Fl c Display a grand total. +.It Fl b +Display block counts in bytes. .It Fl k Display block counts in 1024-byte (1-Kbyte) blocks. .It Fl m diff -u -r a/usr.bin/du/du.c b/usr.bin/du/du.c --- a/usr.bin/du/du.c Mon Mar 24 02:56:25 2008 +++ b/usr.bin/du/du.c Mon Mar 24 03:05:13 2008 @@ -90,20 +90,20 @@ int ftsoptions; int listall; int depth; - int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval; + int Hflag, Lflag, Pflag, aflag, bflag, sflag, dflag, cflag, hflag, ch, notused, rval; char **save; static char dot[] = "."; setlocale(LC_ALL, ""); - Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0; + Hflag = Lflag = Pflag = aflag = bflag = sflag = dflag = cflag = hflag = 0; save = argv; ftsoptions = 0; depth = INT_MAX; SLIST_INIT(&ignores); - while ((ch = getopt(argc, argv, "HI:LPasd:chkmnrx")) != -1) + while ((ch = getopt(argc, argv, "HI:LPabsd:chkmnrx")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -143,11 +143,17 @@ putenv("BLOCKSIZE=512"); hflag = 1; break; + case 'b': + putenv("BLOCKSIZE=512"); + bflag = 1; + break; case 'k': + bflag = 0; hflag = 0; putenv("BLOCKSIZE=1024"); break; case 'm': + bflag = 0; hflag = 0; putenv("BLOCKSIZE=1048576"); break; @@ -213,8 +219,12 @@ argv[1] = NULL; } - (void) getbsize(¬used, &blocksize); - blocksize /= 512; + if (!bflag) { + (void) getbsize(¬used, &blocksize); + blocksize /= 512; + } else { + blocksize=1; + } rval = 0; @@ -231,8 +241,13 @@ if (ignorep(p)) break; - p->fts_parent->fts_bignum += - p->fts_bignum += p->fts_statp->st_blocks; + if (!bflag) { + p->fts_parent->fts_bignum += + p->fts_bignum += p->fts_statp->st_blocks; + } else { + p->fts_parent->fts_bignum += + p->fts_bignum += p->fts_statp->st_size; + } if (p->fts_level <= depth) { if (hflag) { @@ -261,18 +276,34 @@ break; if (listall || p->fts_level == 0) { - if (hflag) { - (void) prthumanval(howmany(p->fts_statp->st_blocks, - blocksize)); - (void) printf("\t%s\n", p->fts_path); + if (!bflag) { + if (hflag) { + (void) prthumanval(howmany(p->fts_statp->st_blocks, + 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), + p->fts_path); + } } else { - (void) printf("%jd\t%s\n", - (intmax_t)howmany(p->fts_statp->st_blocks, blocksize), - p->fts_path); + if (hflag) { + (void) prthumanval(howmany(p->fts_statp->st_size, + blocksize)); + (void) printf("\t%s\n", p->fts_path); + } else { + (void) printf("%jd\t%s\n", + (intmax_t)howmany(p->fts_statp->st_size, blocksize), + p->fts_path); + } } } - p->fts_parent->fts_bignum += p->fts_statp->st_blocks; + if (!bflag) { + p->fts_parent->fts_bignum += p->fts_statp->st_blocks; + } else { + p->fts_parent->fts_bignum += p->fts_statp->st_size; + } } savednumber = p->fts_parent->fts_bignum; } @@ -443,7 +474,7 @@ usage(void) { (void)fprintf(stderr, - "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n"); + "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -b | -m] [-n] [-x] [-I mask] [file ...]\n"); exit(EX_USAGE); } >Release-Note: >Audit-Trail: >Unformatted: