2

Why is there a difference in the used size between dfc and df -h?

$ df -h
Dateisystem    Größe Benutzt Verf. Verw% Eingehängt auf
/dev/sda7        64G     51G   11G   83% /
none            4,0K       0  4,0K    0% /sys/fs/cgroup
udev            3,9G    4,0K  3,9G    1% /dev
tmpfs           801M    1,5M  799M    1% /run
none            5,0M       0  5,0M    0% /run/lock
none            4,0G    148K  4,0G    1% /run/shm
...

$ dfc

FILESYSTEM  (=) USED      FREE (-) %USED AVAILABLE     TOTAL MOUNTED ON 
/dev/sda7   [=================---]   83%     10.6G     63.9G /
none        [--------------------]    0%      4.0K      4.0K /sys/fs/cgroup
udev        [=-------------------]    0%      3.9G      3.9G /dev
tmpfs       [=-------------------]    0%    798.7M    800.1M /run
none        [--------------------]    0%      5.0M      5.0M /run/lock
none        [=-------------------]    0%      3.9G      3.9G /run/shm
...

I wouldnt round 3.9 up to 4 and then display 4,0 that makes no sense to me.

1
  • What are the actual figures (df -k)? Are you sure they didn't change between your two measurements? Commented Aug 5, 2014 at 22:52

2 Answers 2

5

It is not simply "rounding". dfc (and di) print the value rounded to the nearest representation in digits, while df rounds up.

The question does not specify a version of coreutils; I'm answering based on version 8.13 (in Debian 7), though I see the same result with 8.25.

Start with the -h option in df.c:

    case 'h':
      human_output_opts = human_autoscale | human_SI | human_base_1024;
      output_block_size = 1;
      break;

There is followup code in gnulib's "human.c" (humblock), where it decides which type of rounding to use. Because the human-options are not modified, it uses the ceiling rather than floor or rounding to the nearest value. That is because a zero happens to be the enumeration value for ceiling:

  /* Unless otherwise specified these options may be ORed together.  */

  /* The following three options are mutually exclusive.  */
  /* Round to plus infinity (default).  */
  human_ceiling = 0,
  /* Round to nearest, ties to even.  */
  human_round_to_nearest = 1,
  /* Round to minus infinity.  */
  human_floor = 2,
3
  • So this is a display Bug? Due to rounding at the wrong place? Commented May 14, 2016 at 6:17
  • yes - there's a lot of configurability in human.c which is not used in df, and rounding up (for disk-freespace) is definitely wrong. Commented May 14, 2016 at 11:08
  • Can someone fix this upstream? Or create a bug report? Commented Dec 16, 2018 at 8:33
-1

I believe this is called "rounding".

1
  • I wouldnt round 3.9 up to 4 and then display 4,0 that makes no sense to me Commented Aug 5, 2014 at 20:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.