100分求教:请教proc/net下面的文件的生成和填写方法
小弟最近在把linux下的nettool,如netstat等,向freebsd移植,需要使用linprocfs来在net目录下添加一些新的文件,如tcp,udp, netstatd,但是刚刚涉及这个领域,非常希望看到linux下的proc/net/中tcp,udp这些文件的填写过程,但我找不到具体的函数,据说他们是分散在各个驱动中的,众说不一。希望各位指教,再拜!!
proc目录下的文件有的是系统启动的时候建立的,有的是在用户访问这个目录时才创建的,但我不知道net目录下的那些文件到底是由哪段代码创建的,希望达人指教!!
我发现,大多数在后缀为init的函数中
如 ip_init
void __init ip_init(void)
{
dev_add_pack(&ip_packet_type);
ip_rt_init();
inet_initpeers();
#if defined(CONFIG_IP_MULTICAST) && defined(CONFIG_PROC_FS)
igmp_mc_proc_init(); //看到没有??
#endif
}
在ip_rt_init();中又有如下的代码
#ifdef CONFIG_PROC_FS
if (!proc_net_fops_create("rt_cache", S_IRUGO, &rt_cache_seq_fops) ||
!proc_net_fops_create("rt_cache_stat", S_IRUGO, &rt_cpu_seq_fops)) {
free_percpu(rt_cache_stat);
return -ENOMEM;
}
#ifdef CONFIG_NET_CLS_ROUTE
create_proc_read_entry("rt_acct", 0, proc_net, ip_rt_acct_read, NULL);
#endif
但是如果我使用Linprocfs.c向freebsd移植linux的proc/net,也要这样来做么,还是直接在×init中填入代码?
PS:我也是刚刚接触freebsd,他也有Proc fs文件系统,但是与linux的不兼容,为了可以在freebsd下使用linux下用的一些软件,必须模拟linux下的proc,所以有人为freebsd添加了compat/linux/linprocfs.c来专门管理这项工作,我想对Linprocfs.c进一步完善,以让他支持linux下的net_tool,such as netstat and route.thus need to add tcp ,udp ,netstat under the compat/linux/proc/net dictionary in Freebsd