diff --git a/examples/chardev.c b/examples/chardev.c index c00969c..8d901b8 100644 --- a/examples/chardev.c +++ b/examples/chardev.c @@ -3,9 +3,6 @@ * you've read from the dev file */ -#include -#include -#include #include #include #include diff --git a/examples/chardev2.c b/examples/chardev2.c index 859325d..cdfb32d 100644 --- a/examples/chardev2.c +++ b/examples/chardev2.c @@ -2,9 +2,6 @@ * chardev2.c - Create an input/output character device */ -#include -#include -#include #include #include #include diff --git a/examples/kbleds.c b/examples/kbleds.c index 83c393e..c734653 100644 --- a/examples/kbleds.c +++ b/examples/kbleds.c @@ -2,7 +2,6 @@ * kbleds.c - Blink keyboard leds until the module is unloaded. */ -#include /* For vc_cons */ #include #include /* For KDSETLED */ #include @@ -10,6 +9,8 @@ #include #include /* for fg_console */ +#include /* For vc_cons */ + MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs."); MODULE_AUTHOR("Daniele Paolo Scarpazza"); MODULE_LICENSE("GPL"); diff --git a/examples/procfs1.c b/examples/procfs1.c index 54a2630..42432d8 100644 --- a/examples/procfs1.c +++ b/examples/procfs1.c @@ -6,6 +6,11 @@ #include #include #include +#include + +#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() { diff --git a/examples/procfs2.c b/examples/procfs2.c index f7eade4..6e4d4f9 100644 --- a/examples/procfs2.c +++ b/examples/procfs2.c @@ -7,6 +7,11 @@ #include /* Specifically, a module */ #include /* Necessary because we use the proc fs */ #include /* for copy_from_user */ +#include + +#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 diff --git a/examples/procfs3.c b/examples/procfs3.c index 456b2a0..d56d11e 100644 --- a/examples/procfs3.c +++ b/examples/procfs3.c @@ -7,6 +7,11 @@ #include #include #include +#include + +#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() { diff --git a/examples/procfs4.c b/examples/procfs4.c index 1ccde6f..4d63424 100644 --- a/examples/procfs4.c +++ b/examples/procfs4.c @@ -8,6 +8,11 @@ #include /* Specifically, a module */ #include /* Necessary because we use proc fs */ #include /* for seq_file */ +#include + +#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 diff --git a/examples/sleep.c b/examples/sleep.c index 4a9d692..b14ab99 100644 --- a/examples/sleep.c +++ b/examples/sleep.c @@ -9,6 +9,11 @@ #include /* For putting processes to sleep and waking them up */ #include /* for get_user and put_user */ +#include + +#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