字符设备捕获多个(int)个ioctl参数 [英] char device catch multiple (int) ioctl-arguments

查看:247
本文介绍了字符设备捕获多个(int)个ioctl参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个linux char设备,该设备可为每个unlock_ioctl处理ioctl(无BKL)功能.目前,每个

I have to write a linux char device, which handles ioctl (without BKL) functions per unlock_ioctl. At the moment I can receive one argument from the userspace ioctl command per

__get_user(myint, (int __user *) arg);

如何接收多个int参数(例如此调用)?

How can I receive multiple int-arguments (for example this call)?:

ioctl(fp, SZ_NEW_DEV_FORMAT, 0, 1, 30);

推荐答案

是的,您必须使用结构.对于特定的ioctl命令,将有一些预定义的参数.您需要将所有这些参数包装到一个结构对象中并传递该对象的地址.在内核方面,您需要类型转换给定的arg以构造指针并访问参数.例如.

Yes, you have to use structures. For a particular ioctl command there will be some predefined arguments. You need to wrap these all arguments into a structure object and pass in the address of the object. In side the kernel, you need to type cast the given arg to structure pointer and access the arguments. For instance.

 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);

在内核内部,您可以这样访问它:

Inside the kernel you access it like this:

      struct mesg *msg;
      copy_from_user((char *)msg, (char *)arg, sizeof(*msg));

这篇关于字符设备捕获多个(int)个ioctl参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆