Device Drivers, Introduction Following the “everything is a file” Unix™ tradition, device drivers are used to allow user code access to kernel functions controlling a number of peripheral components. There are 3 classes for device drivers character drivers block drivers network drivers Character drivers are widely use for a number of simple and more sophisticated applications. These range from simple led flashers to IEEE1394 ( firewire ) and USB (Universal Serial Bus) drivers. Block drivers interface to the file system and are used to mount things like disk partitions. They differ from simple character drivers in that access to the device data is usually buffered by the kernel. Network drivers have a different structure and are closely connected with the network stacks that can be built into the kernel. They use ports and sockets to route data packets within, as well as to and from the system. The user is normally not allowed to execute kernel code or access Input/Output (I/O) devices. When this functionality is required an application should use a device driver. They are quite easy to build and very fast to run so consider creating a device driver for all your I/O needs. A device driver can be a module or it can be statically linked into the kernel. An appropriate kernel registration function is executed during the module init process. (Replacing the simple printk used in the module example.) This function passes pointers to one or more functions internal to the driver and may include some other parameters. A device driver will register the following components: a fops table a Major Number a Device Class (block or char) a name Special files called device nodes are created on a file system that hold the class, Major and Minor number of a particular device. The device driver registers a number of callback functions that are used to extend the default behaviour of the kernel when accessing these device nodes. These functions are recorded in a file operations table. The open system call retrieves that Major number and then looks for a device registered by the Major number in the device table to recover the fops table for the device. This information is then recorded in a special per process table called the file descriptor table. The process uses a simple integer index (fd) to access the file descripter table entry after it has been opened. [../images/ddfig1.gif] FIXME