I want to add percent to output used/maximum files and blocks
cover I want to add percent to output used/maximum files and blocks
I think this is good information because
numbers alone are not enough for people.
I check that the denominator is zero for safety, may never be zero, but I prefer to check.
Same for copying in char pointers. I prefer to use snprintf, than sprintf or strcpy, because this way it won't never overrun the pointer size.
My experience says that there is to check all possibilities, even if I think that never will happen (error free).
Oscar Megia López (1):
e2fsck: Add percent to files and blocks feature
e2fsck/unix.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
base-commit: 25ad8a431331b4d1d444a70b6079456cc612ac40
Signature · 1 line
2.40.0
PATCH 1/1 e2fsck: Add percent to files and blocks feature
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.
--- e2fsck/unix.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
e2fsck/unix.c +23 -2
@@ -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;
Signature · 1 line
2.40.0
Re: [PATCH 1/1] e2fsck: Add percent to files and blocks feature
Quoted 33 lines · Oscar Megia López
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 <[email protected]>---
e2fsck/unix.c| 25 +++++++++++++++++++++++--1 file changed, 23 insertions(+), 2 deletions(-)e2fsck/unix.c +2
-0@@ -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);
e2fsck/unix.c static void check_if_skip(e2fsck_t ctx) · line 454
Quoted 10 lines
e2fsck/unix.c +8
-0} +/* 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)," " ); + }
Instead of snprintf() this could just be initialized at variable declaration time:
char percent_files[8] = "";
That avoids extra runtime overhead and is no less safe. (This is adjusted to compensate for the format change below.)
e2fsck/unix.c static void check_if_skip(e2fsck_t ctx) · line 462
Quoted 7 lines
e2fsck/unix.c +7
-0+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)," " ); + }
This could similarly be set at initialization:
char percent_blocks[8] = "";
e2fsck/unix.c static void check_if_skip(e2fsck_t ctx) · line 465
Quoted 3 lines
e2fsck/unix.c +1
-1/* 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"),
This would be more readable if it left one space after each "%s" and then didn't include the trailing space in each string:
log_out(ctx, _("%s: clean, %u/%u%s files, %llu/%llu%s blocks"),Cheers, Andreas
Quoted 15 lines
e2fsck/unix.c +3
-1ctx->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;Signature · 1 line
2.40.0
Re: [PATCH 1/1] e2fsck: Add percent to files and blocks feature
Quoted 47 lines · Andreas Dilger
Quoted 33 lines · Oscar Megia López
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 <[email protected]>---
e2fsck/unix.c| 25 +++++++++++++++++++++++--1 file changed, 23 insertions(+), 2 deletions(-)e2fsck/unix.c +2
-0@@ -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);e2fsck/unix.c static void check_if_skip(e2fsck_t ctx) · line 454
Quoted 10 lines
e2fsck/unix.c +8
-0} +/* 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)," " ); + }Instead of
snprintf()this could just be initialized at variable declaration time:
Quoted 5 lines
char percent_files[8] = "";That avoids extra runtime overhead and is no less safe. (This is adjusted to compensate for the format change below.)
Thanks for your advice, I will apply it.
Quoted 8 lines
e2fsck/unix.c static void check_if_skip(e2fsck_t ctx) · line 462
Quoted 7 lines
e2fsck/unix.c +7
-0+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)," " ); + }
Quoted 4 lines
This could similarly be set at initialization:
char percent_blocks[8] = "";
Thanks for your advice, I will apply it.
Quoted 9 lines
e2fsck/unix.c static void check_if_skip(e2fsck_t ctx) · line 465
Quoted 3 lines
e2fsck/unix.c +1
-1/* 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"),This would be more readable if it left one space after each "%s" and then didn't include the trailing space in each string:
log_out(ctx, _("%s: clean, %u/%u%s files, %llu/%llu%s blocks"),
You are right. I will apply it.
Quoted 2 lines
Cheers, Andreas
Very thanks Andreas for your advices and your time.
I will apply these changes to my patch.
Regards
Oscar
Quoted 15 lines
Quoted 15 lines
e2fsck/unix.c +3
-1ctx->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;Signature · 1 line
2.40.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH] e2fsck: Add percent to files and blocks feature
Quoted 6 lines · Markus Elfring
You should put also the address "[email protected]" into the message header field "Cc" (or "To").
Sorry, I though that were different proyects.
Quoted 5 lines
Quoted 2 lines
I need percentages to see how disk is occupied.
At which occasions do you tend to care for such numbers?
For example, when the root disk is almost full, I'd rather know than get system/application errors. It has happened to me and I think it is necessary information.
Quoted 5 lines
Quoted 2 lines
If also I would see percentages for me would be perfect.
Where would you find such information more helpful?
Because on my computer it shows busy/full for one or two seconds and I don't have time to remember them, much less to calculate the occupancy percentage. Humans handle percentages much better than many numbers in a row (at least I do). Also when running e2fsck it is useful to see percentages.
This is e2fsck with my patch:
$ sudo e2fsck/e2fsck /dev/sdc5 e2fsck 1.47.0 (5-Feb-2023) label: clean, 405784/2449408 (16%) files, 6651303/9765625 (68%) blocks $
I think it is helpful to show the percentage. Only number of files/blocks and totals is not enought.
Quoted 5 lines
Quoted 2 lines
I think that this feature is going to be good for everyone.
Will persuasion efforts grow accordingly?
Sorry, I don't understand what you mean.
Quoted 3 lines
How do you think about to choose a corresponding imperative change suggestion?
Sorry I do not understand what you mean. If you want to say that my sentence "I think that this feature is going to be good for everyone." is to force the change, I'm sorry. It was just a comment to explain why I submitted the patch. If it was only useful to me, I would not have sent it.
Quoted 5 lines
Regards,
Markus
Signature · 2 lines
Regards Oscar Megia López