Improve the compatibility with kernel version < 5.6

This commit is contained in:
Jim Huang 2021-07-22 07:17:31 +08:00
parent 50b8dfe6c2
commit 64f791f274
8 changed files with 74 additions and 13 deletions

View File

@ -3,9 +3,6 @@
* you've read from the dev file
*/
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/device.h>

View File

@ -2,9 +2,6 @@
* chardev2.c - Create an input/output character device
*/
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/device.h>

View File

@ -2,7 +2,6 @@
* kbleds.c - Blink keyboard leds until the module is unloaded.
*/
#include <linux/console_struct.h> /* For vc_cons */
#include <linux/init.h>
#include <linux/kd.h> /* For KDSETLED */
#include <linux/module.h>
@ -10,6 +9,8 @@
#include <linux/vt.h>
#include <linux/vt_kern.h> /* for fg_console */
#include <linux/console_struct.h> /* For vc_cons */
MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs.");
MODULE_AUTHOR("Daniele Paolo Scarpazza");
MODULE_LICENSE("GPL");

View File

@ -6,6 +6,11 @@
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
#define HAVE_PROC_OPS
#endif
#define procfs_name "helloworld"
@ -26,9 +31,15 @@ ssize_t procfile_read(struct file *filePointer,
return ret;
}
#ifdef HAVE_PROC_OPS
static const struct proc_ops proc_file_fops = {
.proc_read = procfile_read,
};
#else
static const struct file_operations proc_file_fops = {
.read = procfile_read,
};
#endif
int init_module()
{

View File

@ -7,6 +7,11 @@
#include <linux/module.h> /* Specifically, a module */
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
#include <linux/uaccess.h> /* for copy_from_user */
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
#define HAVE_PROC_OPS
#endif
#define PROCFS_MAX_SIZE 1024
#define PROCFS_NAME "buffer1k"
@ -68,10 +73,17 @@ static ssize_t procfile_write(struct file *file,
return procfs_buffer_size;
}
#ifdef HAVE_PROC_OPS
static const struct proc_ops proc_file_fops = {
.proc_read = procfile_read,
.proc_write = procfile_write,
};
#else
static const struct file_operations proc_file_fops = {
.read = procfile_read,
.write = procfile_write,
};
#endif
/**
*This function is called when the module is loaded

View File

@ -7,6 +7,11 @@
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/uaccess.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
#define HAVE_PROC_OPS
#endif
#define PROCFS_MAX_SIZE 2048
#define PROCFS_ENTRY_FILENAME "buffer2k"
@ -57,12 +62,21 @@ int procfs_close(struct inode *inode, struct file *file)
return 0;
}
#ifdef HAVE_PROC_OPS
static struct proc_ops File_Ops_4_Our_Proc_File = {
.proc_read = procfs_read,
.proc_write = procfs_write,
.proc_open = procfs_open,
.proc_release = procfs_close,
};
#else
static const struct file_operations File_Ops_4_Our_Proc_File = {
.read = procfs_read,
.write = procfs_write,
.open = procfs_open,
.release = procfs_close,
};
#endif
int init_module()
{

View File

@ -8,6 +8,11 @@
#include <linux/module.h> /* Specifically, a module */
#include <linux/proc_fs.h> /* Necessary because we use proc fs */
#include <linux/seq_file.h> /* for seq_file */
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
#define HAVE_PROC_OPS
#endif
#define PROC_NAME "iter"
@ -92,11 +97,21 @@ static int my_open(struct inode *inode, struct file *file)
* This structure gather "function" that manage the /proc file
*
*/
static struct proc_ops my_file_ops = {.proc_open = my_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = seq_release};
#ifdef HAVE_PROC_OPS
static const struct proc_ops my_file_ops = {
.proc_open = my_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = seq_release,
};
#else
static const struct file_operations my_file_ops = {
.open = my_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
#endif
/**
* This function is called when the module is loaded

View File

@ -9,6 +9,11 @@
#include <linux/sched.h> /* For putting processes to sleep and
waking them up */
#include <linux/uaccess.h> /* for get_user and put_user */
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
#define HAVE_PROC_OPS
#endif
/*
* The module's file functions
@ -219,12 +224,21 @@ int module_close(struct inode *inode, struct file *file)
* the functions called when somebody tries to do something to our file. NULL
* means we don't want to deal with something.
*/
static struct proc_ops File_Ops_4_Our_Proc_File = {
#ifdef HAVE_PROC_OPS
static const struct proc_ops File_Ops_4_Our_Proc_File = {
.proc_read = module_output, /* "read" from the file */
.proc_write = module_input, /* "write" to the file */
.proc_open = module_open, /* called when the /proc file is opened */
.proc_release = module_close, /* called when it's closed */
};
#else
static const struct file_operations File_Ops_4_Our_Proc_File = {
.read = module_output,
.write = module_input,
.open = module_open,
.release = module_close,
};
#endif
/*
* Module initialization and cleanup