bin/67467: df -m and -g incorrect with negative avail
David G. Andersen
dga at lcs.mit.edu
Tue Jun 1 19:10:33 PDT 2004
The following reply was made to PR bin/67467; it has been noted by GNATS.
From: "David G. Andersen" <dga at lcs.mit.edu>
To: freebsd-gnats-submit at FreeBSD.org, dga at 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.
More information about the freebsd-bugs
mailing list