Linux驱动设计ioctl函数的第二个参数cmd不能为2

Linux驱动设计ioctl函数的cmd参数不能为2。


今天遇到一个难题,使用系统调用ioctl()函数时,第二个参数request不能传入2。



文件操作接口:

struct file_operations{

…… …… ……

long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long),

};


在设计驱动接口函数时:

static long mem_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)

{

…… …… ……

}


测试驱动的程序:(系统调用函数ioctl())

FILE *fp0 = NULL;

fp0 = fopen("/dev/memdev2","r+");

ioctl(fileno(fp0),2,10);


在上面测试驱动的程序中,我在系统调用ioctl函数的第二参数request传入了2,导致驱动的mem_ioctl里面程序执行不了。

系统调用ioctl()函数的第二参数cmd不能为2,如果为2,驱动接口ioctl()函数则返回-1。返回-1,则说明失败。


参考:https://blog.youkuaiyun.com/tq384998430/article/details/71213499

http://www.cnblogs.com/helloworldtoyou/p/4945543.html

https://stackoverflow.com/questions/10071296/ioctl-is-not-called-if-cmd-2StackOverFlow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值