From owner-freebsd-bugs@FreeBSD.ORG Tue Jun 1 19:10:33 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8DD3F16A4D0 for ; Tue, 1 Jun 2004 19:10:33 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7BBA343D39 for ; Tue, 1 Jun 2004 19:10:33 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i522AJ1R034651 for ; Tue, 1 Jun 2004 19:10:19 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i522AJVY034650; Tue, 1 Jun 2004 19:10:19 -0700 (PDT) (envelope-from gnats) Date: Tue, 1 Jun 2004 19:10:19 -0700 (PDT) Message-Id: <200406020210.i522AJVY034650@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: "David G. Andersen" Subject: Re: bin/67467: df -m and -g incorrect with negative avail X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: "David G. Andersen" List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2004 02:10:33 -0000 The following reply was made to PR bin/67467; it has been noted by GNATS. From: "David G. Andersen" To: freebsd-gnats-submit@FreeBSD.org, dga@lcs.mit.edu Cc: Subject: Re: bin/67467: df -m and -g incorrect with negative avail Date: Tue, 1 Jun 2004 22:08:14 -0400 The problem is with the fsbtoblk macro on line 401 of /usr/src/bin/df.c #define fsbtoblk(num, fsbs, bs) \ (((fsbs) != 0 && (fsbs) < (bs)) ? \ (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs))) The problem only occurs when the user specifies a blocksize larger than the filesystem blocksize (probably 4k), invoking this part of the code: (num) / ((bs) / (fsbs)) Unfortunately, the result of this is of the type of fsbs (which is a u_int64_t), instead of being of the type of num (int64_t). The easiest solution is an explicit cast in the macro: (num) / (intmax_t)((bs) / (fsbs)) : (num) * ((fsbs) / (bs))) This could result in a premature cast out of unsignedness iff fsbs = 1 and bs > 2^63 and num is an unsigned quantity, but it's safe in other situations. If gcc extensions are kosher, then it would better be written as: (num) / (typeof(num))((bs) / (fsbs)) : (num) * ((fsbs) / (bs))) since typeof seems to be used elsewhere in the kernel, I assume this is acceptable.