Subject: bin/23688: Incorrect header with df -h -k
To: None <gnats-bugs@gnats.NetBSD.org>
From: Gary Duzan <gary@duzan.org>
List: netbsd-bugs
Date: 12/07/2003 13:02:32
>Number: 23688
>Category: bin
>Synopsis: Incorrect header with df -h -k
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Dec 07 18:03:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Gary Duzan
>Release: NetBSD 1.6ZG, 2003-12-06
>Organization:
N/A
>Environment:
System: NetBSD capo 1.6ZG NetBSD 1.6ZG (XCAPO) #2: Sat Dec 6 13:38:17 EST 2003 gary@capo:/usr2/src/sys/arch/i386/compile/obj/XCAPO i386
Architecture: i386
Machine: i386
>Description:
"df -h -k" reports "1K-blocks" in the header, but size for the
column values.
>How-To-Repeat:
capo { ~ } % /bin/df
Filesystem 512-blocks Used Avail Capacity Mounted on
/dev/wd0a 1056164 181420 821934 18% /
/dev/wd0e 13150740 4891786 7601416 39% /usr
/dev/wd1a 151582250 7233570 136769566 5% /usr2
kernfs 2 2 0 100% /kern
capo { ~ } % /bin/df -k
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/wd0a 528082 90710 410967 18% /
/dev/wd0e 6575370 2445893 3800708 39% /usr
/dev/wd1a 75791125 3616785 68384783 5% /usr2
kernfs 1 1 0 100% /kern
capo { ~ } % /bin/df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/wd0a 516M 89M 401M 18% /
/dev/wd0e 6.3G 2.3G 3.6G 39% /usr
/dev/wd1a 72G 3.4G 65G 5% /usr2
kernfs 1.0K 1.0K 0.0B 100% /kern
capo { ~ } % /bin/df -h -k
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/wd0a 516M 89M 401M 18% /
/dev/wd0e 6.3G 2.3G 3.6G 39% /usr
/dev/wd1a 72G 3.4G 65G 5% /usr2
kernfs 1.0K 1.0K 0.0B 100% /kern
capo { ~ } %
>Fix:
Probably the simplest option is to check -h first, as in
the following patch:
Index: bin/df/df.c
===================================================================
RCS file: /cvsroot/src/bin/df/df.c,v
retrieving revision 1.49
diff -u -r1.49 df.c
--- bin/df/df.c 2003/08/07 09:05:11 1.49
+++ bin/df/df.c 2003/12/07 17:58:43
@@ -334,7 +334,10 @@
if (maxwidth < 11)
maxwidth = 11;
if (++timesthrough == 1) {
- if (kflag) {
+ if (hflag) {
+ header = " Size";
+ headerlen = strlen(header);
+ } else if (kflag) {
blocksize = 1024;
header = Pflag ? "1024-blocks" : "1K-blocks";
headerlen = strlen(header);
@@ -345,9 +348,6 @@
} else if (gflag) {
blocksize = 1024 * 1024 * 1024;
header = Pflag ? "1073741824-blocks" : "1G-blocks";
- headerlen = strlen(header);
- } else if (hflag) {
- header = " Size";
headerlen = strlen(header);
} else
header = getbsize(&headerlen, &blocksize);
The result is more what is expected:
capo { ~ } % /usr/src/bin/df/obj/df -h -k
Filesystem Size Used Avail Capacity Mounted on
/dev/wd0a 516M 89M 401M 18% /
/dev/wd0e 6.3G 2.3G 3.6G 39% /usr
/dev/wd1a 72G 3.4G 65G 5% /usr2
kernfs 1.0K 1.0K 0.0B 100% /kern
wheel:/usr/home 3.9G 1.7G 2.0G 44% /usr/home
wheel:/usr2/export/roadtrip 2.9G 1.3G 1.4G 48% /roadtrip
capo { ~ } %
>Release-Note:
>Audit-Trail:
>Unformatted: