17.8.2. seq_file
TODO these examples broke in kernel 5.0 and we didn’t notice because they just added a flimsy warning and nothing else:
Fix with ifdef for kernel 4/5. The error message is:
seq_file: buggy .next function next [module-name] did not update position index
Writing trivial read File operations is repetitive and error prone. The seq_file API makes the process much easier for those trivial cases:
./seq_file.sh echo $?
Outcome: the test passes:
0
Sources:
In this example we create a debugfs file that 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.
seq_file does not provide write: https://stackoverflow.com/questions/30710517/how-to-implement-a-writable-proc-file-by-using-seq-file-in-a-driver-module
Bibliography: