mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
Move debugfs, rootfs and procfs documentation to README
This commit is contained in:
@@ -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[]
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user