Hmmmm... I guess I'll discuss ioctl today...
Maybe it's worth delving a little bit deeper into device drivers. Last time, we talked about the driver implementing the syscall interface for a device file. A natural question arises: is that interface sufficient? Would I only ever want to read from, write to, open, mmap, etc. a device file (Note: Those system calls are relevant for character devices. Let's ignore block devices for the time being.)?
Well, probably not, and that answer is the impetus for the development of ioctl. ioctl is a specific system call for device files that allows one to execute custom functionality specific to the device and not captured by other system calls. The signature from the sys/ioctl.h header is here as follows:
int ioctl(int fd, unsigned long request, ...) (from https://man7.org/linux/man-pages/man2/ioctl.2.html)
Here, fd is a file descriptor, or an id referring to an open file, our device file. The request argument refers to the specific custom call implemented in the driver. The driver is responsible for implementing the ioctl call to provide support for such codes.
Comments
Post a Comment