Linux version code include

[KERNEL] Где определена LINUX_VERSION_CODE ?

Доброе утро.
Собственно сабж.
Где определена LINUX_VERSION_CODE?

[ megabaks@desktop ] ~ $ grep -RH "LINUX_VERSION_CODE" /usr/src/linux /usr/src/linux/arch/sh/kernel/vsyscall/vsyscall-note.S: .long LINUX_VERSION_CODE /usr/src/linux/arch/arm/include/asm/stackprotector.h: canary ^= LINUX_VERSION_CODE; /usr/src/linux/arch/x86/vdso/vdso-note.S: .long LINUX_VERSION_CODE /usr/src/linux/arch/x86/vdso/vdso32/note.S: .long LINUX_VERSION_CODE /usr/src/linux/arch/s390/kernel/vdso32/note.S: .long LINUX_VERSION_CODE /usr/src/linux/arch/s390/kernel/vdso64/note.S: .long LINUX_VERSION_CODE /usr/src/linux/arch/sparc/boot/piggyback.c: /* skip HdrS + LINUX_VERSION_CODE + HdrS version */ /usr/src/linux/arch/sparc/kernel/head_32.S: .word LINUX_VERSION_CODE /usr/src/linux/arch/sparc/kernel/head_64.S: .word LINUX_VERSION_CODE /usr/src/linux/arch/powerpc/kernel/vdso32/note.S: .long LINUX_VERSION_CODE /usr/src/linux/init/version.c:extern int version_string(LINUX_VERSION_CODE); /usr/src/linux/init/version.c:int version_string(LINUX_VERSION_CODE); /usr/src/linux/Makefile: (echo \#define LINUX_VERSION_CODE $(shell \ /usr/src/linux/scripts/checkpatch.pl: if ($line =~ /\bLINUX_VERSION_CODE\b/) < /usr/src/linux/scripts/checkpatch.pl: WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); /usr/src/linux/scripts/checkversion.pl:# checkversion find uses of LINUX_VERSION_CODE or KERNEL_VERSION /usr/src/linux/scripts/checkversion.pl: # Look for uses: LINUX_VERSION_CODE, KERNEL_VERSION, UTS_RELEASE /usr/src/linux/scripts/checkversion.pl: if (($_ =~ /LINUX_VERSION_CODE/) || ($_ =~ /\WKERNEL_VERSION/)) < /usr/src/linux/drivers/net/wan/farsync.c: info->kernelVersion = LINUX_VERSION_CODE; /usr/src/linux/drivers/usb/core/hcd.c:#define KERNEL_REL ((LINUX_VERSION_CODE >> 16) & 0x0ff) /usr/src/linux/drivers/usb/core/hcd.c:#define KERNEL_VER ((LINUX_VERSION_CODE >> 8) & 0x0ff) /usr/src/linux/drivers/s390/char/sclp_cpi.c: LINUX_VERSION_CODE); /usr/src/linux/drivers/scsi/gdth.c: osv.version = (u8)(LINUX_VERSION_CODE >> 16); /usr/src/linux/drivers/scsi/gdth.c: osv.subversion = (u8)(LINUX_VERSION_CODE >> 8); /usr/src/linux/drivers/scsi/gdth.c: osv.revision = (u16)(LINUX_VERSION_CODE & 0xff); /usr/src/linux/drivers/staging/rtl8192e/ieee80211/ieee80211_wx.c:#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13)) /usr/src/linux/kernel/power/snapshot.c: info->version_code = LINUX_VERSION_CODE; /usr/src/linux/kernel/power/snapshot.c: if (info->version_code != LINUX_VERSION_CODE) /usr/src/linux/Documentation/scsi/ChangeLog.lpfc: * Moved #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,6) to include /usr/src/linux/Documentation/bus-virt-phys-mapping.txt: #if LINUX_VERSION_CODE < 0x020100 /usr/src/linux/include/linux/version.h:#define LINUX_VERSION_CODE 196609 [ megabaks@desktop ] ~ $ 

Чем мне заменить такую конструкцию?

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9) /* Подключение файлов для ядра 2.6.9 */ #endif 

Источник

LINUX_VERSION_CODE where the value from?

I just make a mistake about the macro LINUX_VERSION_CODE. Here is what I want to do,when execute the code,the code run different branch due to the machine ,which is running. I just realized,the result is not change,since I compile my code always in the same server.For example I compile the belw code in kernel version of 2.6.18,then the LINUX_VERSION_CODE marco is always 132626 . If there is any way ,let the run different branch due to the version of which it runs?

Читайте также:  Бэкап системы linux tar

What happens? Can you paraphrase that, I don't understand you at all. You have 4 machines with different operating systems installed - centos5.5, redhat5.5, centos7.0 and centos6.5. On the first three of them, that is cnetos5.5, redhat5.5 and centos7.0 the value of the macro defined in linux/version.h named "LINUX_VERSION_CODE" is the same (in comparison to each other). On the machine centos6.5 the macro is different. Can you post the source of llinux/version.h on your centos6.5 machine ? Did I understood you correctly?

The simplest answer would be: the linux headers installed on your machine do not match the kernel version installed. Reinstall them then. As to your question : the value of LINUX_VERSION_CODE comes from /usr/include/linux/version.h as a standard location.

1 Answer 1

So you want to run a different code depending on kernel version. But you don't want to decide on that using a compile time constant - you want that at runtime.
Nothing simpler, but a call to uname:

#include #include #include #include int main() < struct utsname name; if (uname(&name)) < fprintf(stderr, "Uname failed!\n"); exit(-1); >printf("%s\n", name.release); if (!memcmp(&name.release, "4.18.9-", sizeof("4.18.9-") - 1)) < printf("Och, kernel 4.18.9 found!\n"); >else < printf("Och, you've got a different kernel. \n"); >> 
$ cat 1.c | gcc -xc - && ./a.out 4.18.9-arch1-1-ARCH Och, kernel 4.18.9 found! 
cat 1.c | ssh friend 'gcc -xc - && ./a.out' 4.12.14-lp150.11-default Och, you've got a different kernel. 

I will leave it to the OP, to call strtoll or sscanf(&name.release, "%d.%d.%d-", &major, &minor, &release) to get the kernel version as integer number.

But you can get way more hardcore than that. On runtime, you can just do anything, so just read the content of /usr/include/linux/version.h file:

#define _GNU_SOURCE 1 #include #include #include #include #include #include int main() < FILE *f; f = fopen("/usr/include/linux/version.h", "r"); if (f == NULL) return -__LINE__; char *line = NULL; size_t linelen = 0; char *found = NULL; while (getline(&line, &linelen, f) >0) < if ((found = strstr(line, "LINUX_VERSION_CODE")) != NULL) < break; >> if (found == NULL) return -__LINE__; fclose(f); found += sizeof("LINUX_VERSION_CODE") - 1; errno = 0; const long long kv = strtoll(found, NULL, 10); if (errno) return -__LINE__; free(line); printf("%ld.%ld.%ld\n", kv>>16&0xff, kv>>8&0xff, kv&0xff); if (kv > KERNEL_VERSION(4,17,0)) < printf("Och, kernel api greater then 4.17.0 found!\n"); >else < printf("Och, kernel api below 4.17.0 found!\n"); >> 

And on my machine this outputs:

$ cat 1.c | gcc -xc - && ./a.out 4.17.11 Och, kernel api greater then 4.17.0 found! 
$ cat 1.c | ssh friend 'gcc -xc - && ./a.out' 4.15.0 Och, kernel api below 4.17.0 found! 

We can also see, that uname -a != grep "LINUX_VERSION_CODE" /usr/include/linux/version.h .

Читайте также:  Linux boot to ram

Источник

Help locating linux/version.h

I already have the headers installed, so created the ln But it produces another error /lib/modules/3.8.0-29-generic/build/include/uapi/linux/types.h:4:23: fatal error: asm/types.h: No such file or directory I find it very odd, why would there be an error in /lib/modules/3.8.0-29-generic/build/include/uapi/linux/types.h it being a part of the linux header

@AshiqIrphan types.h file's directory is changed. It's now in include/uapi/asm-generic/. To fix your error follow the edited section

With apt-file you can find any file Ubuntu provides:

$ apt-file search linux/version.h gcc-arm-linux-androideabi: /usr/arm-linux-androideabi/include/linux/version.h linux-headers-3.11.0-11-lowlatency: /usr/src/linux-headers-3.11.0-11-lowlatency/include/generated/uapi/linux/version.h linux-headers-3.11.0-12-generic: /usr/src/linux-headers-3.11.0-12-generic/include/generated/uapi/linux/version.h linux-headers-3.4.0-1-goldfish: /usr/src/linux-headers-3.4.0-1-goldfish/include/linux/version.h linux-libc-dev: /usr/include/linux/version.h linux-libc-dev-arm64-cross: /usr/aarch64-linux-gnu/include/linux/version.h linux-libc-dev-armel-cross: /usr/arm-linux-gnueabi/include/linux/version.h linux-libc-dev-armhf-cross: /usr/arm-linux-gnueabihf/include/linux/version.h linux-libc-dev-powerpc-cross: /usr/powerpc-linux-gnu/include/linux/version.h ruby1.8-dev: /usr/lib/ruby/1.8/i686-linux/version.h 

From this list, linux-libc-dev looks like the most promising candidate.

Источник

Оцените статью
Adblock
detector