Created
January 8, 2024 18:30
-
-
Save maurorappa/b6107f032c9af67b935aa9e7c4e03d70 to your computer and use it in GitHub Desktop.
create a /proc file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifneq ($(KERNELRELEASE),) | |
obj-m := proc.o | |
else | |
KERNELDIR ?= /lib/modules/$(shell uname -r)/build | |
PWD := $(shell pwd) | |
KBUILD_CFLAGS += $(call cc-option,-Wno-error,) | |
default: | |
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules | |
endif | |
clean: | |
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/proc_fs.h> | |
#include <linux/seq_file.h> | |
static int hello_proc_show(struct seq_file *m, void *v) { | |
const int val = 13; | |
//seq_printf(m, "Hello proc!\n"); | |
seq_printf(m, "%d!\n", val); | |
return 0; | |
} | |
static int hello_proc_open(struct inode *inode, struct file *file) { | |
return single_open(file, hello_proc_show, NULL); | |
} | |
static const struct proc_ops hello_proc_fops = { | |
.proc_open = hello_proc_open, | |
.proc_read = seq_read, | |
.proc_lseek = seq_lseek, | |
.proc_release = single_release, | |
}; | |
static int __init hello_proc_init(void) { | |
proc_create("hello_proc", 0, NULL, &hello_proc_fops); | |
return 0; | |
} | |
static void __exit hello_proc_exit(void) { | |
remove_proc_entry("hello_proc", NULL); | |
} | |
MODULE_LICENSE("GPL"); | |
module_init(hello_proc_init); | |
module_exit(hello_proc_exit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for recent kernels >5.10