Here is the ioctl call in user space:
int ioctl(int fd, int cmd, ...);
As far as I know, when we want to perforate I / O operations, we define our own ioctl function with a set of requests (commands), assign our ioctl file_operations :
struct file_operations fops = { .read = device_read, .write = device_write, .ioctl = device_ioctl,
And the device_ioctl function device_ioctl defined differently compared to the user space interface:
static long device_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
I think that based on the file descriptor, the kernel can get the appropriate file structure and calls the ioctl device.
Is this just an assumption because I cannot find this definition of a generic function when the kernel selects the appropriate ioctl function based on the file descriptor fd passed to the generic ioctl interface? There are only 3 ioctl definitions that I can find, but apparently these are just device definitions, not the kernel: ioctl
Amumu source share