ioctrl原形 linux_linux内核升级后,ioctl的坑

最近写linux驱动,被网上的教程狠狠坑了一把.

linux内核为3.13, 网上博客都是基于2.6.x的.

大部分都提及: file_operations 的 ioctl 已经废弃,改由使用unlocked_ioctl 或者compat_ioctl

此时编译会失败,一般提示:  error:unknown field 'ioctl' specified in initializer

把ioctl修改下就好:

struct file_operations vppgo_io_fops = {

.open = test_io_open,

.release = test_io_close,

//.ioctl =  test_io_ioctl, //#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))

.unlocked_ioctl = test_io_ioctl,

};

但是还有一点: ioctl函数指针,参数个数减少,这个是国内大部分教程都没有写明的,搜索了好久,才google出来,详细见这个链接.

int ioctl(struct inode *i, struct file *f, unsigned int cmd, unsigned long arg);

从 2.6.35开始,变为:

long ioctl(struct file *f, unsigned int cmd, unsigned long arg);

存在的坑还在于,由于是函数指针类型,在编译的时候参数错了也不会报错.

因此在实际使用时,就会发现ioctl到驱动的参数值对不上.

还是要多多看看头文件啊,确定下参数形式...

ioctl相关的file_operations位于中.

/usr/src/linux-source-3.13.0/include/linux/fs.h

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值