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

浪尽此生 提交于 2019-12-01 03:14:45

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!