aboutsummaryrefslogtreecommitdiffstats
path: root/com32/hdt/hdt-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'com32/hdt/hdt-util.c')
-rw-r--r--com32/hdt/hdt-util.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/com32/hdt/hdt-util.c b/com32/hdt/hdt-util.c
index f96a943f..3b41a919 100644
--- a/com32/hdt/hdt-util.c
+++ b/com32/hdt/hdt-util.c
@@ -29,6 +29,10 @@
#include <stdio.h>
#include <string.h>
+/* Computing div(x,y) */
+#define sub(val) (((val%1024)*100)>>10)
+#define sub_dec(val) (((val%1000)*100)/1000)
+
void sectors_to_size(int sectors, char *buffer)
{
int b = (sectors / 2);
@@ -37,13 +41,13 @@ void sectors_to_size(int sectors, char *buffer)
int tib = gib >> 10;
if (tib > 0)
- sprintf(buffer, "%3d TiB", tib);
+ sprintf(buffer, "%3d.%02d TiB", tib,sub(gib));
else if (gib > 0)
- sprintf(buffer, "%3d GiB", gib);
+ sprintf(buffer, "%3d.%02d GiB", gib,sub(mib));
else if (mib > 0)
- sprintf(buffer, "%3d MiB", mib);
+ sprintf(buffer, "%3d.%02d MiB", mib,sub(b));
else
- sprintf(buffer, "%d b", b);
+ sprintf(buffer, "%d B", b);
}
void sectors_to_size_dec(char *previous_unit, int *previous_size, char *unit,
@@ -70,3 +74,20 @@ void sectors_to_size_dec(char *previous_unit, int *previous_size, char *unit,
}
}
}
+
+void sectors_to_size_dec2(int sectors, char *buffer)
+{
+ int b = (sectors / 2);
+ int mib = b / 1000;
+ int gib = mib / 1000;
+ int tib = gib / 1000;
+
+ if (tib > 0)
+ sprintf(buffer, "%3d.%02d TB", tib,sub_dec(gib));
+ else if (gib > 0)
+ sprintf(buffer, "%3d.%02d GB", gib,sub_dec(mib));
+ else if (mib > 0)
+ sprintf(buffer, "%3d.%02d MB", mib,sub_dec(b));
+ else
+ sprintf(buffer, "%d B", b);
+}