From patchwork Sun Jan 13 09:08:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 211603 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 6AACF2C00F7 for ; Sun, 13 Jan 2013 19:54:53 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752013Ab3AMIyw (ORCPT ); Sun, 13 Jan 2013 03:54:52 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:62181 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751772Ab3AMIyw (ORCPT ); Sun, 13 Jan 2013 03:54:52 -0500 Received: by mail-pa0-f45.google.com with SMTP id bg2so1714404pad.4 for ; Sun, 13 Jan 2013 00:54:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=KQ0ansWJBm6V5Po32tePv/7kS2e+oQtmie/UOV99TYg=; b=k21QC18r2pABo2jpq2h41Cc+Z2llOjhui6WntjfCkZzyFA4qUaayn2Fnl92TCQivUt +aoTauaQgm5gyJcoaGZNbnc3Wi+RzhLHTKI3jbRTpsosT464sR/+zQ0jA5cMKaz2Iogu BR0c3YiM67GXAIAEXUHoXMjXI+7d7GDg+/5t0ykR31atRFdTvPdy3bFTY45YoK4at0Ac 9+yfQu63lVOcTmjpFp/d+AxeBqHQ7pv+clOa/wEkW2AwYmV98zWNIpq8ai71q6vv1VPl YXZ8a4/beNYgqau/P9Dzluu5moqdiJ52T6fQMHeW0UDABRoCqVcxZJXYXrdIzYk6HtIQ 68Cw== X-Received: by 10.68.203.129 with SMTP id kq1mr23391107pbc.30.1358067291701; Sun, 13 Jan 2013 00:54:51 -0800 (PST) Received: from lz-desktop.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPS id qf7sm6027872pbb.49.2013.01.13.00.54.47 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 13 Jan 2013 00:54:50 -0800 (PST) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Zheng Liu Subject: [PATCH 2/3] mke2fs: reduce the range of cluster-size Date: Sun, 13 Jan 2013 17:08:14 +0800 Message-Id: <1358068095-9034-2-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: <1358068095-9034-1-git-send-email-wenqing.lz@taobao.com> References: <1358068095-9034-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu There are two bugs need to be fixed, which are about cluster-size. Now the range of cluster-size is from 1024 to 512M bytes. Although with '-C 1024', the cluster-size will be 4096 after making a filesystem because in ext2fs_initialize() set_field() needs to check 'param->s_log_cluster_size' and s_log_cluster_size is 0 as cluster-size is 1024. Then s_log_cluster_size will be assigned to s_log_block_size+4. So we never set cluster-size to 1024. Another bug is that when cluster-size is 512M EXT2FS_C2B will return 0. So s_blocks_per_group will be assigned to zero and we will meet a 'division by zero' error. Here we reduce the range of cluster-size and check s_blocks_per_group=0 to avoid 'division by zero' error. Signed-off-by: Zheng Liu --- lib/ext2fs/initialize.c | 4 ++++ misc/mke2fs.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index dca0d9a..0eccd59 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -226,6 +226,10 @@ errcode_t ext2fs_initialize(const char *name, int flags, super->s_clusters_per_group = EXT2_MAX_CLUSTERS_PER_GROUP(super); super->s_blocks_per_group = EXT2FS_C2B(fs, super->s_clusters_per_group); + if (super->s_blocks_per_group == 0) { + retval = EXT2_ET_TOOSMALL; + goto cleanup; + } } else { set_field(s_blocks_per_group, fs->blocksize * 8); if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) diff --git a/misc/mke2fs.c b/misc/mke2fs.c index bf4d7a2..f4140a1 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1384,8 +1384,8 @@ profile_error: break; case 'C': cluster_size = strtoul(optarg, &tmp, 0); - if (cluster_size < EXT2_MIN_CLUSTER_SIZE || - cluster_size > EXT2_MAX_CLUSTER_SIZE || *tmp) { + if (cluster_size <= EXT2_MIN_CLUSTER_SIZE || + cluster_size >= EXT2_MAX_CLUSTER_SIZE || *tmp) { com_err(program_name, 0, _("invalid cluster size - %s"), optarg);