内核模块的 proc_create() 示例 [英] proc_create() example for kernel module
问题描述
有人能给我 proc_create()
的例子吗?
Can someone give me proc_create()
example?
之前他们在内核中使用了 create_proc_entry()
,但现在他们使用了 proc_create()
.
Earlier they used create_proc_entry()
in the kernel but now they are using proc_create()
.
推荐答案
此示例将创建一个启用读取访问的 proc 条目.我认为您可以通过更改传递给函数的 mode
参数来启用其他类型的访问.我没有通过父目录,因为没有必要.结构 file_operations
是您设置读取和写入回调的地方.
This example will create a proc entry which enables reading access. I think you can enable other kinds of access by changing the mode
argument passed to the function. I haven't passed a parent directory because there is no need to. The structure file_operations
is where you setup your reading and writing callbacks.
struct proc_dir_entry *proc_file_entry;
static const struct file_operations proc_file_fops = {
.owner = THIS_MODULE,
.open = open_callback,
.read = read_callback,
};
int __init init_module(void){
proc_file_entry = proc_create("proc_file_name", 0, NULL, &proc_file_fops);
if(proc_file_entry == NULL)
return -ENOMEM;
return 0;
}
您可以查看此示例以了解更多详细信息:https://www.linux.com/learn/linux-training/37985-the-kernel-newbie-corner-kernel-debugging-using-proc-qsequenceq-files-part-1
You can check this example for more details: https://www.linux.com/learn/linux-training/37985-the-kernel-newbie-corner-kernel-debugging-using-proc-qsequenceq-files-part-1
这篇关于内核模块的 proc_create() 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!