您的位置:首页 > 其它

ioctl 调用方法

2016-08-28 14:19 183 查看
说明:当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 =
aaaIoctl,
};

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);
}<
4000
/span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息