Implementation of loctls

Ioctls permit the use of special device-specific functions that cannot be accessed by normal read and write operations. This form of support is implemented by means of the ioctl system call that can be used with regular files (detailed descriptions of how it is used are provided in the many system programming manuals).

As expected, the system call is implemented in sys_ioctl, but the main work is done in vfs_ioctl. Figure 6-19 shows the associated code flow diagram.

Figure 6-19: Code flow diagram for sys_ioctl.

The desired ioctl is specified by means of a passed constant; typically, symbolic pre-processor constants are used for this purpose.

Two situations must be distinguished once the kernel has checked whether one of the standard ioctls has been applied (these are available for all files in the system regardless of type); for example, whether the file descriptor is to be closed when exec is executed (see Chapter 2).

□ If the file is a regular file, file_ioctl is invoked. The function first checks a number of standard ioctls that are always implemented for this file type (figetbsz, for example, to query the block size used by the file). do_ioctl is then used to invoke the file-specific ioctl function in the file_operations (if it exists) to process the ioctl (regular files do not usually provide a ioctl function so that the system call returns an error code).

□ If the file is not a regular file, do_ioctl and therefore the file-specific ioctl methods are invoked immediately; the method for block device files is blkdev_ioctl.

blkdev_ioctl also implements some ioctls that must be available for all block devices; for instance, a request to read the partitioning data or a method of determining the total size of the device. Thereafter the device-specific ioctls are processed by invoking the ioctl method in the file_operations of the gendisk instance. This is where driver-specific commands, such as the eject medium command for CD-ROMs, are implemented.

Continue reading here: Tree Data Structures

Was this article helpful?

0 0