From owner-svn-src-all@FreeBSD.ORG Wed Aug 19 21:33:09 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C3D7B106568E; Wed, 19 Aug 2009 21:33:09 +0000 (UTC) (envelope-from simon@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AAA848FC3F; Wed, 19 Aug 2009 21:33:09 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n7JLX90c066006; Wed, 19 Aug 2009 21:33:09 GMT (envelope-from simon@svn.freebsd.org) Received: (from simon@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n7JLX9xX066003; Wed, 19 Aug 2009 21:33:09 GMT (envelope-from simon@svn.freebsd.org) Message-Id: <200908192133.n7JLX9xX066003@svn.freebsd.org> From: "Simon L. Nielsen" Date: Wed, 19 Aug 2009 21:33:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r196394 - stable/7/bin/df X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Aug 2009 21:33:10 -0000 Author: simon Date: Wed Aug 19 21:33:09 2009 New Revision: 196394 URL: http://svn.freebsd.org/changeset/base/196394 Log: MFC r193629: Make "human-readable" (-H/-h) output also "humanize" inode counts. Base 10 is always used for the inode counts as I could not think of any reason base 2 inode counts would be useful. Minor mdoc markup fix to df(1) while here anyway. Modified: stable/7/bin/df/ (props changed) stable/7/bin/df/df.1 stable/7/bin/df/df.c Modified: stable/7/bin/df/df.1 ============================================================================== --- stable/7/bin/df/df.1 Wed Aug 19 21:01:32 2009 (r196393) +++ stable/7/bin/df/df.1 Wed Aug 19 21:33:09 2009 (r196394) @@ -78,15 +78,20 @@ this overrides the .Ev BLOCKSIZE specification from the environment. .It Fl H -"Human-readable" output. +.Dq Human-readable +output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 10 for sizes. .It Fl h -"Human-readable" output. +.Dq Human-readable +output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 2 for sizes. +Inodes statistics, if enabled with +.Fl i , +are always printed in base 10. .It Fl i Include statistics on the number of free inodes. .It Fl k Modified: stable/7/bin/df/df.c ============================================================================== --- stable/7/bin/df/df.c Wed Aug 19 21:01:32 2009 (r196393) +++ stable/7/bin/df/df.c Wed Aug 19 21:33:09 2009 (r196394) @@ -365,6 +365,23 @@ prthumanval(int64_t bytes) } /* + * Print an inode count in "human-readable" format. + */ +static void +prthumanvalinode(int64_t bytes) +{ + char buf[6]; + int flags; + + flags = HN_NOSPACE | HN_DECIMAL | HN_DIVISOR_1000; + + humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), + bytes, "", HN_AUTOSCALE, flags); + + (void)printf(" %5s", buf); +} + +/* * Convert statfs returned file system size into BLOCKSIZE units. * Attempts to avoid overflow for large file systems. */ @@ -406,8 +423,10 @@ prtstat(struct statfs *sfsp, struct maxw mwp->mntfrom, "Filesystem", mwp->total, header, mwp->used, "Used", mwp->avail, "Avail"); if (iflag) { - mwp->iused = imax(mwp->iused, (int)strlen(" iused")); - mwp->ifree = imax(mwp->ifree, (int)strlen("ifree")); + mwp->iused = imax(hflag ? 0 : mwp->iused, + (int)strlen(" iused")); + mwp->ifree = imax(hflag ? 0 : mwp->ifree, + (int)strlen("ifree")); (void)printf(" %*s %*s %%iused", mwp->iused - 2, "iused", mwp->ifree, "ifree"); } @@ -431,8 +450,15 @@ prtstat(struct statfs *sfsp, struct maxw if (iflag) { inodes = sfsp->f_files; used = inodes - sfsp->f_ffree; - (void)printf(" %*jd %*jd %4.0f%% ", mwp->iused, (intmax_t)used, - mwp->ifree, (intmax_t)sfsp->f_ffree, inodes == 0 ? 100.0 : + if (hflag) { + (void)printf(" "); + prthumanvalinode(used); + prthumanvalinode(sfsp->f_ffree); + } else { + (void)printf(" %*jd %*jd", mwp->iused, (intmax_t)used, + mwp->ifree, (intmax_t)sfsp->f_ffree); + } + (void)printf(" %4.0f%% ", inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0); } else (void)printf(" ");