我必须编写一个linux char设备,它处理每个unlock_ioctl的ioctl(没有BKL)函数。目前,我可以从用户空间 ioctl 命令接收一个参数
__get_user(myint, (int __user *) arg);
我如何接收多个 int 参数(例如此调用)?:
ioctl(fp, SZ_NEW_DEV_FORMAT, 0, 1, 30);
是的,你必须使用结构。对于特定的 ioctl 命令,会有一些预定义的参数。您需要将所有这些参数包装到一个结构对象中,并传入该对象的地址。在内核内部,您需要将给定的 arg 类型转换为结构指针并访问参数。例如。
struct mesg {
int size;
char buf[100];
};
struct mesg msg1;
/*Fill in the structure object here and call ioctl like this*/
ret = ioctl(fd, SZ_NEW_DEV_FORMAT, &msg1);
在内核中你可以像这样访问它:
struct mesg *msg;
copy_from_user((char *)msg, (char *)arg, sizeof(*msg));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)