On 10/28/2012 10:50:50 PM, Roy Tam wrote:
Hello,

I noticed that toybox df shows different percentage from GNU df.
GNU df calculates percentage by used/(used+free) while toybox use
(blocks-free)/blocks.
(which one is better by the way?)

According to posix-2008:

<percentage used>

The percentage of the normally available space that is currently allocated to all
files on the file system. This shall be calculated using the fraction:
  <space used>/( <space used>+ <space free>)
expressed as a percentage. This percentage may be greater than 100 if <space free> is less than zero. The percentage value shall be expressed as a positive integer, with any fractional result causing it to be rounded to the next highest integer.

The "space used" and "space free" entries are the used/available displayed in columns 3 and 4. The "any fractional result" implies that you do something like:

  pct=(used*100)/(used+free)
  if (pct*(used+free) != (used*100)) pct++;

(Except all with 64 bit math so overflow sucks less.)

toybox$ ../busybox/busybox df
Filesystem           1K-blocks      Used Available Use% Mounted on
udev                     10240         0     10240   0% /dev
tmpfs                    12456       160     12296   1% /run
/dev/disk/by-uuid/4277274d-e9a1-42ff-a247-b75bde522deb
                       1913244   1151656    664400  63% /
tmpfs                    24912         0     24912   0% /run/shm

160/(160+12296.0)
0.012845215157353885

Not doing the pedantic rounding up.

toybox$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
rootfs                 1913244   1151656    664400  64% /
udev                     10240         0     10240   0% /dev
tmpfs                    12456       160     12296   2% /run
/dev/disk/by-uuid/4277274d-e9a1-42ff-a247-b75bde522deb
                       1913244   1151656    664400  64% /
tmpfs                    24912         0     24912   0% /run/shm

Doing the pedantic rounding up.

toybox$ ./toybox df
Filesystem      1K-blocks       Used Available Use% Mounted on
tmpfs               24912          0     24912   0% /run/shm
/dev/sda1         1913244    1151656    664400  66% /
tmpfs               12456        160     12296   2% /run
udev                10240          0     10240   0% /dev

Showing used as a percentage of 1K-blocks, ignoring "available" altogether.

Right, I fixed it to match what the standard requires, which seems to be what upstream is doing.

Thanks for the heads up,

Rob
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to