How to parse large amount of data passed to kernel module through /proc file? How to parse large amount of data passed to kernel module through /proc file? linux linux

How to parse large amount of data passed to kernel module through /proc file?


The request_firmware() interface may be of interest to you; the whole thing gets buffered by the kernel before it's handed to you.

Otherwise, maybe the sysfs binary attributes interface is more useful than proc?


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:

  1. Reads from internal buffer until it finds a space, then returns the text so far.
  2. 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.