ioctl 调用方法

来源:互联网 发布:java多态的原理 编辑:程序博客网 时间:2024/04/29 12:34
说明:当struct DDD的长度何long不对等时,不能简单的类型转换,会导致编译错误。
可以使用 memcpy() 方式拷贝解决。

应用程序:
typedef struct DDD{
int aa;
int bb;
int cc;
}ABC;

ABC abc;

abc.aa = 0x12;
abc.bb = 0x34;
abc.cc = 0x56;

ioctl(fd, 0x98, &abc);


驱动程序方式:
typedef struct DDD{
int aa;
int bb;
int cc;
}ABC;

static struct file_operations aa = {
.unlocked_ioctl = PilotlabSystemRunLedIoctl,
};

static long aaaIoctl(struct file *file, unsigned int cmd, unsigned long arg)
{
ABC *ddd = NULL;
ddd = kmalloc(sizeof(struct DDD), GFP_KERNEL);
memcpy(ddd, (void *)arg, sizeof(struct DDD));
printk(KERN_WARNING "%s cmd:0x%02x, 0x%02x 0x%02x 0x%02x  \n", __func__, cmd, ddd->aa, ddd->bb, ddd->cc);
kfree(ddd);
}
1 0
原创粉丝点击