From owner-freebsd-current@FreeBSD.ORG Tue Dec 9 21:35:39 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D4EB316A4CE; Tue, 9 Dec 2003 21:35:39 -0800 (PST) Received: from locore.org (ns01.locore.org [218.45.21.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5FD1E43D2F; Tue, 9 Dec 2003 21:35:38 -0800 (PST) (envelope-from iwasaki@jp.FreeBSD.org) Received: from localhost (ns01.locore.org [218.45.21.227]) hBA5ZZau006038; Wed, 10 Dec 2003 14:35:35 +0900 (JST) (envelope-from iwasaki@jp.FreeBSD.org) Date: Wed, 10 Dec 2003 14:35:33 +0900 (JST) Message-Id: <20031210.143533.108775228.iwasaki@jp.FreeBSD.org> To: current@freebsd.org From: Mitsuru IWASAKI X-Mailer: Mew version 2.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: re@freebsd.org Subject: 5.2-RC: odd df(1) output X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Dec 2003 05:35:40 -0000 Hi, I've found a odd df(1) output when filesystem available space is negative value. % df -k /usr Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/ad0s1g 18084782 16722518 -84518 101% /usr % df -m /usr Filesystem 1M-blocks Used Avail Capacity Mounted on /dev/ad0s1g 17660 16329 36028797018963886 101% /usr It seems that this happen in case df block size is bigger than fs block size(eg. df -m on 2048-byte block filesystem). And we can reproduce the problem with simple program, such as: ---- #include #include int main() { int64_t num = -58420; uint64_t fsbs = 2048; u_long bs = 1048576; printf("%jd\n", (intmax_t)(num) / ((bs) / (fsbs))); printf("%jd\n", (intmax_t)(num) / (intmax_t)((bs) / (fsbs))); return 0; } ---- Quick fix is attached below. Thanks Index: df.c =================================================================== RCS file: /home/ncvs/src/bin/df/df.c,v retrieving revision 1.53 diff -u -r1.53 df.c --- df.c 12 Nov 2003 21:47:42 -0000 1.53 +++ df.c 10 Dec 2003 05:26:48 -0000 @@ -398,9 +398,15 @@ * Convert statfs returned file system size into BLOCKSIZE units. * Attempts to avoid overflow for large file systems. */ -#define fsbtoblk(num, fsbs, bs) \ - (((fsbs) != 0 && (fsbs) < (bs)) ? \ - (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs))) +static intmax_t +fsbtoblk(int64_t num, uint64_t fsbs, u_long bs) +{ + if (fsbs != 0 && fsbs < bs) { + return (intmax_t)(num / (intmax_t)(bs / fsbs)); + } else { + return (intmax_t)(num * (fsbs / bs)); + } +} /* * Print out status about a file system.