The ioctl(2) system call's signature is as follows:
#include <sys/ioctl.h>
int ioctl(int fd, unsigned long request, ...);
The parameter list is a varargs – variable arguments – one. Realistically and typically, we pass either two or three parameters:
- The first parameter is obvious – the file descriptor of the (in our case) device file that was opened.
- The second parameter, called request, is the interesting one: it's the command to be passed to the driver. In reality, it's an encoding, encapsulating a so-called ioctl magic number: a number and a type (read/write).
- The (optional) third parameter, often called arg, is also an unsigned long quantity; we use it to either pass some data in the usual fashion to the underlying driver or, often, to return data to the user space by passing its (virtual) address and having the kernel write into it, utilizing C's so-called value-result or in-out...