summaryrefslogtreecommitdiff
path: root/sbin/pdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2016-01-31 22:52:58 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2016-01-31 22:52:58 +0000
commit59951a45e8aa5cf7b3af4fc7621604654e6ea66b (patch)
tree7d7567a318028904655d1aafe0fcc92d516d873a /sbin/pdisk
parent422e2e4a6457cc777b90a1fbd24fa64b8ae946de (diff)
Nuke djust_value_and_compute_prefix() and use fmt_scaled() to display
human readable sizes.
Diffstat (limited to 'sbin/pdisk')
-rw-r--r--sbin/pdisk/dump.c69
1 files changed, 19 insertions, 50 deletions
diff --git a/sbin/pdisk/dump.c b/sbin/pdisk/dump.c
index 7a0f0995e8a..a8ced2c7135 100644
--- a/sbin/pdisk/dump.c
+++ b/sbin/pdisk/dump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dump.c,v 1.72 2016/01/31 15:28:56 krw Exp $ */
+/* $OpenBSD: dump.c,v 1.73 2016/01/31 22:52:57 krw Exp $ */
/*
* dump.c - dumping partition maps
@@ -32,12 +32,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <util.h>
#include "partition_map.h"
#include "dump.h"
#include "io.h"
-void adjust_value_and_compute_prefix(double *, int *);
void dump_block(unsigned char *, int);
void dump_block_zero(struct partition_map *);
void dump_partition_entry(struct entry *, int, int, int);
@@ -48,14 +48,16 @@ int get_max_type_string_length(struct partition_map *);
void
dump_block_zero(struct partition_map *map)
{
+ char buf[FMT_SCALED_STRSIZE];
struct ddmap *m;
- double value;
- int i, prefix;
+ int i;
- value = ((double)map->sbBlkCount) * map->sbBlkSize;
- adjust_value_and_compute_prefix(&value, &prefix);
- printf("\nDevice block size=%u, Number of Blocks=%u (%1.1f%c)\n",
- map->sbBlkSize, map->sbBlkCount, value, prefix);
+ printf("\nDevice block size=%u, Number of Blocks=%u",
+ map->sbBlkSize, map->sbBlkCount);
+ if (fmt_scaled(map->sbBlkCount * map->sbBlkSize, buf) == 0)
+ printf(" (%s)\n", buf);
+ else
+ printf("\n");
printf("DeviceType=0x%x, DeviceId=0x%x\n", map->sbDevType,
map->sbDevId);
@@ -90,7 +92,7 @@ dump_partition_map(struct partition_map *map)
max_name_length = get_max_name_string_length(map);
if (max_name_length < 6)
max_name_length = 6;
- printf(" #: %*s %-*s %*s %-*s ( size )\n", max_type_length, "type",
+ printf(" #: %*s %-*s %*s %-*s\n", max_type_length, "type",
max_name_length, "name", digits, "length", digits, "base");
LIST_FOREACH(entry, &map->disk_order, disk_entry) {
@@ -102,11 +104,10 @@ dump_partition_map(struct partition_map *map)
void
-dump_partition_entry(struct entry *entry, int type_length,
- int name_length, int digits)
+dump_partition_entry(struct entry *entry, int type_length, int name_length,
+ int digits)
{
- double bytes;
- int j;
+ char buf[FMT_SCALED_STRSIZE];
printf("%2ld: %*.32s", entry->disk_address, type_length,
entry->dpme_type);
@@ -116,11 +117,11 @@ dump_partition_entry(struct entry *entry, int type_length,
printf("%*u @ %-*u", digits, entry->dpme_pblocks, digits,
entry->dpme_pblock_start);
- bytes = ((double)entry->dpme_pblocks) * entry->the_map->physical_block;
- adjust_value_and_compute_prefix(&bytes, &j);
- if (j != ' ' && j != 'K')
- printf(" (%#5.1f%c)", bytes, j);
- printf("\n");
+ if (fmt_scaled(entry->dpme_pblocks * entry->the_map->sbBlkSize, buf) ==
+ 0)
+ printf("(%s)\n", buf);
+ else
+ printf("\n");
}
@@ -369,35 +370,3 @@ get_max_base_or_length(struct partition_map *map)
return max;
}
-
-void
-adjust_value_and_compute_prefix(double *value, int *prefix)
-{
- double bytes;
- int multiplier;
-
- bytes = *value;
- if (bytes < 1024.0) {
- multiplier = ' ';
- } else {
- bytes = bytes / 1024.0;
- if (bytes < 1024.0) {
- multiplier = 'K';
- } else {
- bytes = bytes / 1024.0;
- if (bytes < 1024.0) {
- multiplier = 'M';
- } else {
- bytes = bytes / 1024.0;
- if (bytes < 1024.0) {
- multiplier = 'G';
- } else {
- bytes = bytes / 1024.0;
- multiplier = 'T';
- }
- }
- }
- }
- *value = bytes;
- *prefix = multiplier;
-}