diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2010-09-07 11:25:30 -0700 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2010-09-08 11:02:28 -0700 |
commit | 3cab31db10dd74aa148ad20aaa3455723bf45138 (patch) | |
tree | 35452a78331a34c3487596c50b29b3901727ee41 /kexec | |
parent | ebeb4da62f8b51c63a46349b219a5605ee8d79bd (diff) |
kexec: Move kernel_version into the kexec core
I'm not pleased with the hacks that we use kernel_version
for but kernel_version itself is reasonable code and might
be needed elsewhere, so move kernel_version into the kexec
core.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Diffstat (limited to 'kexec')
-rw-r--r-- | kexec/Makefile | 1 | ||||
-rw-r--r-- | kexec/arch/x86_64/arch_init.c | 55 | ||||
-rw-r--r-- | kexec/kernel_version.c | 58 | ||||
-rw-r--r-- | kexec/kexec.h | 4 |
4 files changed, 64 insertions, 54 deletions
diff --git a/kexec/Makefile b/kexec/Makefile index 23385fc..5d7b618 100644 --- a/kexec/Makefile +++ b/kexec/Makefile @@ -22,6 +22,7 @@ KEXEC_SRCS += kexec/firmware_memmap.c KEXEC_SRCS += kexec/crashdump.c KEXEC_SRCS += kexec/crashdump-xen.c KEXEC_SRCS += kexec/phys_arch.c +KEXEC_SRCS += kexec/kernel_version.c KEXEC_SRCS += kexec/lzma.c KEXEC_SRCS += kexec/zlib.c diff --git a/kexec/arch/x86_64/arch_init.c b/kexec/arch/x86_64/arch_init.c index 79fb642..4cffbf6 100644 --- a/kexec/arch/x86_64/arch_init.c +++ b/kexec/arch/x86_64/arch_init.c @@ -1,3 +1,4 @@ +#include "../../kexec.h" #include <errno.h> #include <string.h> #include <sys/utsname.h> @@ -7,60 +8,6 @@ #include "crashdump-x86_64.h" -#define KERNEL_VERSION(major, minor, patch) \ - (((major) << 16) | ((minor) << 8) | patch) - -long kernel_version(void) -{ - struct utsname utsname; - unsigned long major, minor, patch; - char *p; - - if (uname(&utsname) < 0) { - fprintf(stderr, "uname failed: %s\n", strerror(errno)); - return -1; - } - - p = utsname.release; - major = strtoul(p, &p, 10); - if (major == ULONG_MAX) { - fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); - return -1; - } - - if (*p++ != '.') { - fprintf(stderr, "Unsupported utsname.release: %s\n", - utsname.release); - return -1; - } - - minor = strtoul(p, &p, 10); - if (major == ULONG_MAX) { - fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); - return -1; - } - - if (*p++ != '.') { - fprintf(stderr, "Unsupported utsname.release: %s\n", - utsname.release); - return -1; - } - - patch = strtoul(p, &p, 10); - if (major == ULONG_MAX) { - fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); - return -1; - } - - if (major >= 256 || minor >= 256 || patch >= 256) { - fprintf(stderr, "Unsupported utsname.release: %s\n", - utsname.release); - return -1; - } - - return KERNEL_VERSION(major, minor, patch); -} - #define PAGE_OFFSET_PRE_2_6_27 0xffff810000000000UL #define PAGE_OFFSET 0xffff880000000000UL diff --git a/kexec/kernel_version.c b/kexec/kernel_version.c new file mode 100644 index 0000000..079312b --- /dev/null +++ b/kexec/kernel_version.c @@ -0,0 +1,58 @@ +#include "kexec.h" +#include <errno.h> +#include <string.h> +#include <sys/utsname.h> +#include <string.h> +#include <limits.h> +#include <stdlib.h> + +long kernel_version(void) +{ + struct utsname utsname; + unsigned long major, minor, patch; + char *p; + + if (uname(&utsname) < 0) { + fprintf(stderr, "uname failed: %s\n", strerror(errno)); + return -1; + } + + p = utsname.release; + major = strtoul(p, &p, 10); + if (major == ULONG_MAX) { + fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); + return -1; + } + + if (*p++ != '.') { + fprintf(stderr, "Unsupported utsname.release: %s\n", + utsname.release); + return -1; + } + + minor = strtoul(p, &p, 10); + if (major == ULONG_MAX) { + fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); + return -1; + } + + if (*p++ != '.') { + fprintf(stderr, "Unsupported utsname.release: %s\n", + utsname.release); + return -1; + } + + patch = strtoul(p, &p, 10); + if (major == ULONG_MAX) { + fprintf(stderr, "strtoul failed: %s\n", strerror(errno)); + return -1; + } + + if (major >= 256 || minor >= 256 || patch >= 256) { + fprintf(stderr, "Unsupported utsname.release: %s\n", + utsname.release); + return -1; + } + + return KERNEL_VERSION(major, minor, patch); +} diff --git a/kexec/kexec.h b/kexec/kexec.h index 4d22017..6909ca1 100644 --- a/kexec/kexec.h +++ b/kexec/kexec.h @@ -135,6 +135,10 @@ struct arch_map_entry { extern const struct arch_map_entry arches[]; long physical_arch(void); +#define KERNEL_VERSION(major, minor, patch) \ + (((major) << 16) | ((minor) << 8) | patch) +long kernel_version(void); + void usage(void); int get_memory_ranges(struct memory_range **range, int *ranges, unsigned long kexec_flags); |