summaryrefslogtreecommitdiffstats
path: root/bin/df
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1996-01-14 18:55:09 +0000
committerbde <bde@FreeBSD.org>1996-01-14 18:55:09 +0000
commitd1eb245b0ad962a7359d05c2bae5afe05ec72e85 (patch)
treef11ca3d29cbe8bf42a1caf7f3972f80fb2adbe64 /bin/df
parent167b5f5854e2142bcbd74d1a418f45a8907b6fcd (diff)
downloadFreeBSD-src-d1eb245b0ad962a7359d05c2bae5afe05ec72e85.zip
FreeBSD-src-d1eb245b0ad962a7359d05c2bae5afe05ec72e85.tar.gz
Partially fixed negative and truncated "Avail" counts in df output.
This fixes PR943. ffs/ffs_vfsops.c: ffs_statfs() multiplied by (100 - minfree) as part of calculating the minfree percentage (complemented in 100%), so with the standard minfree of 8, it was broken for file systems of size >= 1TB/92 = 11GB. Use the standard freespace() macro instead. This also fixes a rounding bug (the "Avail" count was sometimes 1 too small). ffs/* (not fixed): The freespace() macro multiplies by minfree, so with the standard minfree of 8, it is broken for file systems of size >= 1TB/8 = 128GB. This bug is more serious since it affects block allocation. ffs/ffs_alloc.c (not fixed): Ordinary users are sometimes allowed to allocate 1 (partial) block too many so that the "Avail" count goes negative. E.g., if there is 1 fragment available and the file is fairly large, one more full block is allocated. df/df.c: ufs_df() used/uses essentially the same code as ffs_statfs(), so it had/has the same bugs. ufs_df() gratuitously replaced "Avail" counts of < 0 by 0, so it gave different results for non-mounted file systems in this case.
Diffstat (limited to 'bin/df')
-rw-r--r--bin/df/df.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/bin/df/df.c b/bin/df/df.c
index 80cbba4..701a9ad 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -35,7 +35,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: df.c,v 1.6 1995/03/19 13:28:15 joerg Exp $
+ * $Id: df.c,v 1.7 1995/05/30 00:06:42 rgrimes Exp $
*/
#ifndef lint
@@ -386,10 +386,7 @@ ufs_df(file, maxwidth)
sfsp->f_blocks = sblock.fs_dsize;
sfsp->f_bfree = sblock.fs_cstotal.cs_nbfree * sblock.fs_frag +
sblock.fs_cstotal.cs_nffree;
- sfsp->f_bavail = (sblock.fs_dsize * (100 - sblock.fs_minfree) / 100) -
- (sblock.fs_dsize - sfsp->f_bfree);
- if (sfsp->f_bavail < 0)
- sfsp->f_bavail = 0;
+ sfsp->f_bavail = freespace(&sblock, sblock.fs_minfree);
sfsp->f_files = sblock.fs_ncg * sblock.fs_ipg;
sfsp->f_ffree = sblock.fs_cstotal.cs_nifree;
sfsp->f_fsid.val[0] = 0;
OpenPOWER on IntegriCloud