From c3749cad154ace57ef3c23a950fbaf44c7ad8a3b Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 3 Jan 2019 23:06:42 -0500 Subject: [PATCH] e4defrag: adjust total count when files change during the run If files are created while e4defrag is running, it's quite possible for succeed_cnt to be larger than total_count, in which case the number of failures (calculated via total_count - succeed_cnt) will overflow and become a very large unsigned number. The way we calculate statistics is a bit silly, since when recurse into directories is counted, it's counted as a "failure". But we'll ignore this from now, and avoid the unsigned overflow. Address-Debian-Bug: #888899 Signed-off-by: Theodore Ts'o --- misc/e4defrag.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 9d237da..b0a825f 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -1055,6 +1055,8 @@ static int file_statistic(const char *file, const struct stat64 *buf, struct fiemap_extent_list *logical_list_head = NULL; defraged_file_count++; + if (defraged_file_count > total_count) + total_count = defraged_file_count; if (mode_flag & DETAIL) { if (total_count == 1 && regular_count == 1) @@ -1421,6 +1423,8 @@ static int file_defrag(const char *file, const struct stat64 *buf, struct fiemap_extent_group *orig_group_tmp = NULL; defraged_file_count++; + if (defraged_file_count > total_count) + total_count = defraged_file_count; if (mode_flag & DETAIL) { printf("[%u/%u]", defraged_file_count, total_count); -- 1.8.3.1