diff options
author | Arda Cinar <kuzux92@gmail.com> | 2023-01-10 15:07:17 +0300 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-01-15 19:12:19 +0100 |
commit | ae36a80a6c7622ae1d017d619e6fd1b393481d3a (patch) | |
tree | eb0b45e396d570b8b9c9103634046e5b8811da48 /Userland/Utilities | |
parent | dd582e4ae3994f98754e255ad8890d0128cf737d (diff) | |
download | serenity-ae36a80a6c7622ae1d017d619e6fd1b393481d3a.zip |
df: Add an option to print the human readable sizes in powers of 10
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/df.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Userland/Utilities/df.cpp b/Userland/Utilities/df.cpp index 760b0456d2..a2454542d2 100644 --- a/Userland/Utilities/df.cpp +++ b/Userland/Utilities/df.cpp @@ -26,11 +26,13 @@ struct FileSystem { ErrorOr<int> serenity_main(Main::Arguments arguments) { bool flag_human_readable = false; + bool flag_human_readable_si = false; bool flag_inode_info = false; Core::ArgsParser args_parser; args_parser.set_general_help("Display free disk space of each partition."); args_parser.add_option(flag_human_readable, "Print human-readable sizes", "human-readable", 'h'); + args_parser.add_option(flag_human_readable_si, "Print human-readable sizes in SI units", "si", 'H'); args_parser.add_option(flag_inode_info, "Show inode information as well", "inodes", 'i'); args_parser.parse(arguments); @@ -80,10 +82,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) out("{:12} ", fs); - if (flag_human_readable) { - out("{:>12} ", human_readable_size(total_block_count * block_size)); - out("{:>12} ", human_readable_size(used_block_count * block_size)); - out("{:>12} ", human_readable_size(free_block_count * block_size)); + bool human_readable = flag_human_readable || flag_human_readable_si; + auto human_readable_based_on = flag_human_readable_si ? AK::HumanReadableBasedOn::Base10 : AK::HumanReadableBasedOn::Base2; + + if (human_readable) { + out("{:>12} ", human_readable_size(total_block_count * block_size, human_readable_based_on)); + out("{:>12} ", human_readable_size(used_block_count * block_size, human_readable_based_on)); + out("{:>12} ", human_readable_size(free_block_count * block_size, human_readable_based_on)); out("{:>11}% ", used_percentage); } else { out("{:>12} ", (uint64_t)total_block_count); @@ -93,10 +98,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } if (flag_inode_info) { - if (flag_human_readable) { - out("{:>12} ", human_readable_quantity(total_inode_count)); - out("{:>12} ", human_readable_quantity(used_inode_count)); - out("{:>12} ", human_readable_quantity(free_inode_count)); + if (human_readable) { + out("{:>12} ", human_readable_quantity(total_inode_count, human_readable_based_on)); + out("{:>12} ", human_readable_quantity(used_inode_count, human_readable_based_on)); + out("{:>12} ", human_readable_quantity(free_inode_count, human_readable_based_on)); out("{:>11}% ", used_inode_percentage); } else { out("{:>12} ", (uint64_t)total_inode_count); |