From 84cf7c1df73c161d9e2fc752bd0d9959b0c31da2 Mon Sep 17 00:00:00 2001 From: Allan Jude Date: Sat, 13 Oct 2018 02:21:23 +0000 Subject: [PATCH] Make `mfiutil show progress` print out the elapsed time estimate in a more humanized way PR: 225993 Submitted by: Enji Cooper Reviewed by: jhb (previous version) Approved by: re (rgrimes) --- usr.sbin/mfiutil/mfi_cmd.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/usr.sbin/mfiutil/mfi_cmd.c b/usr.sbin/mfiutil/mfi_cmd.c index 33bd01dc6e8c..094c9017348b 100644 --- a/usr.sbin/mfiutil/mfi_cmd.c +++ b/usr.sbin/mfiutil/mfi_cmd.c @@ -31,17 +31,18 @@ * $FreeBSD$ */ -#include -#include #include +#include #include #include #include +#include #include #include #include #include +#include #include #include "mfiutil.h" @@ -311,24 +312,34 @@ mfi_open(int unit, int acs) return (open(path, acs)); } +static void +print_time_humanized(uint seconds) +{ + + if (seconds > 3600) { + printf("%u:", seconds / 3600); + } + if (seconds > 60) { + seconds %= 3600; + printf("%02u:%02u", seconds / 60, seconds % 60); + } else { + printf("%us", seconds); + } +} + void mfi_display_progress(const char *label, struct mfi_progress *prog) { uint seconds; - printf("%s: %.2f%% complete, after %ds", label, - (float)prog->progress * 100 / 0xffff, prog->elapsed_seconds); + printf("%s: %.2f%% complete after ", label, + (float)prog->progress * 100 / 0xffff); + print_time_humanized(prog->elapsed_seconds); if (prog->progress != 0 && prog->elapsed_seconds > 10) { printf(" finished in "); seconds = (0x10000 * (uint32_t)prog->elapsed_seconds) / prog->progress - prog->elapsed_seconds; - if (seconds > 3600) - printf("%u:", seconds / 3600); - if (seconds > 60) { - seconds %= 3600; - printf("%02u:%02u", seconds / 60, seconds % 60); - } else - printf("%us", seconds); + print_time_humanized(seconds); } printf("\n"); }