From 8505ff35cfc77f5f38aa0357c313aca99f0bda92 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 7 Nov 2007 21:25:48 +0100 Subject: [PATCH] elvtune: use get_linux_version() Signed-off-by: Karel Zak --- disk-utils/Makefile.am | 1 + disk-utils/elvtune.c | 27 ++++----------------------- include/blkdev.h | 1 + 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/disk-utils/Makefile.am b/disk-utils/Makefile.am index 9ee98574..397d8efb 100644 --- a/disk-utils/Makefile.am +++ b/disk-utils/Makefile.am @@ -15,6 +15,7 @@ usrbinexec_PROGRAMS = fdformat isosize if BUILD_ELVTUNE sbin_PROGRAMS += elvtune man_MANS += elvtune.8 +elvtune_SOURCES = elvtune.c ../lib/linux_version.c endif if HAVE_RAW diff --git a/disk-utils/elvtune.c b/disk-utils/elvtune.c index dc264658..fc7550ba 100644 --- a/disk-utils/elvtune.c +++ b/disk-utils/elvtune.c @@ -30,6 +30,8 @@ #include #include #include "nls.h" +#include "blkdev.h" +#include "linux_version.h" /* this has to match with the kernel structure */ /* current version for ac19 and 2.2.16 */ @@ -40,10 +42,6 @@ typedef struct blkelv_ioctl_arg_s { int max_bomb_segments; } blkelv_ioctl_arg_t; -/* ioctls introduced in 2.2.16, removed in 2.5.58 */ -#define BLKELVGET _IOR(0x12,106,size_t) -#define BLKELVSET _IOW(0x12,107,size_t) - static void usage(void) { fprintf(stderr, "elvtune (%s)\n", PACKAGE_STRING); @@ -61,23 +59,6 @@ version(void) { fprintf(stderr, "elvtune (%s)\n", PACKAGE_STRING); } -#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) - -static int -linux_version_code(void) { - struct utsname my_utsname; - int p, q, r; - - if (uname(&my_utsname) == 0) { - p = atoi(strtok(my_utsname.release, ".")); - q = atoi(strtok(NULL, ".")); - r = atoi(strtok(NULL, ".")); - return MAKE_VERSION(p,q,r); - } - return 0; -} - - int main(int argc, char * argv[]) { int read_value = 0xbeefbeef, write_value = 0xbeefbeef, bomb_value = 0xbeefbeef; @@ -123,7 +104,7 @@ main(int argc, char * argv[]) { if (optind >= argc) fprintf(stderr, "missing blockdevice, use -h for help\n"), exit(1); - + while (optind < argc) { devname = argv[optind++]; @@ -141,7 +122,7 @@ main(int argc, char * argv[]) { int errsv = errno; perror("ioctl get"); if ((errsv == EINVAL || errsv == ENOTTY) && - linux_version_code() >= MAKE_VERSION(2,5,58)) { + get_linux_version() >= KERNEL_VERSION(2,5,58)) { fprintf(stderr, "\nelvtune is only useful on older " "kernels;\nfor 2.6 use IO scheduler " diff --git a/include/blkdev.h b/include/blkdev.h index 8065acc1..1f0fe674 100644 --- a/include/blkdev.h +++ b/include/blkdev.h @@ -21,6 +21,7 @@ #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ +/* ioctls introduced in 2.2.16, removed in 2.5.58 */ #define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */ #define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */ -- 2.39.5