From patchwork Fri Apr 8 07:53:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 90295 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 F029EB6F84 for ; Fri, 8 Apr 2011 18:14:17 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755289Ab1DHIOQ (ORCPT ); Fri, 8 Apr 2011 04:14:16 -0400 Received: from TYO202.gate.nec.co.jp ([202.32.8.206]:58578 "EHLO tyo202.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754302Ab1DHIOP (ORCPT ); Fri, 8 Apr 2011 04:14:15 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.197]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id p388ECKI026643; Fri, 8 Apr 2011 17:14:12 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id p388ECT23324; Fri, 8 Apr 2011 17:14:12 +0900 (JST) Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv4.nec.co.jp (8.13.8/8.13.4) with ESMTP id p388DBtK007707; Fri, 8 Apr 2011 17:14:11 +0900 (JST) Received: from monta.jp.nec.com ([10.26.220.14] [10.26.220.14]) by mail01b.kamome.nec.co.jp with ESMTP id BT-MMP-585997; Fri, 8 Apr 2011 16:54:42 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTP; Fri, 8 Apr 2011 16:53:28 +0900 Message-ID: <4D9EBEF2.4040508@sx.jp.nec.com> Date: Fri, 08 Apr 2011 16:53:22 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: ext4 , Theodore Tso Subject: [PATCH 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, 11 insertions(+), 42 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 76e84a2..11810a3 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -19,25 +19,17 @@ #define _GNU_SOURCE #endif -#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" @@ -325,15 +317,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) PRINT_ERR_MSG(NGMSG_EXT4); - return -1; - } + + endmntent(fp); + FREE(mnt_type); + + return ret ? -1 : 0; } /* @@ -371,9 +362,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; - /* In mmap, offset should be a multiple of the page size */ offset = (loff_t)defrag_data.orig_start * block_size; length = (loff_t)defrag_data.len * block_size; @@ -498,7 +486,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; @@ -824,8 +811,6 @@ static void print_progress(const char *file, loff_t start, loff_t file_size) printf("\033[79;0H\033[K[%u/%u]%s:\t%3d%%", defraged_file_count, total_count, file, min(percent, 100)); fflush(stdout); - - return; } /* @@ -1018,14 +1003,6 @@ static int file_defrag(const char *file, const struct stat64 *buf, if (file_check(fd, file, file_frags_start, 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; - } - /* * Calculate the threshold of perfection. * NOTE: 2048 means the maximum block region of mballoc. @@ -1209,9 +1186,6 @@ int main(int argc, char *argv[]) struct stat64 buf; /* Parse arguments */ - if (argc == 1) - goto out; - while ((opt = getopt(argc, argv, "v")) != EOF) { switch (opt) { case 'v': @@ -1270,7 +1244,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; @@ -1299,17 +1272,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, @@ -1322,9 +1294,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",