Linux V3.10 内核的变化…

把一个在3.8内核运行的内核模块源码放到3.10内核编译失败,编译显示在kernel 3.8 下调用的 create_proc_entry() 函数未定义。总结一下这个内核模块源码在3.10与3.8编译通过的区别。

1. create_proc_entry() 函数

1 static inline struct proc_dir_entry *create_proc_entry(const char *name,
2                 umode_t mode, struct proc_dir_entry *parent)

3.8 内核有这个API,3.10 内核没有

3.10 可以使用:proc_create() 函数

1 static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
2     struct proc_dir_entry *parent,
3     const struct file_operations *proc_fops)

这个函数在 3.8与 3.10 内核都有。

比较可以看出 proc_create() 比create_proc_entry() 多了一个file_operations参数

调用create_proc_entry()代码:

1 ipf_stats = create_proc_entry("stats", 0, proc_ipf);
2 if (ipf_stats)
3 {
4     ipf_stats->proc_fops = &stats_file_ops;
5 }

使用proc_create() 代码:

1 ipf_stats = proc_create("stats", 0, proc_ipf, &stats_file_ops);

2. struct proc_dir_entry 变化

3.10内核去掉了:write_proc_t *write_proc 函数指针。那么如何实现相同功能的写函数呢?答案是通过proc_create()最后一个参数。

1 static struct file_operations cmd_file_ops = {
2     .write = ipf_cmd_write,
3 };
1 ipf_cmd = proc_create("cmd", S_IFREG | S_IRUGO | S_IWUSR, proc_ipf, &cmd_file_ops);

ipf_cmd_write 是自定义的写函数,其内容可以自己实现。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值