mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
seq_file: move doc to README
This commit is contained in:
@@ -22,8 +22,6 @@
|
||||
.. link:ioctl.c[]
|
||||
.. link:mmap.c[]
|
||||
.. link:poll.c[]
|
||||
.. link:seq_file.c[]
|
||||
.. link:seq_file_inode.c[]
|
||||
. Asynchronous
|
||||
.. link:irq.c[]
|
||||
.. link:kthread.c[]
|
||||
|
||||
@@ -24,6 +24,9 @@ static ssize_t read(struct file *filp, char __user *buf, size_t len, loff_t *off
|
||||
ret = -EFAULT;
|
||||
}
|
||||
myval <<= 4;
|
||||
if (myval == 0) {
|
||||
myval = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,4 @@
|
||||
/*
|
||||
Adapted from: Documentation/filesystems/seq_file.txt
|
||||
but we limit the count to the max module parameter.
|
||||
|
||||
Writting trivial read fops is repetitive and error prone.
|
||||
|
||||
The seq_file API makes the process much easier for those trivial cases.
|
||||
|
||||
This example is behaves just like a file that contains:
|
||||
|
||||
0
|
||||
1
|
||||
2
|
||||
|
||||
However, we only store a single integer in memory
|
||||
and calculate the file on the fly in an iterator fashion.
|
||||
|
||||
There is not write version, as writes are more complex:
|
||||
https://stackoverflow.com/questions/30710517/how-to-implement-a-writable-proc-file-by-using-seq-file-in-a-driver-module
|
||||
|
||||
Bibliography:
|
||||
|
||||
- Documentation/filesystems/seq_file.txt
|
||||
- https://stackoverflow.com/questions/25399112/how-to-use-a-seq-file-in-linux-modules
|
||||
*/
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#seq_file */
|
||||
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/errno.h> /* EFAULT */
|
||||
|
||||
@@ -1,12 +1,4 @@
|
||||
/*
|
||||
If you have the entire read output upfront, single_open
|
||||
is an even more convenient version of seq_file.
|
||||
|
||||
This example behaves like a file that contains:
|
||||
|
||||
ab
|
||||
cd
|
||||
*/
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#seq_file-single_open */
|
||||
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/errno.h> /* EFAULT */
|
||||
@@ -40,8 +32,7 @@ static const struct file_operations fops = {
|
||||
|
||||
static int myinit(void)
|
||||
{
|
||||
debugfs_file = debugfs_create_file(
|
||||
"lkmc_seq_file_single", S_IRUSR, NULL, NULL, &fops);
|
||||
debugfs_file = debugfs_create_file("lkmc_seq_file_single_open", S_IRUSR, NULL, NULL, &fops);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user