如何在/proc/driver下创建proc条目? [英] How to create proc entry under /proc/driver?
问题描述
我想在/proc/driver
目录下创建一个文件.我想使用像proc_root_driver
这样的宏(或其他提供的东西),而不是显式地使用"driver/MODULE_NAME".我使用create_proc_entry
:
I want to create a file under a /proc/driver
directory. I would like to use a macro like proc_root_driver
(or something else provided) rather than use "driver/MODULE_NAME" explicitly. I use create_proc_entry
:
struct proc_dir_entry *simpleproc_fops_entry;
simpleproc_fops_entry = create_proc_entry(MODULE_NAME, 0400, NULL /* proc_root_dir */);
在谷歌搜索后,我发现使用proc_root_driver
的建议,但是当我使用它时,出现了错误
After googling, I found suggestion to use proc_root_driver
, but when I use it, I get the error
此函数未声明的proc_root_driver
proc_root_driver undeclared in this function
而且,proc_root_driver
在linux/proc_fs.h中不可用.
And also, proc_root_driver
is not available in linux/proc_fs.h.
我试图声明这样的结构:
I have tried to declare structure like this:
struct proc_dir_entry proc_root;
struct proc_dir_entry *proc_root_driver = &proc_root;
编译错误消失了,但是文件没有出现在/proc/driver
或/proc
下.如何在/proc
中创建条目?
The compilation errors gone, but the file didn't appear under /proc/driver
or /proc
. How can I make create an entry in /proc
?
推荐答案
看proc_fs.h,proc_root_driver定义为:
Looking at proc_fs.h, proc_root_driver is defined as :
extern struct proc_dir_entry *proc_root_driver;
,只要启用CONFIG_PROC_FS.如果在配置内核时选择了CONFIG_PROC_FS,则应该能够按照自己的建议使用它,即:
so long as CONFIG_PROC_FS is enabled. If you have CONFIG_PROC_FS selected when you configure your kernel, you should be able to use it as you suggested yourself i.e. :
#include <linux/proc_fs.h>
struct proc_dir_entry * procfile
procfile = create_proc_entry("myprocfile", 0400, proc_root_driver);
如果这不起作用,请检查是否已设置CONFIG_PROC_FS.为了确保这一点,您可以使用-E选项编译源文件,并检查create_proc_entry调用是否包含非NULL参数作为最后一个参数.如果它为NULL,或者根本不存在该调用,则不会启用CONFIG_PROC_FS.
If this does not work, check that you have CONFIG_PROC_FS set. To make sure, you can compile your source file with the -E option and check that the create_proc_entry call includes a non NULL parameter as the last parameter. If it is NULL, or the call is not there at all, then CONFIG_PROC_FS is not enabled.
这篇关于如何在/proc/driver下创建proc条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!