Ioctl

From Wikipedia, the free encyclopedia

The correct title of this article is ioctl. The initial letter is shown capitalized due to technical restrictions.

In computing, the system call ioctl (IPA: [ˌaɪˈɑktl̩]), found on Unix-like systems, allows an application to control or communicate with a device driver outside the usual read/write of data. This call originated in AT&T Unix version 7. Its name abbreviates the phrase Input/output control.

An ioctl call takes as parameters:

  1. an open file descriptor
  2. a request code number
  3. either an integer value, possibly unsigned (going to the driver) or
    a pointer to data (either going to the driver or to come back from it).

The kernel generally dispatches an ioctl straight to the device driver, which can interpret the request number and data in whatever way required. The writers of each driver document request numbers for that particular driver and provide them as constants in a header file. Some systems have conventions encoding the size of the data in the number, and whether the processing involves input or output.

TCSETS exemplifies an ioctl on a serial port. The normal read and write calls on a serial port receive and send data bytes. An ioctl(fd,TCSETS,data) call, separate from such normal I/O, controls various driver options like handling of special characters, or the output signals on the port (such as the DTR signal).

[edit] References