【发布时间】:2017-03-20 00:13:34
【问题描述】:
使用 proc,我们可以轻松地使用 read & write 系统调用,如本例所示。 write on /proc entry through user space
但我正在使用 debugfs 将信息从驱动程序传递到用户空间。 我能够找到这两个示例代码。这里应用程序可以使用 mmap() 系统调用读取和写入 debugfs 文件。
- http://people.ee.ethz.ch/~arkeller/linux/code/mmap_simple_kernel.c
- http://people.ee.ethz.ch/~arkeller/linux/code/mmap_user.c
但假设在我的情况下需要使用 Debugfs 文件与设备驱动程序进行通信:
user-space application <-------> debugfs file <-------> Device driver
那么我可以在我的 --->> 设备驱动程序代码 --->> 中使用相同的代码 mmap_simple_kernel.c 并将数据直接从驱动程序传输到 debugfs 吗?但是在这种情况下,我的驱动程序中会有两个 file_operations 结构会导致一些问题吗?这是正确的方法吗?
或者就像应用程序正在遵循 -- mmap_user.c 中的进程 --- 相同的进程 -- 我在我的设备驱动程序中遵循。并保留 mmap_simple_kernel.c 作为 debugfs 条目的单独模块?
【问题讨论】:
-
如果需要,您也可以在 debugfs 中的文件上使用
read()和write()。例如,如果您需要传递大量数据,mmap()会派上用场,但并非强制使用它。 -
在我的一个项目中,我使用 debugfs 文件向用户空间提供一些数据并控制我的内核空间系统,例如,参见this file。在 debugfs 中创建了三个文件("i_addr"、"func_name" 和 "func_i_start"),第一个是可写的,其余的两个是只读的。另请参阅那里如何使用
debugfs_create_file()。我还建议查看其他debugfs_create_* functions,它们可能更适合您的需求。 -
另外一个使用
mmap()的例子,链接是in this comment。根据您要完成的任务,这可能很有用。
标签: linux-kernel linux-device-driver