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>
可以使用 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>
相关文章推荐
- ioctl 调用方法
- Linux 内核与用户空间通信 - netlink使用方法 (不同于 系统调用 和 ioctl)
- 用WinDbg探索CLR世界 [4] 方法的调用机制之动态分析 - 下
- 如何在Java中实现远程方法调用
- 用WinDbg探索CLR世界 [4] 方法的调用机制
- 使用COM或者OLE的方法调用来控制Excel或者其他Office组件
- 调用DLL的方法(验证通过)
- Shark中调用外部程序的方法
- 用WinDbg探索CLR世界 [4] 方法的调用机制之静态结构
- JAVA通过JNI调用本地C语言方法
- 非.NET语言调用.NET XML Web Services返回的数据集合的两个方法
- Java远程方法调用 4
- vc++中调用ADO的常用方法
- 重载方法调用。
- ASP里调用存储过程的几种方法
- 调用MCI录制WAV时,控制流率的方法
- Java远程方法调用 3
- VB动态调用外部函数的方法
- 用WinDbg探索CLR世界 [4] 方法的调用机制之动态分析 - 上
- 《.NET中统一的存储过程调用方法(收藏) 》的具体实现