1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 16:45:08 +00:00

df: Add an option to print the human readable sizes in powers of 10

This commit is contained in:
Arda Cinar 2023-01-10 15:07:17 +03:00 committed by Jelle Raaijmakers
parent dd582e4ae3
commit ae36a80a6c

View file

@ -26,11 +26,13 @@ struct FileSystem {
ErrorOr<int> serenity_main(Main::Arguments arguments) ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
bool flag_human_readable = false; bool flag_human_readable = false;
bool flag_human_readable_si = false;
bool flag_inode_info = false; bool flag_inode_info = false;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.set_general_help("Display free disk space of each partition."); 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, "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.add_option(flag_inode_info, "Show inode information as well", "inodes", 'i');
args_parser.parse(arguments); args_parser.parse(arguments);
@ -80,10 +82,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
out("{:12} ", fs); out("{:12} ", fs);
if (flag_human_readable) { bool human_readable = flag_human_readable || flag_human_readable_si;
out("{:>12} ", human_readable_size(total_block_count * block_size)); auto human_readable_based_on = flag_human_readable_si ? AK::HumanReadableBasedOn::Base10 : AK::HumanReadableBasedOn::Base2;
out("{:>12} ", human_readable_size(used_block_count * block_size));
out("{:>12} ", human_readable_size(free_block_count * block_size)); 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); out("{:>11}% ", used_percentage);
} else { } else {
out("{:>12} ", (uint64_t)total_block_count); out("{:>12} ", (uint64_t)total_block_count);
@ -93,10 +98,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
} }
if (flag_inode_info) { if (flag_inode_info) {
if (flag_human_readable) { if (human_readable) {
out("{:>12} ", human_readable_quantity(total_inode_count)); out("{:>12} ", human_readable_quantity(total_inode_count, human_readable_based_on));
out("{:>12} ", human_readable_quantity(used_inode_count)); out("{:>12} ", human_readable_quantity(used_inode_count, human_readable_based_on));
out("{:>12} ", human_readable_quantity(free_inode_count)); out("{:>12} ", human_readable_quantity(free_inode_count, human_readable_based_on));
out("{:>11}% ", used_inode_percentage); out("{:>11}% ", used_inode_percentage);
} else { } else {
out("{:>12} ", (uint64_t)total_inode_count); out("{:>12} ", (uint64_t)total_inode_count);