From 009e9a29f4fe6b08fb88e7e4aac291be55d58540 Mon Sep 17 00:00:00 2001 From: Robin Hahling Date: Fri, 25 Oct 2013 08:54:23 +0200 Subject: [PATCH] df -hi prints inodes count "human-readable" Enable "human-readable" printing of inodes count when df(1) is called with both -h and -i flags. This is similar to what can be found on FreeBSD df(1) or GNU df(1). The code has been adapted from FreeBSD's df(1) and the manpage updated accordingly. Example output: Now: % df -hi Filesystem Size Used Avail Capacity iused ifree %iused Mounted on [...] /dev/serno/VB6cbedbd6-0a1f16ee.s1a 756M 302M 393M 43% 949 96k 1% /boot [...] Before: % df -hi Filesystem Size Used Avail Capacity iused ifree %iused Mounted on [...] /dev/serno/VB6cbedbd6-0a1f16ee.s1a 756M 302M 393M 43% 949 96329 1% /boot [...] --- bin/df/df.1 | 9 +++++++-- bin/df/df.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bin/df/df.1 b/bin/df/df.1 index 2459eef7af..dae840d872 100644 --- a/bin/df/df.1 +++ b/bin/df/df.1 @@ -29,7 +29,7 @@ .\" $FreeBSD: src/bin/df/df.1,v 1.18.2.9 2003/05/07 23:56:14 trhodes Exp $ .\" $DragonFly: src/bin/df/df.1,v 1.3 2006/02/17 19:33:30 swildner Exp $ .\" -.Dd June 10, 2009 +.Dd October 25, 2013 .Dt DF 1 .Os .Sh NAME @@ -85,7 +85,12 @@ digits to four or fewer using base 10 for sizes. Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to four or fewer using base 2 for sizes. .It Fl i -Include statistics on the number of free inodes. +Include statistics on the number of free and used inodes. +In conjunction with the +.Fl h +or +.Fl H +options, the number of inodes is scaled by powers of 1000. .It Fl k Use 1024-byte (1-Kbyte) blocks rather than the default. Note that this overrides the diff --git a/bin/df/df.c b/bin/df/df.c index 18ec6a7700..c4b6899094 100644 --- a/bin/df/df.c +++ b/bin/df/df.c @@ -340,6 +340,23 @@ prthumanval(int64_t bytes) printf(" %6s", buf); } +/* + * 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); + + printf(" %5s", buf); +} + /* * Convert statfs returned filesystem size into BLOCKSIZE units. * Attempts to avoid overflow for large filesystems. @@ -404,8 +421,15 @@ prtstat(struct statfs *sfsp, struct statvfs *vsfsp, struct maxwidths *mwp) if (iflag) { inodes = vsfsp->f_files; used = inodes - vsfsp->f_ffree; - printf(" %*jd %*jd %4.0f%% ", mwp->iused, (intmax_t)used, - mwp->ifree, (intmax_t)vsfsp->f_ffree, inodes == 0 ? 100.0 : + if (hflag) { + printf(" "); + prthumanvalinode(used); + prthumanvalinode(vsfsp->f_ffree); + } else { + printf(" %*jd %*jd", mwp->iused, (intmax_t)used, + mwp->ifree, (intmax_t)vsfsp->f_ffree); + } + printf(" %4.0f%% ", inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0); } else printf(" "); -- 2.41.0