Question

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

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

ioctl(fp, SZ_NEW_DEV_FORMAT, 0, 1, 30);
Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top