简体   繁体   English

从内核空间执行ioctl

[英]Performing an ioctl from the kernel-space

I'm writing a kernel driver that needs to perform an ioctl on another device. 我正在编写一个需要在另一台设备上执行ioctl的内核驱动程序。 I realize this is not the best way to handle the code, but this is just a temporary fix for now. 我意识到这不是处理代码的最佳方法,但这只是暂时的修复。 I'm getting back error code -22 (Invalid argument) from my ioctl call in the function, but I don't see what could be wrong with the arguments. 我从函数中的ioctl调用中找回错误代码-22(无效参数),但我没有看到参数可能出错。 Here are the relevant sections of code. 以下是相关的代码部分。

#define GPIO74 "/dev/gpio/74"

struct file* gpio74FD;
  .
  .
  .
gpio74FD = filp_open(GPIO74,O_RDWR,0)
  .
  .
  .
int device_ioctl(struct inode* inode,struct file *file, unsigned int ioctl_num,unsigned long ioctl_param)
{
  .
  .
  .
ret_val = gpio74FD->f_op->ioctl(inode, gpio74FD, GPIO_CONFIG_AS_INP, 0); //returns error code -22 (Invlaid Argument)
  .
  .
  .
return ret_val;
}

I suspect it may have something to do with passing the incorrect inode here, but im not even sure how to get the correct inode if its not the one passed to ioctl from the user space. 我怀疑这可能与在这里传递不正确的inode有关,但我甚至不确定如何获得正确的inode,如果它不是从用户空间传递给ioctl的那个。

Since you are now very deep in "don't do that" hacking territory, adding a few printk to the gpio driver could give you some valuable info. 由于你现在非常深入“不要那样做”黑客攻击领域,在gpio驱动程序中添加一些printk可以为你提供一些有价值的信息。

Another options is to avoid this horrible hack, and switch to a less harmful one : add an exported function to the gpio driver, that you can call from your own module 另一个选择是避免这种可怕的黑客攻击,并切换到危害较小的黑客:将导出的函数添加到gpio驱动程序,您可以从自己的模块调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM