aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErwan Velu <erwan.velu@free.fr>2009-11-29 14:07:52 +0100
committerErwan Velu <erwan.velu@free.fr>2009-12-04 10:11:15 +0100
commit16e3c1c438479d89ab270fd8ea672d5680e7ee52 (patch)
tree464929b20d190a8f69d7574ec67596433d7ca88d
parente8abe5be27038b92d8c40c1762a905249f1f9268 (diff)
downloadsyslinux.git-16e3c1c438479d89ab270fd8ea672d5680e7ee52.tar.gz
syslinux.git-16e3c1c438479d89ab270fd8ea672d5680e7ee52.tar.xz
syslinux.git-16e3c1c438479d89ab270fd8ea672d5680e7ee52.zip
hdt: Preventing agressive disk's size rounding
Impact: Visual Prevent reported case where 1997MB could be displayed as 1GB.
-rw-r--r--com32/hdt/hdt-cli-disk.c6
-rw-r--r--com32/hdt/hdt-menu-disk.c22
-rw-r--r--com32/hdt/hdt-util.c29
-rw-r--r--com32/hdt/hdt-util.h1
4 files changed, 41 insertions, 17 deletions
diff --git a/com32/hdt/hdt-cli-disk.c b/com32/hdt/hdt-cli-disk.c
index 290940c1..cabee9de 100644
--- a/com32/hdt/hdt-cli-disk.c
+++ b/com32/hdt/hdt-cli-disk.c
@@ -55,7 +55,7 @@ static void show_partition_information(struct driveinfo *drive_info,
int partition_offset,
int nb_partitions_seen)
{
- char size[9];
+ char size[11];
char bootloader_name[9];
char *parttype;
unsigned int start, end;
@@ -108,7 +108,7 @@ void main_show_disk(int argc, char **argv, struct s_hardware *hardware)
int i = drive - 0x80;
struct driveinfo *d = &hardware->disk_info[i];
- char disk_size[9];
+ char disk_size[11];
char mbr_name[50];
detect_disks(hardware);
@@ -199,7 +199,7 @@ void disks_summary(int argc __unused, char **argv __unused,
found = true;
struct driveinfo *d = &hardware->disk_info[i];
- char disk_size[9];
+ char disk_size[11];
if ((int)d->edd_params.sectors > 0)
sectors_to_size((int)d->edd_params.sectors, disk_size);
diff --git a/com32/hdt/hdt-menu-disk.c b/com32/hdt/hdt-menu-disk.c
index 17be236a..f0455004 100644
--- a/com32/hdt/hdt-menu-disk.c
+++ b/com32/hdt/hdt-menu-disk.c
@@ -75,7 +75,7 @@ static void compute_partition_information(struct driveinfo *drive_info,
int partition_offset,
int nb_partitions_seen)
{
- char size[9];
+ char size[11];
char bootloader_name[9];
char *parttype;
unsigned int start, end;
@@ -165,19 +165,21 @@ static int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu,
int previous_size, size;
char previous_unit[3], unit[3]; // GB
- char size_iec[9]; // GiB
+ char size_iec[11]; // GiB
+ char size_dec[11]; // GB
sectors_to_size_dec(previous_unit, &previous_size, unit, &size,
d[disk_number].edd_params.sectors);
sectors_to_size(d[disk_number].edd_params.sectors, size_iec);
+ sectors_to_size_dec2(d[disk_number].edd_params.sectors, size_dec);
- snprintf(buffer, sizeof buffer, "Size : %s/%d %s (%d %s)",
- remove_spaces(size_iec), size, unit, previous_size, previous_unit);
- snprintf(statbuffer, sizeof statbuffer, "Size: %s/%d %s (%d %s)",
- remove_spaces(size_iec), size, unit, previous_size, previous_unit);
+ snprintf(buffer, sizeof buffer, "Size : %s/%s (%d %s)",
+ remove_spaces(size_iec), remove_spaces(size_dec), previous_size, previous_unit);
+ snprintf(statbuffer, sizeof statbuffer, "Size: %s/%s (%d %s)",
+ remove_spaces(size_iec), remove_spaces(size_dec), previous_size, previous_unit);
add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
menu[nb_sub_disk_menu].items_count++;
- snprintf(buffer, sizeof buffer, "Host Bus / Interface : %s / %s",
+ snprintf(buffer, sizeof buffer, "Host Bus/Interface: %s / %s",
remove_spaces((char *)d[disk_number].edd_params.host_bus_type),
d[disk_number].edd_params.interface_type);
snprintf(statbuffer, sizeof statbuffer, "Host Bus / Interface: %s / %s",
@@ -186,7 +188,7 @@ static int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu,
add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
menu[nb_sub_disk_menu].items_count++;
- snprintf(buffer, sizeof buffer, "C / H / S : %d / %d / %d",
+ snprintf(buffer, sizeof buffer, "C / H / S : %d / %d / %d",
d[disk_number].legacy_max_cylinder + 1,
d[disk_number].legacy_max_head + 1,
(int)d[disk_number].edd_params.sectors);
@@ -198,7 +200,7 @@ static int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu,
add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
menu[nb_sub_disk_menu].items_count++;
- snprintf(buffer, sizeof buffer, "Sectors/Track : %d",
+ snprintf(buffer, sizeof buffer, "Sectors/Track : %d",
d[disk_number].legacy_sectors_per_track);
snprintf(statbuffer, sizeof statbuffer, "Sectors per Track: %d",
d[disk_number].legacy_sectors_per_track);
@@ -207,7 +209,7 @@ static int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu,
get_mbr_string(hardware->mbr_ids[disk_number], &mbr_name, 50);
- snprintf(buffer, sizeof buffer, "MBR : %s (0x%X)",
+ snprintf(buffer, sizeof buffer, "MBR : %s (0x%X)",
remove_spaces(mbr_name), hardware->mbr_ids[disk_number]);
snprintf(statbuffer, sizeof statbuffer, "MBR: %s (id 0x%X)",
remove_spaces(mbr_name), hardware->mbr_ids[disk_number]);
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);
+}
diff --git a/com32/hdt/hdt-util.h b/com32/hdt/hdt-util.h
index 8c1d6de5..9e3769e8 100644
--- a/com32/hdt/hdt-util.h
+++ b/com32/hdt/hdt-util.h
@@ -30,4 +30,5 @@
#define DEFINE_HDT_UTIL_H
void sectors_to_size(int, char *);
void sectors_to_size_dec(char *, int *, char *, int *, int);
+void sectors_to_size_dec2(int sectors, char *buffer);
#endif