linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Oscar Megia López" <megia.oscar@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: "Oscar Megia López" <megia.oscar@gmail.com>
Subject: [PATCH 1/1] e2fsck: Add percent to files and blocks feature
Date: Sun, 23 Apr 2023 10:23:49 +0200	[thread overview]
Message-ID: <20230423082349.53474-2-megia.oscar@gmail.com> (raw)
In-Reply-To: <20230423082349.53474-1-megia.oscar@gmail.com>

I need percentages to see how disk is occupied.
Used and maximum are good, but humans work better with percentages.

When my linux boots,
I haven't enough time to remember numbers and calculate.

My PC is very fast. I can only see the message for one or two seconds.

If also I would see percentages for me would be perfect.

I think that this feature is going to be good for everyone.

Signed-off-by: Oscar Megia López <megia.oscar@gmail.com>
---
 e2fsck/unix.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index e5b672a2..b820ca8d 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -350,6 +350,8 @@ static void check_if_skip(e2fsck_t ctx)
 	int defer_check_on_battery;
 	int broken_system_clock;
 	time_t lastcheck;
+	char percent_files[9];
+	char percent_blocks[9];
 
 	if (ctx->flags & E2F_FLAG_PROBLEMS_FIXED)
 		return;
@@ -442,14 +444,33 @@ static void check_if_skip(e2fsck_t ctx)
 		ext2fs_mark_super_dirty(fs);
 	}
 
+	/* Calculate percentages */
+	if (fs->super->s_inodes_count > 0) {
+		snprintf(percent_files, sizeof(percent_files), " (%u%%) ",
+		((fs->super->s_inodes_count - fs->super->s_free_inodes_count) * 100) /
+		fs->super->s_inodes_count);
+	} else {
+		snprintf(percent_files, sizeof(percent_files), " ");
+	}
+
+	if (ext2fs_blocks_count(fs->super) > 0) {
+		snprintf(percent_blocks, sizeof(percent_blocks), " (%llu%%) ",
+		(unsigned long long) ((ext2fs_blocks_count(fs->super) -
+		ext2fs_free_blocks_count(fs->super)) * 100) / ext2fs_blocks_count(fs->super));
+	} else {
+		snprintf(percent_blocks, sizeof(percent_blocks), " ");
+	}
+
 	/* Print the summary message when we're skipping a full check */
-	log_out(ctx, _("%s: clean, %u/%u files, %llu/%llu blocks"),
+	log_out(ctx, _("%s: clean, %u/%u%sfiles, %llu/%llu%sblocks"),
 		ctx->device_name,
 		fs->super->s_inodes_count - fs->super->s_free_inodes_count,
 		fs->super->s_inodes_count,
+		percent_files,
 		(unsigned long long) ext2fs_blocks_count(fs->super) -
 		ext2fs_free_blocks_count(fs->super),
-		(unsigned long long) ext2fs_blocks_count(fs->super));
+		(unsigned long long) ext2fs_blocks_count(fs->super),
+		percent_blocks);
 	next_check = 100000;
 	if (fs->super->s_max_mnt_count > 0) {
 		next_check = fs->super->s_max_mnt_count - fs->super->s_mnt_count;
-- 
2.40.0


  reply	other threads:[~2023-04-23  8:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23  8:23 [PATCH 0/1] I want to add percent to output used/maximum files and blocks Oscar Megia López
2023-04-23  8:23 ` Oscar Megia López [this message]
2023-07-26 16:15   ` [PATCH 1/1] e2fsck: Add percent to files and blocks feature Andreas Dilger
2023-07-27  7:15     ` Oscar Megia López
     [not found]   ` <73bfa972-1f3a-3a74-c511-4255eae91806@web.de>
2023-07-28  7:05     ` [PATCH] " Oscar Megia López

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230423082349.53474-2-megia.oscar@gmail.com \
    --to=megia.oscar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).