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-2(StackOverFlow)