正如在这个问题中指出的,Linux内核模块中的ioctl函数的原型是:
(第1版)
int ioctl(struct inode *i, struct file *f, unsigned int cmd, unsigned long arg);
或
(第2版)
long ioctl(struct file *f, unsigned int cmd, unsigned long arg);
我想在实现字符设备驱动程序的内核模块中使用它们。
在这种情况下,上述两种原型是否都适合?如果是,为什么?如果没有,如何选择正确的?
哪些头/源文件(S)包含这些原型?换句话说:这些原型的官方参考文件是什么?
linux驱动模块中ioctl的原型是
int ioctl(struct inode *i, struct file *f, unsigned int cmd, unsigned long arg);
或
long ioctl(struct file *f, unsigned int cmd, unsigned long arg);
但在sys/ioctl.h
int ioctl(int fd, int request, void *argp);
第一个参数类型不同,在ioctl调用程序和驱动程序之间是否有模块来转换这个参数(从文件描述符到文件结构指针)?
这个映射是如何工作的?(从文件描述符
我试图在内核空间中实现ioctl,以便将一些日期写入寄存器,在cmd的ioctl中我会崩溃。
下面是我的代码:
内核端:
static struct file_operations fops = {
.compat_ioctl = device_ioctl
};
int device_ioctl(struct inode *inode, struct file *filep,
unsigned int cmd, unsigned long arg)
{
int len = 200;
printk (KERN_INFO "In D
嗨,我写了char驱动程序,一切都很好,但是当我实现ioctl时,它就不工作了。我正在编写代码,通过ioctl调用读写设备。这是密码。
驱动程序代码ioctl.c
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/fs.h> /*this is the file structure, file open read close */
#include<linux/cdev.h> /* this is for character device, makes cdev av
我正在使用ioctl()从块设备(Scsi)读取数据。
我注意到,当我读取1024扇区时,ioctl完成时没有任何问题。当我读取2048时,过了很长一段时间后,它返回ENOMEM (errno=12),这甚至没有列在可能的错误列表中(请参阅)
我已经tripple检查了我传递的缓冲区大小是否合适,所以这不可能是这种情况--没有缓冲区溢出。
那么,我如何才能知道使用ioctl读取的最大缓冲区大小?
编辑1
一些附加信息可能会对您有所帮助:
Enterprise Linux Enterprise Linux Server release 5.3 (Carthage)
Red Hat Enterpr
根据,fcntl.ioctl的用法如下:
fcntl.ioctl(fd, op[, arg[, mutate_flag]])
将op定义为
The operation is defined by op and is operating system dependent. These codes are also found in the fcntl module.
它不会回答“什么”是op。它是int类型的吗?一根线?一种结构?如何正确使用此命令,例如在Linux平台上?
我目前正在开发一个Linux驱动程序,目前正在建立整个字符设备基础设施业务;主要是无聊的东西,用处理程序函数填充file_operations结构,同时我正在用Python编写一个小型测试套件。
相关的代码内核端(在这里看得不多)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
/* We try to keep the preprocessor #if/#endif mayhem to a minimum, but
* this is one of the few places where there's no way ar
我试图在Android上运行一个简单的IOCTL示例。我正在使用内核2.6和ICS。模块已正确注册/未注册(insmod/rmmod)。但是,每次尝试在模拟器上执行./user_app时,我总是
error: first ioctl: Not a typewriter
error: second ioctl: Not a typewriter
message: `�
这很明显是个通货。我调试了应用程序,没有执行fops过程(device_ioctl、read_ioctl和write_ioctl)。
我想知道在Android上使用/实现IOCTL是否有任何限制。先谢谢你。
-劳尔
以下是代码