ioctl() prototype is like this:
int ioctl(int d, int request, ...);
The first argument is the file descriptor, second argument is the command and the third argument can be a char *.
The last argument is used to pass parameters to the ioctl and this parameter depends on the second argument 'request'.
Say for example I want to send a parameter to the ioctl for a test command IOCTL_SENDMESG, I can do like this:
struct msg {
int type;
int len;
char buf[100]
};
struct msg msg1;
Fill in the msg1 object properly and send it the ioctl like this:
ret = ioctl(fd, IOCTL_SENDMESG, (char *) &msg1);
In side the driver or where ever the kernel ioctl is, it should type cast it like this.
struct msg *msg1 = (struct msg *) arg;
|