From: Lennart Poettering Date: Wed, 6 May 2020 20:43:54 +0000 (+0200) Subject: homectl: show disk free in percent in 'inspect' X-Git-Tag: v246-rc1~423 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f5b7d681c75dd6e62b8871215a864592de678bac;p=thirdparty%2Fsystemd.git homectl: show disk free in percent in 'inspect' --- diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c index e5eff508401..7b14636ebf7 100644 --- a/src/shared/user-record-show.c +++ b/src/shared/user-record-show.c @@ -340,12 +340,30 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { if (hr->disk_usage != UINT64_MAX) { char buf[FORMAT_BYTES_MAX]; - printf(" Disk Usage: %s\n", format_bytes(buf, sizeof(buf), hr->disk_usage)); + + if (hr->disk_size != UINT64_MAX) { + unsigned permille; + + permille = (unsigned) DIV_ROUND_UP(hr->disk_usage * 1000U, hr->disk_size); /* Round up! */ + printf(" Disk Usage: %s (= %u.%01u%%)\n", + format_bytes(buf, sizeof(buf), hr->disk_usage), + permille / 10, permille % 10); + } else + printf(" Disk Usage: %s\n", format_bytes(buf, sizeof(buf), hr->disk_usage)); } if (hr->disk_free != UINT64_MAX) { char buf[FORMAT_BYTES_MAX]; - printf(" Disk Free: %s\n", format_bytes(buf, sizeof(buf), hr->disk_free)); + + if (hr->disk_size != UINT64_MAX) { + unsigned permille; + + permille = (unsigned) ((hr->disk_free * 1000U) / hr->disk_size); /* Round down! */ + printf(" Disk Free: %s (= %u.%01u%%)\n", + format_bytes(buf, sizeof(buf), hr->disk_free), + permille / 10, permille % 10); + } else + printf(" Disk Free: %s\n", format_bytes(buf, sizeof(buf), hr->disk_free)); } if (hr->disk_floor != UINT64_MAX) {