mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:24:58 +00:00
df: Add an option to print the human readable sizes in powers of 10
This commit is contained in:
parent
dd582e4ae3
commit
ae36a80a6c
1 changed files with 13 additions and 8 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue