From 1d21f4bd8ddf26281eaad3028feedb08c8401408 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 9 Jul 2009 15:03:39 -0400 Subject: [PATCH] e4defrag: Fix a core dump when trying to defrag a file with no blocks Signed-off-by Akira Fujita Signed-off-by: "Theodore Ts'o" --- misc/e4defrag.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 05d6893..1c7c012 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -1303,6 +1303,15 @@ int file_statistic(const char *file, const struct stat64 *buf, return 0; } + /* Has no blocks */ + if (buf->st_blocks == 0) { + if (mode_flag & DETAIL) { + PRINT_FILE_NAME(file); + STATISTIC_ERR_MSG("File has no blocks"); + } + return 0; + } + fd = open64(file, O_RDONLY); if (fd < 0) { if (mode_flag & DETAIL) { @@ -1624,6 +1633,15 @@ int file_defrag(const char *file, const struct stat64 *buf, return 0; } + /* Has no blocks */ + if (buf->st_blocks == 0) { + if (mode_flag & DETAIL) { + PRINT_FILE_NAME(file); + STATISTIC_ERR_MSG("File has no blocks"); + } + return 0; + } + fd = open64(file, O_RDONLY); if (fd < 0) { if (mode_flag & DETAIL) { -- 1.8.3.1