Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Jun 2004 19:10:19 -0700 (PDT)
From:      "David G. Andersen" <dga@lcs.mit.edu>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/67467: df -m and -g incorrect with negative avail
Message-ID:  <200406020210.i522AJVY034650@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/67467; it has been noted by GNATS.

From: "David G. Andersen" <dga@lcs.mit.edu>
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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406020210.i522AJVY034650>