summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArda Cinar <kuzux92@gmail.com>2022-12-09 22:25:10 +0300
committerSam Atkins <atkinssj@gmail.com>2023-01-02 20:11:18 +0000
commitef71104620ea6edc883c41168272e5a4c97e648e (patch)
treef99dcb0cd04ab7f3e17d8feea71c9f995b2b6c32
parentb2cd935efd389b7850a9c8a54fa2d335d009ae7f (diff)
downloadserenity-ef71104620ea6edc883c41168272e5a4c97e648e.zip
df: Show used percentages for each listed entry
-rw-r--r--Userland/Utilities/df.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/Userland/Utilities/df.cpp b/Userland/Utilities/df.cpp
index e3ba52013e..f92cb3b7bd 100644
--- a/Userland/Utilities/df.cpp
+++ b/Userland/Utilities/df.cpp
@@ -35,9 +35,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto file = TRY(Core::Stream::File::open("/sys/kernel/df"sv, Core::Stream::OpenMode::Read));
if (flag_human_readable) {
- outln("Filesystem Size Used Available Mount point");
+ outln("Filesystem Size Used Available Used% Mount point");
} else {
- outln("Filesystem Blocks Used Available Mount point");
+ outln("Filesystem Blocks Used Available Used% Mount point");
}
auto file_contents = TRY(file->read_until_eof());
@@ -48,21 +48,28 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto fs = fs_object.get("class_name"sv).to_deprecated_string();
auto total_block_count = fs_object.get("total_block_count"sv).to_u64();
auto free_block_count = fs_object.get("free_block_count"sv).to_u64();
+ auto used_block_count = total_block_count - free_block_count;
[[maybe_unused]] auto total_inode_count = fs_object.get("total_inode_count"sv).to_u64();
[[maybe_unused]] auto free_inode_count = fs_object.get("free_inode_count"sv).to_u64();
auto block_size = fs_object.get("block_size"sv).to_u64();
auto mount_point = fs_object.get("mount_point"sv).to_deprecated_string();
+ auto used_percentage = 100;
+ if (total_block_count != 0)
+ used_percentage = (used_block_count * 100) / total_block_count;
+
out("{:10}", fs);
if (flag_human_readable) {
out("{:>10} ", human_readable_size(total_block_count * block_size));
- out("{:>10} ", human_readable_size((total_block_count - free_block_count) * block_size));
+ out("{:>10} ", human_readable_size(used_block_count * block_size));
out("{:>10} ", human_readable_size(free_block_count * block_size));
+ out("{:>9}% ", used_percentage);
} else {
out("{:>10} ", (uint64_t)total_block_count);
- out("{:>10} ", (uint64_t)(total_block_count - free_block_count));
+ out("{:>10} ", (uint64_t)used_block_count);
out("{:>10} ", (uint64_t)free_block_count);
+ out("{:>9}% ", used_percentage);
}
out("{}", mount_point);