Files
linux-kernel-module-cheat/kernel_modules/procfs.c
Ciro Santilli 六四事件 法轮功 50570326d4 fix kernel modules build after updating linux to v5.9.2
- `dep.c` and `dep2.c`: `debugfs_create_u32` does not return anymore, not
  sure why:
  https://unix.stackexchange.com/questions/593983/creating-a-debugfs-file-that-is-used-to-read-write-u32-value/621282#621282
  So just doing `debugfs_lookup` for now
- vermagic.c:
  51161bfc66
  prevents its usage in v5.8. Just migrating to `init_utsname` for now
- procfs.c: `struct file_operations` moved to a new `struct proc_ops` at:
  b567e07513
- myprintk.c: `pr_warning` dropped for `pr_warn`:
  61ff72f401
- `poll.c`: `kthread_func` is not defined in kernel, prefix with lkmc to
  avoid conflict

Fix https://github.com/cirosantilli/linux-kernel-module-cheat/issues/136

Fix https://github.com/cirosantilli/linux-kernel-module-cheat/issues/137
2020-11-24 00:00:01 +00:00

42 lines
833 B
C

/* https://cirosantilli.com/linux-kernel-module-cheat#procfs */
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h> /* seq_read, seq_lseek, single_open, single_release */
#include <uapi/linux/stat.h> /* S_IRUSR */
static const char *filename = "lkmc_procfs";
static int show(struct seq_file *m, void *v)
{
seq_printf(m, "abcd\n");
return 0;
}
static int open(struct inode *inode, struct file *file)
{
return single_open(file, show, NULL);
}
static const struct proc_ops pops = {
.proc_lseek = seq_lseek,
.proc_open = open,
.proc_read = seq_read,
.proc_release = single_release,
};
static int myinit(void)
{
proc_create(filename, 0, NULL, &pops);
return 0;
}
static void myexit(void)
{
remove_proc_entry(filename, NULL);
}
module_init(myinit)
module_exit(myexit)
MODULE_LICENSE("GPL");