svn commit: r193629 - head/bin/df
Simon L. Nielsen
simon at FreeBSD.org
Sun Jun 7 09:06:22 UTC 2009
Author: simon
Date: Sun Jun 7 09:06:21 2009
New Revision: 193629
URL: http://svn.freebsd.org/changeset/base/193629
Log:
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.
MFC after: 3 weeks
Modified:
head/bin/df/df.1
head/bin/df/df.c
Modified: head/bin/df/df.1
==============================================================================
--- head/bin/df/df.1 Sun Jun 7 08:42:26 2009 (r193628)
+++ head/bin/df/df.1 Sun Jun 7 09:06:21 2009 (r193629)
@@ -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: head/bin/df/df.c
==============================================================================
--- head/bin/df/df.c Sun Jun 7 08:42:26 2009 (r193628)
+++ head/bin/df/df.c Sun Jun 7 09:06:21 2009 (r193629)
@@ -369,6 +369,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.
*/
@@ -413,8 +430,10 @@ prtstat(struct statfs *sfsp, struct maxw
(void)printf(" %-*s %*s %*s Capacity", 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");
}
@@ -440,8 +459,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(" ");
More information about the svn-src-all
mailing list