How to parse large amount of data passed to kernel module through /proc file?
I finally decided to write something proper to solve this problem.
kio
kio
in short, will be a port of C's standard stdio.h
for kernel modules. It will support either of /proc
, /sys
and /dev
file systems in both read and write modes, whether text or binary. kio
follows the standard closely, but has its minor tweaks to ensure safety in kernel space.
Current status:
/proc
files can be created- Read functions are implemented
- Write functions are implemented
- The files can be only opened by users once at a time
Implement a separate function get_token(), which:
- Reads from internal buffer until it finds a space, then returns the text so far.
- When at the end of the buffer, reads more data from user space to the buffer.
This way your other parsing logic is greatly simplified (not having to parse integers manually etc). Simply call sscanf() or strtol() on the returned strings.
The limitation is that you need to impose a maximum length on a single token so that it can fit in the buffer.