[PATCH] standardize on KERNEL_VERSION(a,b,c) test
Robert P. J. Day
rpjday at mindspring.com
Thu Mar 30 12:51:04 UTC 2006
NOTE: i'm a bit iffy on some of the tests shown below. for
instance, the test in mke2fs.c seems reasonable:
if (linux_version_code && linux_version_code < KERNEL_VERSION(2,2,0))
but the one in rmmod.c is a little curious:
if (get_kernel_revision() <= KERNEL_VERSION(2,6,0))
^^
"<="?? that is, 2.6.0 and below should be treated differently from
2.6.1 and above? could that be a typo that should read just "<"?
perhaps all of the tests should be double-checked, just to play it
safe.
also, interface.c contains the following test:
if (get_kernel_revision() < KERNEL_VERSION(2, 1, 0))
i've mentioned this before -- should busybox be testing for versions
that correspond to experimental kernel releases? why is this testing
against kernel 2.1.0? just curious.
diff -pru busybox.orig/e2fsprogs/mke2fs.c busybox/e2fsprogs/mke2fs.c
--- busybox.orig/e2fsprogs/mke2fs.c 2006-03-29 07:43:43.000000000 -0500
+++ busybox/e2fsprogs/mke2fs.c 2006-03-30 07:30:30.000000000 -0500
@@ -33,6 +33,7 @@
#include "e2p/e2p.h"
#include "ext2fs/ext2fs.h"
#include "util.h"
+#include "platform.h"
#define STRIDE_LENGTH 8
@@ -834,7 +835,7 @@ static int PRS(int argc, char *argv[])
#ifdef __linux__
linux_version_code = get_kernel_revision();
- if (linux_version_code && linux_version_code < (2*65536 + 2*256)) {
+ if (linux_version_code && linux_version_code < KERNEL_VERSION(2,2,0)) {
param.s_rev_level = 0;
param.s_feature_incompat = 0;
param.s_feature_compat = 0;
diff -pru busybox.orig/include/platform.h busybox/include/platform.h
--- busybox.orig/include/platform.h 2006-03-30 07:02:06.000000000 -0500
+++ busybox/include/platform.h 2006-03-30 07:17:18.000000000 -0500
@@ -108,4 +108,6 @@
#define _(Text) Text
#define N_(Text) (Text)
+#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
+
#endif /* platform.h */
diff -pru busybox.orig/modutils/rmmod.c busybox/modutils/rmmod.c
--- busybox.orig/modutils/rmmod.c 2006-03-29 07:43:27.000000000 -0500
+++ busybox/modutils/rmmod.c 2006-03-30 07:31:08.000000000 -0500
@@ -30,6 +30,7 @@
#include <sys/utsname.h>
#include <sys/syscall.h>
#include "busybox.h"
+#include "platform.h"
#ifdef CONFIG_FEATURE_2_6_MODULES
static inline void filename2modname(char *modname, const char *afterslash)
@@ -38,7 +39,7 @@ static inline void filename2modname(char
#if ENABLE_FEATURE_2_4_MODULES
int kr_chk = 1;
- if (get_kernel_revision() <= 2*65536+6*256)
+ if (get_kernel_revision() <= KERNEL_VERSION(2,6,0))
kr_chk = 0;
#else
#define kr_chk 1
diff -pru busybox.orig/networking/interface.c busybox/networking/interface.c
--- busybox.orig/networking/interface.c 2006-03-30 06:46:02.000000000 -0500
+++ busybox/networking/interface.c 2006-03-30 07:32:13.000000000 -0500
@@ -74,6 +74,7 @@
#include <net/if.h>
#include <net/if_arp.h>
#include "libbb.h"
+#include "platform.h"
#ifdef CONFIG_FEATURE_IPV6
# define HAVE_AFINET6 1
@@ -845,7 +846,7 @@ static int sockets_open(int family)
if (force < 0) {
force = 0;
- if (get_kernel_revision() < KRELEASE(2, 1, 0))
+ if (get_kernel_revision() < KERNEL_VERSION(2, 1, 0))
force = 1;
if (access("/proc/net", R_OK))
force = 1;
diff -pru busybox.orig/util-linux/mkswap.c busybox/util-linux/mkswap.c
--- busybox.orig/util-linux/mkswap.c 2006-03-29 15:21:02.000000000 -0500
+++ busybox/util-linux/mkswap.c 2006-03-30 07:33:17.000000000 -0500
@@ -45,6 +45,7 @@
#include <asm/page.h> /* for PAGE_SIZE and PAGE_SHIFT */
/* we also get PAGE_SIZE via getpagesize() */
#include "busybox.h"
+#include "platform.h"
#ifndef _IO
/* pre-1.3.45 */
@@ -61,13 +62,13 @@ static int check = 0;
static int badpages = 0;
#if ENABLE_FEATURE_MKSWAP_V0
static int version = -1;
-#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r))
#else
#define version 1
/* and make sure that we optimize away anything which would deal with checking
* the kernel revision as we have v1 support only anyway.
*/
-#define MAKE_VERSION(p,q,r) 1
+#undef KERNEL_VERSION
+#define KERNEL_VERSION(p,q,r) 1
#define get_kernel_revision() 1
#endif
@@ -294,7 +295,7 @@ int mkswap_main(int argc, char **argv)
if (sz & 4) {
version = bb_xgetlarg(tmp, 10, 0, 1);
} else {
- if (get_kernel_revision() < MAKE_VERSION(2, 1, 117))
+ if (get_kernel_revision() < KERNEL_VERSION(2, 1, 117))
version = 0;
else
version = 1;
@@ -328,7 +329,7 @@ int mkswap_main(int argc, char **argv)
#else
if (!version)
maxpages = V0_MAX_PAGES;
- else if (get_kernel_revision() >= MAKE_VERSION(2, 2, 1))
+ else if (get_kernel_revision() >= KERNEL_VERSION(2, 2, 1))
maxpages = V1_MAX_PAGES;
else {
maxpages = V1_OLD_MAX_PAGES;
diff -pru busybox.orig/util-linux/nfsmount.c busybox/util-linux/nfsmount.c
--- busybox.orig/util-linux/nfsmount.c 2006-03-29 07:43:53.000000000 -0500
+++ busybox/util-linux/nfsmount.c 2006-03-30 07:34:20.000000000 -0500
@@ -45,6 +45,7 @@
#include <arpa/inet.h>
#include <stdlib.h>
#include "busybox.h"
+#include "platform.h"
#undef TRUE
#undef FALSE
#include <rpc/rpc.h>
@@ -214,7 +215,6 @@ enum {
static char *nfs_strerror(int status);
-#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r))
#define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2)
enum {
@@ -251,11 +251,11 @@ find_kernel_nfs_mount_version(void)
kernel_version = get_kernel_revision();
if (kernel_version) {
- if (kernel_version < MAKE_VERSION(2,1,32))
+ if (kernel_version < KERNEL_VERSION(2,1,32))
nfs_mount_version = 1;
- else if (kernel_version < MAKE_VERSION(2,2,18) ||
- (kernel_version >= MAKE_VERSION(2,3,0) &&
- kernel_version < MAKE_VERSION(2,3,99)))
+ else if (kernel_version < KERNEL_VERSION(2,2,18) ||
+ (kernel_version >= KERNEL_VERSION(2,3,0) &&
+ kernel_version < KERNEL_VERSION(2,3,99)))
nfs_mount_version = 3;
else
nfs_mount_version = 4; /* since 2.3.99pre4 */
Signed off by: Robert P. J. Day <rpjday at mindspring.com>
More information about the busybox
mailing list