In Linux/freeBSD kernel whenever we have to make a driver module for a device, we make a file in the /dev/ folder and use it to communicate with the other processes.
If that is so, what is the purpose of the ioctl set of functions ? Whatever information, we want to convey with the device driver can be written to/read from this file.
Can anyone please explain it ?
I have tried reading about it on tldp.org but couldn't really understand it.
ioctl is used for I/O control, and as an example lets take a serial port. You open the serial port device, and can read from the serial port, and write to the serial port, but how do you set e.g. the baud-rate? Or other control options? It's not possible using read or write as those are for reading and writing data from/to the serial port, you need another function for this, which is where the ioctl function comes in.
It would be possible to just create another device file for "control" tasks and use plain reads/writes on that, instead of ioctl. This way ioctl wouldn't be needed at all. Plan 9 operating system did stuff this way.
Thing is - Unix systems just do it in another way. They always did, and since there isn't anything really wrong with it, and lots of software uses ioctl, why bother changing it?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With