问题
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);
回答1:
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));
来源:https://stackoverflow.com/questions/8849445/char-device-catch-multiple-int-ioctl-arguments