The ioctl(2) and fcntl(2) mechanisms provide a way to write
hooks into a device driver. The original, historical use of ioctl(2)
was to set parameters like baud rate and number of framing bits in a
serial-communications driver, thus the name (for ‘I/O
control’). Later, ioctl calls were added for other driver
functions, and fcntl(2) was added as a hook into the
file system.
Over the years, ioctl and
fcntl calls have proliferated. They are
often poorly documented, and often a source of portability problems as
well. With each one comes a grubby pile of macro definitions
describing operation types and special argument values.
The underlying problem is the same as ‘big bag of
bytes’; Unix's object model is weak, leaving no natural places
to put many auxiliary operations. Designers have an untidy choice
among unsatisfactory alternatives; fcntl/ioctl going
through devices in /dev, new
special-purpose system calls, or hooks through special-purpose virtual
file systems that hook into the kernel (e.g. /proc under Linux and elsewhere).
It is not clear whether or how Unix's object model will be
enriched in the future. If MacOS-like file attributes become a common
feature of Unix, tweaking magic named attributes on device drivers may
take over the role ioctl/fcntl now have (this would at least have the
merit of not requiring piles of macro definitions before the interface
could be used). We've already seen that Plan 9, which uses the named
file server or file system as its basic object, rather than the
file/bytestream, presents another possible path.
[an error occurred while processing this directive]