Skip to content

Commit 2c4f4f1

Browse files
committed
iopint: unhardcode units for printing device size
Signed-off-by: Konstantin Khlebnikov <koct9i@gmail.com>
1 parent 9172aae commit 2c4f4f1

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

ioping.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ long long now(void)
382382
char *path = NULL;
383383
char *fstype = "";
384384
char *device = "";
385+
off_t device_size = 0;
385386

386387
int fd;
387388
void *buf;
@@ -901,13 +902,9 @@ int main (int argc, char **argv)
901902
if (fd < 0)
902903
err(2, "failed to open \"%s\"", path);
903904

904-
st.st_size = get_device_size(fd, &st);
905-
905+
device_size = get_device_size(fd, &st);
906+
st.st_size = device_size;
906907
fstype = "device";
907-
device = malloc(32);
908-
if (!device)
909-
err(2, "no mem");
910-
snprintf(device, 32, "%.1f Gb", (double)st.st_size/(1ll<<30));
911908
} else {
912909
errx(2, "unsupported destination: \"%s\"", path);
913910
}
@@ -1008,8 +1005,10 @@ int main (int argc, char **argv)
10081005

10091006
if (!quiet) {
10101007
print_size(ret_size);
1011-
printf(" from %s (%s %s): request=%d time=",
1012-
path, fstype, device, request);
1008+
printf(" from %s (%s %s", path, fstype, device);
1009+
if (device_size)
1010+
print_size(device_size);
1011+
printf("): request=%d time=", request);
10131012
print_time(this_time);
10141013
printf("\n");
10151014
}
@@ -1079,8 +1078,10 @@ int main (int argc, char **argv)
10791078
time_min, time_avg,
10801079
time_max, time_mdev);
10811080
} else if (!quiet || (!period_time && !period_request)) {
1082-
printf("\n--- %s (%s %s) ioping statistics ---\n",
1083-
path, fstype, device);
1081+
printf("\n--- %s (%s %s", path, fstype, device);
1082+
if (device_size)
1083+
print_size(device_size);
1084+
printf(") ioping statistics ---\n");
10841085
print_int(request);
10851086
printf(" requests completed in ");
10861087
print_time(time_total);

0 commit comments

Comments
 (0)