Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow simple-procfs to work with the new procfs api introduced RHEL9 #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
16 changes: 16 additions & 0 deletions simple-procfs-kmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <linux/version.h>
#define BUFSIZE 100

#define PROCFS_NAME "simple-procfs-kmod"
Expand Down Expand Up @@ -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)
{
Expand Down