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
.)
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.
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