Create ProcFS entry in /proc/net

允我心安 提交于 2019-12-10 11:19:27

问题


I try to create an entry inside /proc/net from a kernel module, like this:

struct file *filp = filp_open("/proc/net", O_RDONLY, 0);
struct proc_dir_entry *parent = PDE(filp->f_dentry->d_inode);
filp_close(filp, NULL);

proc_file = create_proc_entry("test", 0644, parent);

Crudely taken from here

Why does it create my entry like /proc/test instead of /proc/net/test?

(Note: I'd like too use create_proc_entry, not proc_create.)


回答1:


In recent kernels you won't find create_proc_entry() anymore, it's been removed completely. Take a look at https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=80e928f7ebb958f4d79d4099d1c5c0a015a23b93. So, you need to use proc_create(). And, pass ->proc_net as parent directory entry. Take a look at this: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/proc.c#n479, this will give you a clear idea.

If you're not using a latest kernel, then you might have create_proc_entry(), therefore might consider using create_proc_entry(), rather proc_create(). But, I think it's best if you cope with current approach. Cause you won't get support for create_proc_entry() with latest kernels.




回答2:


I think the way to do it is :

proc_file = create_proc_entry("test", 0644, init_net.proc_net);



来源:https://stackoverflow.com/questions/16720168/create-procfs-entry-in-proc-net

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