1 | /* $Id: version.h 88975 2021-05-11 11:13:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Linux kernel version.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef IPRT_INCLUDED_linux_version_h
|
---|
28 | #define IPRT_INCLUDED_linux_version_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <linux/version.h>
|
---|
34 |
|
---|
35 | /* We need utsrelease.h in order to detect Ubuntu kernel,
|
---|
36 | * i.e. check if UTS_UBUNTU_RELEASE_ABI is defined. Support kernels
|
---|
37 | * starting from Ubuntu 14.04 Trusty which is based on upstream
|
---|
38 | * kernel 3.13.11. */
|
---|
39 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,11))
|
---|
40 | # include <generated/utsrelease.h>
|
---|
41 | # include <iprt/cdefs.h>
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | /** @def RTLNX_VER_MIN
|
---|
45 | * Evaluates to true if the linux kernel version is equal or higher to the
|
---|
46 | * one specfied. */
|
---|
47 | #define RTLNX_VER_MIN(a_Major, a_Minor, a_Patch) \
|
---|
48 | (LINUX_VERSION_CODE >= KERNEL_VERSION(a_Major, a_Minor, a_Patch))
|
---|
49 |
|
---|
50 | /** @def RTLNX_VER_MAX
|
---|
51 | * Evaluates to true if the linux kernel version is less to the one specfied
|
---|
52 | * (exclusive). */
|
---|
53 | #define RTLNX_VER_MAX(a_Major, a_Minor, a_Patch) \
|
---|
54 | (LINUX_VERSION_CODE < KERNEL_VERSION(a_Major, a_Minor, a_Patch))
|
---|
55 |
|
---|
56 | /** @def RTLNX_VER_RANGE
|
---|
57 | * Evaluates to true if the linux kernel version is equal or higher to the given
|
---|
58 | * minimum version and less (but not equal) to the maximum version (exclusive). */
|
---|
59 | #define RTLNX_VER_RANGE(a_MajorMin, a_MinorMin, a_PatchMin, a_MajorMax, a_MinorMax, a_PatchMax) \
|
---|
60 | ( LINUX_VERSION_CODE >= KERNEL_VERSION(a_MajorMin, a_MinorMin, a_PatchMin) \
|
---|
61 | && LINUX_VERSION_CODE < KERNEL_VERSION(a_MajorMax, a_MinorMax, a_PatchMax) )
|
---|
62 |
|
---|
63 |
|
---|
64 | /** @def RTLNX_RHEL_MIN
|
---|
65 | * Require a minium RedHat release.
|
---|
66 | * @param a_iMajor The major release number (RHEL_MAJOR).
|
---|
67 | * @param a_iMinor The minor release number (RHEL_MINOR).
|
---|
68 | * @sa RTLNX_RHEL_MAX, RTLNX_RHEL_RANGE, RTLNX_RHEL_MAJ_PREREQ
|
---|
69 | */
|
---|
70 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
71 | # define RTLNX_RHEL_MIN(a_iMajor, a_iMinor) \
|
---|
72 | ((RHEL_MAJOR) > (a_iMajor) || ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) >= (a_iMinor)))
|
---|
73 | #else
|
---|
74 | # define RTLNX_RHEL_MIN(a_iMajor, a_iMinor) (0)
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | /** @def RTLNX_RHEL_MAX
|
---|
78 | * Require a maximum RedHat release, true for all RHEL versions below it.
|
---|
79 | * @param a_iMajor The major release number (RHEL_MAJOR).
|
---|
80 | * @param a_iMinor The minor release number (RHEL_MINOR).
|
---|
81 | * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_RANGE, RTLNX_RHEL_MAJ_PREREQ
|
---|
82 | */
|
---|
83 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
84 | # define RTLNX_RHEL_MAX(a_iMajor, a_iMinor) \
|
---|
85 | ((RHEL_MAJOR) < (a_iMajor) || ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) < (a_iMinor)))
|
---|
86 | #else
|
---|
87 | # define RTLNX_RHEL_MAX(a_iMajor, a_iMinor) (0)
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | /** @def RTLNX_RHEL_RANGE
|
---|
91 | * Check that it's a RedHat kernel in the given version range.
|
---|
92 | * The max version is exclusive, the minimum inclusive.
|
---|
93 | * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_MAX, RTLNX_RHEL_MAJ_PREREQ
|
---|
94 | */
|
---|
95 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
96 | # define RTLNX_RHEL_RANGE(a_iMajorMin, a_iMinorMin, a_iMajorMax, a_iMinorMax) \
|
---|
97 | (RTLNX_RHEL_MIN(a_iMajorMin, a_iMinorMin) && RTLNX_RHEL_MAX(a_iMajorMax, a_iMinorMax))
|
---|
98 | #else
|
---|
99 | # define RTLNX_RHEL_RANGE(a_iMajorMin, a_iMinorMin, a_iMajorMax, a_iMinorMax) (0)
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | /** @def RTLNX_RHEL_MAJ_PREREQ
|
---|
103 | * Require a minimum minor release number for the given RedHat release.
|
---|
104 | * @param a_iMajor RHEL_MAJOR must _equal_ this.
|
---|
105 | * @param a_iMinor RHEL_MINOR must be greater or equal to this.
|
---|
106 | * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_MAX
|
---|
107 | */
|
---|
108 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
109 | # define RTLNX_RHEL_MAJ_PREREQ(a_iMajor, a_iMinor) ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) >= (a_iMinor))
|
---|
110 | #else
|
---|
111 | # define RTLNX_RHEL_MAJ_PREREQ(a_iMajor, a_iMinor) (0)
|
---|
112 | #endif
|
---|
113 |
|
---|
114 |
|
---|
115 | /** @def RTLNX_SUSE_MAJ_PREREQ
|
---|
116 | * Require a minimum minor release number for the given SUSE release.
|
---|
117 | * @param a_iMajor CONFIG_SUSE_VERSION must _equal_ this.
|
---|
118 | * @param a_iMinor CONFIG_SUSE_PATCHLEVEL must be greater or equal to this.
|
---|
119 | */
|
---|
120 | #if defined(CONFIG_SUSE_VERSION) && defined(CONFIG_SUSE_PATCHLEVEL)
|
---|
121 | # define RTLNX_SUSE_MAJ_PREREQ(a_iMajor, a_iMinor) ((CONFIG_SUSE_VERSION) == (a_iMajor) && (CONFIG_SUSE_PATCHLEVEL) >= (a_iMinor))
|
---|
122 | #else
|
---|
123 | # define RTLNX_SUSE_MAJ_PREREQ(a_iMajor, a_iMinor) (0)
|
---|
124 | #endif
|
---|
125 |
|
---|
126 |
|
---|
127 | #if defined(UTS_UBUNTU_RELEASE_ABI)
|
---|
128 | /** @def RTLNX_UBUNTU_VERSION
|
---|
129 | * Ubuntu kernels are based on upstream kernels and provide
|
---|
130 | * version information with regular KERNEL_VERSION() macro. However,
|
---|
131 | * Ubuntu kernel additionally provides UTS_UBUNTU_RELEASE_ABI macro
|
---|
132 | * which increases with the kernel update while KERNEL_VERSION() info
|
---|
133 | * stays the same.
|
---|
134 | *
|
---|
135 | * UTS_UBUNTU_RELEASE_ABI does not increase constantly, but rather reset
|
---|
136 | * when the next kernel update is based on a newer upstream version (i.e.
|
---|
137 | * KERNEL_VERSION() value has changed). Therefore, in order to compare
|
---|
138 | * Ubuntu kernels, UTS_UBUNTU_RELEASE_ABI macro is treated as a KERNEL_VERSION()
|
---|
139 | * extension and appended to the end of it. So, regular 24-bit-value
|
---|
140 | * of KERNEL_VERSION() becomes 32-bit-value, as can be seen below.
|
---|
141 | *
|
---|
142 | * NOTE: @a_iVer is expected to be in range of [0x000000..0xFFFFFF],
|
---|
143 | * @a_iAbi is expected to be in range of [0x00..0xFF].
|
---|
144 | *
|
---|
145 | * @param a_iVer The 24-bit-value of kernel version number, result
|
---|
146 | * of KERNEL_VERSION() macro.
|
---|
147 | * @param a_iAbi 8-bit Ubuntu kernel ABI version number.
|
---|
148 | */
|
---|
149 | # define RTLNX_UBUNTU_VERSION(a_iVer, a_iAbi) \
|
---|
150 | (((a_iVer) << 8) | (RT_MIN((a_iAbi), 0xFF)))
|
---|
151 |
|
---|
152 | /** @def RTLNX_UBUNTU_MIN
|
---|
153 | * Require Ubuntu release to be equal or newer than specified version.
|
---|
154 | * @param a_iMajor The major kernel version number.
|
---|
155 | * @param a_iMinor The minor kernel version number.
|
---|
156 | * @param a_iPatch The micro kernel version number.
|
---|
157 | * @param a_iAbi Ubuntu kernel ABI version number.
|
---|
158 | */
|
---|
159 | # define RTLNX_UBUNTU_MIN(a_iMajor, a_iMinor, a_iPatch, a_iAbi) \
|
---|
160 | ( RTLNX_UBUNTU_VERSION(LINUX_VERSION_CODE, UTS_UBUNTU_RELEASE_ABI) \
|
---|
161 | >= RTLNX_UBUNTU_VERSION(KERNEL_VERSION(a_iMajor, a_iMinor, a_iPatch), a_iAbi) )
|
---|
162 |
|
---|
163 | /** @def RTLNX_UBUNTU_MAX
|
---|
164 | * Require Ubuntu release to be older than specified version.
|
---|
165 | * @param a_iMajor The major kernel version number.
|
---|
166 | * @param a_iMinor The minor kernel version number.
|
---|
167 | * @param a_iPatch The micro kernel version number.
|
---|
168 | * @param a_iAbi Ubuntu kernel ABI version number.
|
---|
169 | */
|
---|
170 | # define RTLNX_UBUNTU_MAX(a_iMajor, a_iMinor, a_iPatch, a_iAbi) \
|
---|
171 | ( RTLNX_UBUNTU_VERSION(LINUX_VERSION_CODE, UTS_UBUNTU_RELEASE_ABI) \
|
---|
172 | < RTLNX_UBUNTU_VERSION(KERNEL_VERSION(a_iMajor, a_iMinor, a_iPatch), a_iAbi) )
|
---|
173 |
|
---|
174 | /** @def RTLNX_UBUNTU_RANGE
|
---|
175 | * Require Ubuntu release to be in specified versions range.
|
---|
176 | * The max version is exclusive, the minimum inclusive.
|
---|
177 | *
|
---|
178 | * @param a_iMajorMin The major kernel version number (minimum).
|
---|
179 | * @param a_iMinorMin The minor kernel version number (minimum).
|
---|
180 | * @param a_iPatchMin The micro kernel version number (minimum).
|
---|
181 | * @param a_iAbiMin Ubuntu kernel ABI version number (minimum).
|
---|
182 | * @param a_iMajorMax The major kernel version number (maximum).
|
---|
183 | * @param a_iMinorMax The minor kernel version number (maximum).
|
---|
184 | * @param a_iPatchMax The micro kernel version number (maximum).
|
---|
185 | * @param a_iAbiMax Ubuntu kernel ABI version number (maximum).
|
---|
186 | */
|
---|
187 | # define RTLNX_UBUNTU_RANGE(a_iMajorMin, a_iMinorMin, a_iPatchMin, a_iAbiMin, \
|
---|
188 | a_iMajorMax, a_iMinorMax, a_iPatchMax, a_iAbiMax) \
|
---|
189 | ( RTLNX_UBUNTU_MIN(a_iMajorMin, a_iMinorMin, a_iPatchMin, a_iAbiMin) \
|
---|
190 | && RTLNX_UBUNTU_MAX(a_iMajorMax, a_iMinorMax, a_iPatchMax, a_iAbiMax))
|
---|
191 |
|
---|
192 | #else /* !UTS_UBUNTU_RELEASE_ABI */
|
---|
193 | # define RTLNX_UBUNTU_MIN(a_iMajor, a_iMinor, a_iPatch, a_iAbi) (0)
|
---|
194 | # define RTLNX_UBUNTU_MAX(a_iMajor, a_iMinor, a_iPatch, a_iAbi) (0)
|
---|
195 | #define RTLNX_UBUNTU_RANGE(a_iMajorMin, a_iMinorMin, a_iPatchMin, a_iAbiMin, \
|
---|
196 | a_iMajorMax, a_iMinorMax, a_iPatchMax, a_iAbiMax) (0)
|
---|
197 | #endif /* !UTS_UBUNTU_RELEASE_ABI */
|
---|
198 |
|
---|
199 | #endif /* !IPRT_INCLUDED_linux_version_h */
|
---|
200 |
|
---|