From patchwork Mon Nov 14 06:25:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 125487 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1F652B71FA for ; Mon, 14 Nov 2011 17:32:21 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752103Ab1KNGcU (ORCPT ); Mon, 14 Nov 2011 01:32:20 -0500 Received: from TYO201.gate.nec.co.jp ([202.32.8.193]:57408 "EHLO tyo201.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751855Ab1KNGcT (ORCPT ); Mon, 14 Nov 2011 01:32:19 -0500 Received: from mailgate3.nec.co.jp ([10.7.69.192]) by tyo201.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id pAE6WGNl017490; Mon, 14 Nov 2011 15:32:16 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id pAE6WGL28676; Mon, 14 Nov 2011 15:32:16 +0900 (JST) Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv3.nec.co.jp (8.13.8/8.13.4) with ESMTP id pAE6WFdi024793; Mon, 14 Nov 2011 15:32:15 +0900 (JST) Received: from kameyata.jp.nec.com ([10.26.220.29] [10.26.220.29]) by mail01b.kamome.nec.co.jp with ESMTP id BT-MMP-876309; Mon, 14 Nov 2011 15:25:36 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTPA id BT-MMP-43320; Mon, 14 Nov 2011 15:25:35 +0900 Message-ID: <4EC0B45F.3060106@sx.jp.nec.com> Date: Mon, 14 Nov 2011 15:25:35 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.18) Gecko/20110613 Thunderbird/3.1.11 MIME-Version: 1.0 To: ext4 CC: Theodore Tso , Andreas Dilger Subject: [PATCH v3 11/11] e4defrag: Remove unnecessary code Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Remove unused header include, duplicate code, and so on. Signed-off-by: Kazuya Mio --- misc/e4defrag.c | 53 ++++++++++++----------------------------------------- 1 file changed, 12 insertions(+), 41 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 0b4873d..c07a79b 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -20,25 +20,17 @@ #endif #include "config.h" -#include -#include -#include #include #include #include -#include #include #include -#include -#include #include #include #include #include #include #include -#include -#include #include "e2p/e2p.h" #include "ext2fs/ext2_types.h" @@ -335,15 +327,14 @@ static int is_ext4(const char *file) strncpy(lost_found_dir, mnt->mnt_dir, PATH_MAX); } - endmntent(fp); - if (strcmp(mnt_type, FS_EXT4) == 0) { - FREE(mnt_type); - return 0; - } else { - FREE(mnt_type); + ret = strcmp(mnt_type, FS_EXT4); + if (ret != 0) PRINT_ERR_MSG(NGMSG_EXT4); - return -1; - } + + endmntent(fp); + FREE(mnt_type); + + return (ret == 0) ? 0 : -1; } /* @@ -381,9 +372,6 @@ static int page_in_core(int fd, struct move_extent defrag_data, void *page = NULL; loff_t offset, end_offset, length; - if (vec == NULL || *vec != NULL) - return -1; - pagesize = sysconf(_SC_PAGESIZE); if (pagesize < 0) return -1; @@ -505,7 +493,6 @@ static int file_frag_count(int fd) * ioctl just get file fragment count. */ memset(&fiemap_buf, 0, sizeof(struct fiemap)); - fiemap_buf.fm_start = 0; fiemap_buf.fm_length = FIEMAP_MAX_OFFSET; fiemap_buf.fm_flags |= FIEMAP_FLAG_SYNC; @@ -883,7 +870,7 @@ static int call_defrag(int fd, int donor_fd, const char *file, /* Free pages */ ret = defrag_fadvise(fd, move_data, vec, page_num); - if (vec) { + if (vec != NULL) { free(vec); vec = NULL; } @@ -1030,14 +1017,6 @@ static int file_defrag(const char *file, const struct stat64 *buf, if (file_check(fd, file, blk_count) < 0) goto out; - if (fsync(fd) < 0) { - if (mode_flag & DETAIL) { - PRINT_FILE_NAME(file); - PRINT_ERR_MSG_WITH_ERRNO("Failed to sync(fsync)"); - } - goto out; - } - orig_score = e2p_get_fragscore(fd, threshold, EXTENT_MAX_BLKS, &err); if (err != 0) { errno = err; @@ -1216,9 +1195,6 @@ int main(int argc, char *argv[]) struct stat64 buf; /* Parse arguments */ - if (argc == 1) - goto out; - while ((opt = getopt(argc, argv, "Fv")) != EOF) { switch (opt) { case 'F': @@ -1285,7 +1261,6 @@ int main(int argc, char *argv[]) continue; } arg_type = DIRNAME; - strncpy(dir_name, argv[i], strnlen(argv[i], PATH_MAX)); } else if (S_ISREG(buf.st_mode)) { /* Regular file */ arg_type = FILENAME; @@ -1314,17 +1289,16 @@ int main(int argc, char *argv[]) switch (arg_type) { case DIRNAME: { - int mount_dir_len = 0; - mount_dir_len = strnlen(lost_found_dir, PATH_MAX); + int mount_dir_len = strnlen(lost_found_dir, PATH_MAX); strncat(lost_found_dir, "/lost+found", PATH_MAX - strnlen(lost_found_dir, PATH_MAX)); - /* Not the case("e4defrag mount_piont_dir") */ + /* Not the case("e4defrag mount_point_dir") */ if (dir_name[mount_dir_len] != '\0') { /* - * "e4defrag mount_piont_dir/lost+found" - * or "e4defrag mount_piont_dir/lost+found/" + * "e4defrag mount_point_dir/lost+found" + * or "e4defrag mount_point_dir/lost+found/" */ if (strncmp(lost_found_dir, dir_name, strnlen(lost_found_dir, @@ -1337,9 +1311,6 @@ int main(int argc, char *argv[]) PRINT_FILE_NAME(argv[i]); continue; } - - /* "e4defrag mount_piont_dir/else_dir" */ - memset(lost_found_dir, 0, PATH_MAX + 1); } printf("ext4 defragmentation for directory(%s)\n",