procfs example, S99 symlink

This commit is contained in:
Ciro Santilli
2017-07-27 09:20:40 +01:00
parent ab6cb2626f
commit 4727fadcc8
4 changed files with 60 additions and 1 deletions

View File

@@ -213,6 +213,8 @@ and they will be run automatically before the login prompt.
`S99` is already gitignored for you. `S99` is already gitignored for you.
For convenience, we also setup a symlink from `S99` to `rootfs_overlay/etc/init.d/S99`.
## Debugging ## Debugging
To GDB the Linux kernel, first run: To GDB the Linux kernel, first run:

1
S99 Symbolic link
View File

@@ -0,0 +1 @@
rootfs_overlay/etc/init.d/S99

View File

@@ -5,9 +5,11 @@
1. Debugging 1. Debugging
1. [hello](hello.c) 1. [hello](hello.c)
1. [hello2](hello2.c) 1. [hello2](hello2.c)
1. [debugfs](debugfs.c)
1. [panic](panic.c) 1. [panic](panic.c)
1. [params](params.c) 1. [params](params.c)
1. Pseudo filesystems
1. [debugfs](debugfs.c)
1. [procfs](procfs.c)
1. [fops](fops.c) 1. [fops](fops.c)
1. [ioctl](ioctl.c) 1. [ioctl](ioctl.c)
1. [poll](poll.c) 1. [poll](poll.c)

54
kernel_module/procfs.c Normal file
View File

@@ -0,0 +1,54 @@
/*
Yet another fops entrypoint.
https://stackoverflow.com/questions/8516021/proc-create-example-for-kernel-module
insmod /procfs.ko
cat /proc/lkmc_procfs
Output:
abcd
*/
#include <linux/debugfs.h>
#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 file_operations fops = {
.llseek = seq_lseek,
.open = open,
.owner = THIS_MODULE,
.read = seq_read,
.release = single_release,
};
static int myinit(void)
{
proc_create(filename, 0, NULL, &fops);
return 0;
}
static void myexit(void)
{
remove_proc_entry(filename, NULL);
}
module_init(myinit)
module_exit(myexit)
MODULE_LICENSE("GPL");