Is it possible to call ioctl
from a Linux kernel module?
Can anyone provide an example of how it\'s used?
You can try to call sys_ioctl
.
It's exported if the kernel is compiled with CONFIG_COMPAT
.
Or, if you have the device driver's struct file_operations
, you can call its ioctl
handler directly.
However, the ioctl handle would expect pointer parameters to be in the address space of the process currently running, not in the kernel address space. copy_from_user
would be used to read them. If you give pointers to the kernel address space, copy_from_user
will fail. I don't see how you would get around this.
Edit:
If you will call ioctl handler between below code than copy_from_user
will not ever fail.
mm_segment_t fs;
fs = get_fs(); /* save previous value */
set_fs (get_ds()); /* use kernel limit */
/* system calls can be invoked */
set_fs(fs); /* restore before returning to user space */