]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/mount/version.h
nfsidmap: Added Error Logging
[nfs-utils.git] / utils / mount / version.h
1 /*
2  * version.h -- get running kernel version
3  *
4  * Copyright (C) 2008 Oracle.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 0211-1301 USA
20  *
21  */
22
23 #ifndef _NFS_UTILS_MOUNT_VERSION_H
24 #define _NFS_UTILS_MOUNT_VERSION_H
25
26 #include <stdio.h>
27 #include <limits.h>
28
29 #include <sys/utsname.h>
30
31 static inline unsigned int MAKE_VERSION(unsigned int p, unsigned int q,
32                                         unsigned int r)
33 {
34         return (65536 * p) + (256 * q) + r;
35 }
36
37 static inline unsigned int linux_version_code(void)
38 {
39         struct utsname my_utsname;
40         unsigned int p, q = 0, r = 0;
41
42         /* UINT_MAX as backward compatibility code should not be run */
43         if (uname(&my_utsname))
44                 return UINT_MAX;
45
46         /* UINT_MAX as future versions might not start with an integer */
47         if (sscanf(my_utsname.release, "%u.%u.%u", &p, &q, &r) < 1)
48                 return UINT_MAX;
49         
50         return MAKE_VERSION(p, q, r);
51 }
52
53 #endif  /* _NFS_UTILS_MOUNT_VERSION_H */