From patchwork Thu Dec 12 23:14:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 300811 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 DD4E02C00A1 for ; Fri, 13 Dec 2013 10:14:59 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751929Ab3LLXO7 (ORCPT ); Thu, 12 Dec 2013 18:14:59 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:25752 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751915Ab3LLXO6 (ORCPT ); Thu, 12 Dec 2013 18:14:58 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rBCNErVg028615 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 12 Dec 2013 23:14:54 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBCNErJh022801 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 12 Dec 2013 23:14:53 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBCNErId022795; Thu, 12 Dec 2013 23:14:53 GMT Received: from localhost (/10.145.179.107) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 12 Dec 2013 15:14:52 -0800 Date: Thu, 12 Dec 2013 15:14:51 -0800 From: "Darrick J. Wong" To: Andreas Dilger Cc: "Theodore Ts'o" , Ext4 Developers List , Zheng Liu Subject: [PATCH] mke2fs: clean up kernel version tests Message-ID: <20131212231451.GH10143@birch.djwong.org> References: <20131211011813.30655.39624.stgit@birch.djwong.org> <20131211011837.30655.67812.stgit@birch.djwong.org> <2EB0A146-8AAA-4F4A-9B11-29ED1D2B42F2@dilger.ca> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <2EB0A146-8AAA-4F4A-9B11-29ED1D2B42F2@dilger.ca> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Refactor the running kernel version checks to hide the details of version code checking, etc. Signed-off-by: Darrick J. Wong --- misc/mke2fs.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 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/mke2fs.c b/misc/mke2fs.c index c1cbcaa..a76ebe6 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -27,6 +27,7 @@ #include #ifdef __linux__ #include +#include #endif #ifdef HAVE_GETOPT_H #include @@ -109,7 +110,6 @@ char **fs_types; profile_t profile; int sys_page_size = 4096; -int linux_version_code = 0; static void usage(void) { @@ -168,7 +168,28 @@ static int parse_version_number(const char *s) rev = strtol(cp, &endptr, 10); if (cp == endptr) return 0; - return ((((major * 256) + minor) * 256) + rev); + return KERNEL_VERSION(major, minor, rev); +} + +static int is_before_linux_ver(unsigned int major, unsigned int minor) +{ + struct utsname ut; + int linux_version_code = 0; + + if (uname(&ut)) { + perror("uname"); + exit(1); + } + linux_version_code = parse_version_number(ut.release); + if (linux_version_code == 0) + return 0; + + return linux_version_code < KERNEL_VERSION(major, minor, 0); +} +#else +static int is_before_linux_ver(unsigned int major, unsigned int minor) +{ + return 0; } #endif @@ -1315,9 +1336,6 @@ static void PRS(int argc, char *argv[]) * Finally, we complain about fs_blocks_count > 2^32 on a non-64bit fs. */ blk64_t fs_blocks_count = 0; -#ifdef __linux__ - struct utsname ut; -#endif long sysval; int s_opt = -1, r_opt = -1; char *fs_features = 0; @@ -1382,15 +1400,8 @@ profile_error: memset(&fs_param, 0, sizeof(struct ext2_super_block)); fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */ -#ifdef __linux__ - if (uname(&ut)) { - perror("uname"); - exit(1); - } - linux_version_code = parse_version_number(ut.release); - if (linux_version_code && linux_version_code < (2*65536 + 2*256)) + if (is_before_linux_ver(2, 2)) fs_param.s_rev_level = 0; -#endif if (argc && *argv) { program_name = get_progname(*argv); @@ -1827,8 +1838,7 @@ profile_error: if (use_bsize == -1) { use_bsize = sys_page_size; - if ((linux_version_code < (2*65536 + 6*256)) && - (use_bsize > 4096)) + if (is_before_linux_ver(2, 6) && use_bsize > 4096) use_bsize = 4096; } if (lsector_size && use_bsize < lsector_size)