Blame SOURCES/e2fsprogs-1.42.9-mke2fs-clean-up-kernel-version-tests.patch

252946
From 604a29de2a70e97264e169957a224412868ca64a Mon Sep 17 00:00:00 2001
252946
From: "Darrick J. Wong" <darrick.wong@oracle.com>
252946
Date: Thu, 6 Feb 2014 15:24:01 -0500
252946
Subject: [PATCH 1/8] mke2fs: clean up kernel version tests
252946
252946
Refactor the running kernel version checks to hide the details of
252946
version code checking, etc.
252946
252946
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
252946
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
252946
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
252946
---
252946
 misc/mke2fs.c | 40 ++++++++++++++++++++++++++--------------
252946
 1 file changed, 26 insertions(+), 14 deletions(-)
252946
252946
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
252946
index 2e8ba60..2afcb05 100644
252946
--- a/misc/mke2fs.c
252946
+++ b/misc/mke2fs.c
252946
@@ -27,6 +27,7 @@
252946
 #include <time.h>
252946
 #ifdef __linux__
252946
 #include <sys/utsname.h>
252946
+#include <linux/version.h>
252946
 #endif
252946
 #ifdef HAVE_GETOPT_H
252946
 #include <getopt.h>
252946
@@ -168,7 +169,29 @@ static int parse_version_number(const char *s)
252946
 	rev = strtol(cp, &endptr, 10);
252946
 	if (cp == endptr)
252946
 		return 0;
252946
-	return ((((major * 256) + minor) * 256) + rev);
252946
+	return KERNEL_VERSION(major, minor, rev);
252946
+}
252946
+
252946
+static int is_before_linux_ver(unsigned int major, unsigned int minor)
252946
+{
252946
+	struct		utsname ut;
252946
+	static int	linux_version_code = -1;
252946
+
252946
+	if (uname(&ut)) {
252946
+		perror("uname");
252946
+		exit(1);
252946
+	}
252946
+	if (linux_version_code < 0)
252946
+		linux_version_code = parse_version_number(ut.release);
252946
+	if (linux_version_code == 0)
252946
+		return 0;
252946
+
252946
+	return linux_version_code < KERNEL_VERSION(major, minor, 0);
252946
+}
252946
+#else
252946
+static int is_before_linux_ver(unsigned int major, unsigned int minor)
252946
+{
252946
+	return 0;
252946
 }
252946
 #endif
252946
 
252946
@@ -1306,9 +1329,6 @@ static void PRS(int argc, char *argv[])
252946
 	 * Finally, we complain about fs_blocks_count > 2^32 on a non-64bit fs.
252946
 	 */
252946
 	blk64_t		fs_blocks_count = 0;
252946
-#ifdef __linux__
252946
-	struct 		utsname ut;
252946
-#endif
252946
 	long		sysval;
252946
 	int		s_opt = -1, r_opt = -1;
252946
 	char		*fs_features = 0;
252946
@@ -1374,15 +1394,8 @@ profile_error:
252946
 	memset(&fs_param, 0, sizeof(struct ext2_super_block));
252946
 	fs_param.s_rev_level = 1;  /* Create revision 1 filesystems now */
252946
 
252946
-#ifdef __linux__
252946
-	if (uname(&ut)) {
252946
-		perror("uname");
252946
-		exit(1);
252946
-	}
252946
-	linux_version_code = parse_version_number(ut.release);
252946
-	if (linux_version_code && linux_version_code < (2*65536 + 2*256))
252946
+	if (is_before_linux_ver(2, 2))
252946
 		fs_param.s_rev_level = 0;
252946
-#endif
252946
 
252946
 	if (argc && *argv) {
252946
 		program_name = get_progname(*argv);
252946
@@ -1790,8 +1803,7 @@ profile_error:
252946
 
252946
 		if (use_bsize == -1) {
252946
 			use_bsize = sys_page_size;
252946
-			if ((linux_version_code < (2*65536 + 6*256)) &&
252946
-			    (use_bsize > 4096))
252946
+			if (is_before_linux_ver(2, 6) && use_bsize > 4096)
252946
 				use_bsize = 4096;
252946
 		}
252946
 		if (lsector_size && use_bsize < lsector_size)
252946
-- 
252946
1.8.3.1
252946