Chapter 5. Enhanced Char Driver Operations
In Chapter 3, we built a complete device driver that the user can write to and read from. But a real device usually offers more functionality than synchronous read and write. Now that we’re equipped with debugging tools should something go awry, we can safely go ahead and implement new operations.
What is normally needed, in addition to reading and writing the device, is the ability to perform various types of hardware control via the device driver. Control operations are usually supported via the ioctl method. The alternative is to look at the data flow being written to the device and use special sequences as control commands. This latter technique should be avoided because it requires reserving some characters for controlling purposes; thus, the data flow can’t contain those characters. Moreover, this technique turns out to be more complex to handle than ioctl. Nonetheless, sometimes it’s a useful approach to device control and is used by tty’s and other devices. We’ll describe it later in this chapter in Section 5.1.7.
As we suggested in the previous chapter, the ioctl system call offers a device specific entry point for the driver to handle “commands.” ioctl is device specific in that, unlike read and other methods, it allows applications to access features unique to the hardware being driven, such as configuring the device and entering or exiting operating modes. These control operations are usually not available through the read/write ...