创建设备驱动程序,但是当调用函数ioctl时,它说"ioctl(*,0x *" [英] Create a device driver, but when call the function ioctl , it say "ioctl(*, 0x* "

查看:129
本文介绍了创建设备驱动程序,但是当调用函数ioctl时,它说"ioctl(*,0x *"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

谢谢你的帮助.

我尝试构建设备驱动程序并成功构建它.

当我调用ioctl系统调用时,它提示杀死".

然后我用strace命令运行,它说" ioctl(3,0x22< unfinished ... ="> +++被SIGKILL杀死+++被杀死". >
相关的驱动程序代码为:

Hi All,

Thank you for help.

I try to build a device driver and have build it Successfully.

When I call the ioctl system call, it prompts "Killed".

Then I run with strace command, it say "ioctl(3, 0x22 <unfinished ...=""> +++ killed by SIGKILL +++ Killed".

The related driver code is:

#define TEST_IOC_MAGIC 0x00
//Documentation/ioctl-number.txt say 0x00~0x1F are been used.
#define TEST_IOCRESET _IO(TEST_IOC_MAGIC, 0x22)
....
static const struct file_operations globalfifo_fops =
{
       .unlocked_ioctl = globalfifo_ioctl,

};
...
static int globalfifo_ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
{
      ...
      case TEST_IOCRESET:
      ....
}


相关程序代码为:


The related program code is:

int main()
{
      //  /dev/globalfifopoll is the device file.
      fd = open("/dev/globalfifopoll", O_CREAT|O_RDWR|O_NONBLOCK);
      ioctl(fd, TEST_IOCRESET, 0);
}


设备驱动程序和程序均已成功构建.同时,当您向其写入缓冲区数据或从中读取缓冲区数据时,设备驱动程序可以正常工作.

我不知道哪里出了问题.在程序中,函数open()将值3返回给fd.但是在运行代码ioctl()时,它会显示" ioctl(3,0x22< unfinished ... ="> ".

如果删除代码ioctl(fd, TEST_IOCRESET, 0),该程序可以正常运行.

谢谢您的帮助.


The device driver and the program are both build Successfully. Meanwhile, the device driver can work well when you write buffer data to it or read buffer data from it.

I don''t know where is wrong. In the program, the function open() return value 3 to fd. But when run the code ioctl(), it says "ioctl(3, 0x22 <unfinished ...=""> ".

If I delete the code ioctl(fd, TEST_IOCRESET, 0), the program can run well.

Thank you for your help.

推荐答案

对不起,错误的结果说是ioctl(3,0x22(未完成....).

我在globalfifo_ioctl()函数中编写了日志,但是日志不是print(使用dmesg命令查看).我确定这个设备驱动程序可以正常工作,因为我可以在驱动程序的其他界面中打印其他日志.
Sorry, the wrong result say ioctl(3, 0x22 (unfinished ....).

I write the log in the function of globalfifo_ioctl(), but the log is not print( use the command dmesg to see). I''m sure this device driver can work well, because I can print other log in other interfaces of the driver.


哦,我解决了.谢谢您的通知.

原因是:

在Linux版本2.6.32之前,ioctl驱动程序方法是:
静态int(* ioctl)(struct inode * inode,结构文件* filp,unsigned int cmd,unsigned long arg);
我的linux版本是2.6.38,ioctl驱动程序方法是:
静态长整数(* ioctl)(结构文件* filp,unsigned int cmd,unsigned long arg)

在我的设备驱动程序中,我使用了第一个ioctl驱动程序方法.当我使用第二个ioctl驱动程序方法时,一切正常.
Oh, I resolve it. Thank you for your notice.

The reason is that:

Before the linux version 2.6.32, the ioctl driver method is :
static int (*ioctl)(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg);
My linux version is 2.6.38, the ioctl driver method is :
static long (*ioctl)(struct file *filp, unsigned int cmd, unsigned long arg)

In my device driver, I use the first ioctl driver method, that is abandon. When I use the second ioctl driver method, everything is OK.


这篇关于创建设备驱动程序,但是当调用函数ioctl时,它说"ioctl(*,0x *"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆