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