From 24e5d4918db371a2c670be75a2fcae67757df6c5 Mon Sep 17 00:00:00 2001 From: LSKhappychild Date: Fri, 23 Dec 2022 16:28:16 +0900 Subject: [PATCH] Revise proc_ops creation logic in ch2 proc kernel module exercise --- ch2/hello.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ch2/hello.c b/ch2/hello.c index f521088..0e47997 100644 --- a/ch2/hello.c +++ b/ch2/hello.c @@ -9,7 +9,7 @@ * Operating System Concepts - 10th Edition * Copyright John Wiley & Sons - 2018 */ - +#include #include #include #include @@ -26,11 +26,19 @@ */ static ssize_t proc_read(struct file *file, char *buf, size_t count, loff_t *pos); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) +#define HAVE_PROC_OPS +#endif +#ifdef HAVE_PROC_OPS +static const struct proc_ops proc_ops = { + .proc_read = proc_read +}; +#else static struct file_operations proc_ops = { .owner = THIS_MODULE, .read = proc_read, }; - +#endif /* This function is called when the module is loaded. */ static int proc_init(void)