From 29092b38be10764ae11b5e56ef1ec047b6796f80 Mon Sep 17 00:00:00 2001 From: chrisp Date: Mon, 23 May 2022 12:02:01 -0400 Subject: [PATCH 1/2] allow simple-procfs to work with the new procfs api introduced in kernel 5.6 while still supporting older kernels --- simple-procfs-kmod.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/simple-procfs-kmod.c b/simple-procfs-kmod.c index fef17fe..3b96bf4 100644 --- a/simple-procfs-kmod.c +++ b/simple-procfs-kmod.c @@ -9,6 +9,7 @@ #include #include #include +#include #define BUFSIZE 100 #define PROCFS_NAME "simple-procfs-kmod" @@ -60,12 +61,27 @@ static ssize_t myread(struct file *file, char __user *ubuf,size_t count, loff_t return len; } +// the api for procfs changed with the 5.6 kernel to use the proc_ops struct rather than file_operations +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) +static loff_t proc_lseek(struct file *file, loff_t offset, int i) +{ + file->f_pos = offset; + return offset; +} +static struct proc_ops myops = +{ + .proc_read = myread, + .proc_write = mywrite, + .proc_lseek = proc_lseek, +}; +#else static struct file_operations myops = { .owner = THIS_MODULE, .read = myread, .write = mywrite, }; +#endif static int simple_init(void) { From ec540c9706d83d3f3c00ce728a4d216516dbff3a Mon Sep 17 00:00:00 2001 From: Chris Procter Date: Wed, 22 Feb 2023 12:39:47 +0000 Subject: [PATCH 2/2] update makefile for when build doesn't exist --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ddd7479..4b6f1ff 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,10 @@ KMODVER=$(shell git describe HEAD 2>/dev/null || git rev-parse --short HEAD) endif all: - make -C /lib/modules/$(KVER)/build M=$(PWD) EXTRA_CFLAGS=-DKMODVER=\\\"$(KMODVER)\\\" modules + make -C /usr/src/kernels/$(KVER)/ M=$(PWD) EXTRA_CFLAGS=-DKMODVER=\\\"$(KMODVER)\\\" modules gcc -o spkut ./simple-procfs-kmod-userspace-tool.c clean: - make -C /lib/modules/$(KVER)/build M=$(PWD) clean + make -C /usr/src/kernels/$(KVER)/ M=$(PWD) clean rm -f spkut install: install -v -m 755 spkut /bin/