If it is completely disk full, it will be a later festival, so I recognize that it is displayed with a little buffer, but how is it actually? When I calculate it, it doesn't fit.
$ df /
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 30909700 14577164 16332536 48% /
The display of df is 48%, but (use * 100) / (Used + Available)
This calculation gives 47%.
echo "(14577164 * 100) / (14577164 + 16332536)" | bc
47
Let's try core-utils.
df.c
case PCENT_FIELD:
case IPCENT_FIELD:
{
double pct = -1;
if (! known_value (v->used) || ! known_value (v->available))
;
else if (!v->negate_used
&& v->used <= TYPE_MAXIMUM (uintmax_t) / 100
&& v->used + v->available != 0
&& (v->used + v->available < v->used)
== v->negate_available)
{
uintmax_t u100 = v->used * 100;
uintmax_t nonroot_total = v->used + v->available;
pct = u100 / nonroot_total + (u100 % nonroot_total != 0);
}
Is it a feeling that it is generally +1?
In the first place, this (u100% nonroot_total! = 0)
returns 0 or 1.
$ cat x.c
#include <stdio.h>
int main(void)
{
printf("%d\n", (0 != 0));
printf("%d\n", (1 != 0));
}
$ gcc x.c
$ ./a.out
0
1
Recommended Posts