1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*
* Abstractions between different versions of Linux
* Currently only tested amonst the latest versions of 2.0 and 2.2
* Copyright (C) 2026 Javier S. Pedro
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/version.h>
#define MAKE_VERSION_CODE(vers, rel, seq) ( (vers)<<16 | (rel)<<8 | (seq) )
#include <linux/kernel.h>
#include <linux/module.h>
// Module entry point abstraction
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,36)
#define __init /**/
#define module_init(x) int init_module(void) { return x(); }
#define module_exit(x) void cleanup_module(void) { x(); }
#else
#include <linux/init.h>
#endif
// Module params
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,26)
#define MODULE_PARM(var, type) /**/
#define MODULE_PARM_DESC(var, s) /**/
#define MODULE_DESCRIPTION(s) /**/
#endif
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,4,0)
#define MODULE_LICENSE(s) /**/
#endif
#include <linux/ioport.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/blk.h>
#include <linux/blkdev.h>
#include <linux/hdreg.h>
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
#define invalidate_inodes_dev(devno) invalidate_inodes(devno)
#else
static inline void invalidate_inodes_dev(kdev_t devno) {
struct super_block *sb = get_super(devno);
if (sb) invalidate_inodes(sb);
}
#endif
#include <linux/delay.h>
// time before/after
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,95)
#define time_after(a,b) ((long)(b) - (long)(a) < 0)
#define time_before(a,b) time_after(b,a)
#endif
// mdelay
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
static inline void mdelay(int milliseconds)
{
int i;
for(i=0; i<milliseconds; i++)
udelay(1000);
}
#endif
// put_user/copy_to_user
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
#undef put_user
#undef get_user
#define put_user(x,ptr) ({ \
int i = verify_area(VERIFY_WRITE, (ptr), sizeof(*(ptr))); \
if (i == 0) { __put_user((unsigned long)(x),(ptr),sizeof(*(ptr))); } \
i; \
})
#define get_user(x,ptr) ({ \
int i = verify_area(VERIFY_READ, (ptr), sizeof(*(ptr))); \
if (i == 0) { x = ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr)))); } \
i; \
})
extern inline int copy_from_user(void *to, const void *from, unsigned long n)
{
int i = verify_area(VERIFY_READ, from, n);
if (i)
return i;
memcpy_fromfs(to, from, n);
return 0;
}
extern inline int copy_to_user(void *to, const void *from, unsigned long n)
{
int i = verify_area(VERIFY_WRITE, to, n);
if (i)
return i;
memcpy_tofs(to, from, n);
return 0;
}
#else
#include <asm/uaccess.h>
#endif
// capabilities
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
#define is_sys_admin() suser()
#else
#define is_sys_admin() capable(CAP_SYS_ADMIN)
#endif
// stdtypes
#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
typedef __s8 int8_t;
typedef __s16 int16_t;
typedef __s32 int32_t;
typedef __u8 uint8_t;
typedef __u16 uint16_t;
typedef __u32 uint32_t;
#endif
#include <asm/byteorder.h>
|