From ca210687f858d6e294939410af245e14106e79da Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 19 Nov 2019 19:06:55 +0100 Subject: [PATCH] btrfs-progs: fi usage: print ratio of used/total for each chunk type This is based on idea from Stanislaw Gruszka to print the ratio, originally suggested for the 'fi df', but we don't want to add new things there and let people use 'fi us' instead. The new output fits there and is printed by default without options: Example output: $ btrfs fi us /mnt [...] Data,single: Size:339.00GiB, Used:172.05GiB (50.75%) Metadata,single: Size:7.00GiB, Used:3.41GiB (48.70%) System,single: Size:32.00MiB, Used:64.00KiB (0.20%) Signed-off-by: David Sterba --- cmds/filesystem-usage.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c index 95b157bf..aa7065d5 100644 --- a/cmds/filesystem-usage.c +++ b/cmds/filesystem-usage.c @@ -932,8 +932,10 @@ static void _cmd_filesystem_usage_linear(unsigned unit_mode, r_mode, pretty_size_mode(sargs->spaces[i].total_bytes, unit_mode)); - printf("Used:%s\n", - pretty_size_mode(sargs->spaces[i].used_bytes, unit_mode)); + printf("Used:%s (%.2f%%)\n", + pretty_size_mode(sargs->spaces[i].used_bytes, unit_mode), + 100.0f * sargs->spaces[i].used_bytes / + (sargs->spaces[i].total_bytes + 1)); print_chunk_device(flags, info_ptr, info_count, device_info_ptr, device_info_count, unit_mode); printf("\n");