内核模块的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;
}
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屋!