nftw64() may go wrong sometimes, so add error checking to its calls. Signed-off-by: Geliang Tang <geliangtang@xxxxxxxxx> --- misc/e4defrag.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 1d1b4f4..edf54c9 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -1856,7 +1856,12 @@ int main(int argc, char *argv[]) PATH_MAX)); } - nftw64(dir_name, calc_entry_counts, FTW_OPEN_FD, flags); + if (nftw64(dir_name, calc_entry_counts, + FTW_OPEN_FD, flags)) { + perror("nftw64 error"); + PRINT_FILE_NAME(argv[i]); + continue; + } if (mode_flag & STATISTIC) { if (mode_flag & DETAIL) @@ -1870,8 +1875,12 @@ int main(int argc, char *argv[]) continue; } - nftw64(dir_name, file_statistic, - FTW_OPEN_FD, flags); + if (nftw64(dir_name, file_statistic, + FTW_OPEN_FD, flags)) { + perror("nftw64 error"); + PRINT_FILE_NAME(argv[i]); + continue; + } if (succeed_cnt != 0 && current_uid == ROOT_UID) { @@ -1908,7 +1917,11 @@ int main(int argc, char *argv[]) break; } /* File tree walk */ - nftw64(dir_name, file_defrag, FTW_OPEN_FD, flags); + if (nftw64(dir_name, file_defrag, FTW_OPEN_FD, flags)) { + perror("nftw64 error"); + PRINT_FILE_NAME(argv[i]); + continue; + } printf("\n\tSuccess:\t\t\t[ %u/%u ]\n", succeed_cnt, total_count); printf("\tFailure:\t\t\t[ %u/%u ]\n", -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html