summaryrefslogtreecommitdiffstats
path: root/toolbox/df.c
diff options
context:
space:
mode:
authorMichal Frynas <michal.frynas@sonyericsson.com>2011-07-14 15:20:05 +0200
committerKenneth Andersson <kenneth.andersson@sonymobile.com>2012-10-02 10:39:19 +0200
commit1f90dcd0c022182220c37b300690cf73674d03b8 (patch)
tree19cee83dcd34aa80f551d29fd688f87d394195ad /toolbox/df.c
parent1c0c52503dcedff1a75775bf8bfffe7ec77b722b (diff)
downloadsystem_core-1f90dcd0c022182220c37b300690cf73674d03b8.zip
system_core-1f90dcd0c022182220c37b300690cf73674d03b8.tar.gz
system_core-1f90dcd0c022182220c37b300690cf73674d03b8.tar.bz2
Fixed improper size displaying in 'df' utility
'df' command used to display filesystem usage statistics as integer values, in most cases rounding the actual value down. Because of that 'df' tended to display faulty size values. This fix to 'df' utility calculates the fractional part of the size, then it rounds it when needed to the nearest one-digit integer value and displays after decimal dot. Change-Id: I9bc52635d45d3e55ce61b3b1c6b80d1267516e75
Diffstat (limited to 'toolbox/df.c')
-rw-r--r--toolbox/df.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/toolbox/df.c b/toolbox/df.c
index 63940a1..9cd0743 100644
--- a/toolbox/df.c
+++ b/toolbox/df.c
@@ -9,16 +9,22 @@ static int ok = EXIT_SUCCESS;
static void printsize(long long n)
{
char unit = 'K';
- n /= 1024;
- if (n > 1024) {
+ long long t;
+
+ n *= 10;
+
+ if (n > 1024*1024*10) {
n /= 1024;
unit = 'M';
}
- if (n > 1024) {
+
+ if (n > 1024*1024*10) {
n /= 1024;
unit = 'G';
}
- printf("%4lld%c", n, unit);
+
+ t = (n + 512) / 1024;
+ printf("%4lld.%1lld%c", t/10, t%10, unit);
}
static void df(char *s, int always) {
@@ -41,7 +47,7 @@ static void df(char *s, int always) {
}
int df_main(int argc, char *argv[]) {
- printf("Filesystem Size Used Free Blksize\n");
+ printf("Filesystem Size Used Free Blksize\n");
if (argc == 1) {
char s[2000];
FILE *f = fopen("/proc/mounts", "r");