Move debugfs, rootfs and procfs documentation to README

This commit is contained in:
Ciro Santilli
2018-06-29 09:55:25 +01:00
parent 0cd1a2b602
commit 9a4eae50c8
11 changed files with 149 additions and 98 deletions

View File

@@ -20,14 +20,11 @@
... link:dep2.c[]
. Pseudo filesystems
.. link:anonymous_inode.c[]
.. link:debugfs.c[]
.. link:ioctl.c[]
.. link:mmap.c[]
.. link:poll.c[]
.. link:procfs.c[]
.. link:seq_file.c[]
.. link:seq_file_inode.c[]
.. link:sysfs.c[]
. Asynchronous
.. link:irq.c[]
.. link:kthread.c[]

View File

@@ -1,3 +1,5 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#character-devices */
#include <linux/fs.h> /* register_chrdev, unregister_chrdev */
#include <linux/module.h>
#include <linux/seq_file.h> /* seq_read, seq_lseek, single_release */

View File

@@ -1,3 +1,5 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#automatically-create-character-device-file-on-insmod */
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h> /* register_chrdev, unregister_chrdev */

View File

@@ -1,17 +1,4 @@
/*
Adapted from: https://github.com/chadversary/debugfs-tutorial/blob/47b3cf7ca47208c61ccb51b27aac6f9f932bfe0b/example1/debugfs_example1.c
Usage:
/debugfs.sh
Requires `CONFIG_DEBUG_FS=y`.
Only the more basic fops can be implemented in debugfs, e.g. mmap is never called:
- https://patchwork.kernel.org/patch/9252557/
- https://github.com/torvalds/linux/blob/v4.9/fs/debugfs/file.c#L212
*/
/* https://github.com/cirosantilli/linux-kernel-module-cheat#debugfs */
#include <linux/debugfs.h>
#include <linux/kernel.h>

View File

@@ -1,15 +1,4 @@
/*
Yet another fops entrypoint.
https://stackoverflow.com/questions/8516021/proc-create-example-for-kernel-module
insmod /procfs.ko
cat /proc/lkmc_procfs
Output:
abcd
*/
/* https://github.com/cirosantilli/linux-kernel-module-cheat#procfs */
#include <linux/debugfs.h>
#include <linux/module.h>

View File

@@ -1,24 +1,4 @@
/*
Adapted from: https://github.com/t3rm1n4l/kern-dev-tutorial/blob/1f036ef40fc4378f5c8d2842e55bcea7c6f8894a/05-sysfs/sysfs.c
Vs procfs:
- https://unix.stackexchange.com/questions/4884/what-is-the-difference-between-procfs-and-sysfs
- https://stackoverflow.com/questions/37237835/how-to-attach-file-operations-to-sysfs-attribute-in-platform-driver
This example shows how sysfs is more restricted, as it does not take a file_operations.
So you basically can only do open, close, read, write, and lseek on sysfs files.
It is kind of similar to a seq_file file_operations, except that write is also implemented.
TODO: what are those kobject structs? Make a more complex example that shows what they can do.
- https://www.kernel.org/doc/Documentation/kobject.txt
- https://www.quora.com/What-are-kernel-objects-Kobj
- http://www.makelinux.net/ldd3/chp-14-sect-1
- https://www.win.tue.nl/~aeb/linux/lk/lk-13.html
*/
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sysfs */
#include <linux/init.h>
#include <linux/kobject.h>