Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


Names are assigned to device files because users (humans) find it easier to
remember symbolic names rather than numbers. However, the actual functionality
of a device file isnotdenoted by its name but exclusively by its major and minor
number. Neither is the directory in which a device file is located of any relevance.
(Nevertheless, a standard way of naming files has been adopted.)mknodis used to
create device files. How this is done is described in the standard literature on
system administration.

The kernel employs the major and minor numbers to identify the matching driver. The reason why two
numbers are used is because of the general structureof a device driver. Firstly, the system may include
several devices of the same type that are managed by a single device driver (it wouldn’t make sense
to load the same code into the kernel more than once). Secondly, devices of the same category can be
combined so that they can be inserted logically into the kernel’s data structures.

The major number is used to address the device driver itself. For instance, as we can see in the above
example, the major number of the first SATA controller on which diskssdaandsdbare located is 8. The
individual devices of the drive (that is, the primary and secondary disk) are designated by the different
minor numbers; 0 forsdaand 16 forsdb. Why is there such a big gap between both numbers? Let’s look
at the remaining files that refer to thesdadisk in the/devdirectory.

wolfgang@meitner>ls -l /dev/sda*
brw-r----- 1 root disk 8, 0 2008-02-21 21:06 /dev/sda
brw-r----- 1 root disk 8, 1 2008-02-21 21:06 /dev/sda1
brw-r----- 1 root disk 8, 2 2008-02-21 21:06 /dev/sda2
brw-r----- 1 root disk 8, 5 2008-02-21 21:06 /dev/sda5
brw-r----- 1 root disk 8, 6 2008-02-21 21:06 /dev/sda6
brw-r----- 1 root disk 8, 7 2008-02-21 21:06 /dev/sda7
As you know, individualpartitionsof a disk can be addressed by means of device files/dev/sda1,
/dev/sda2, and so on, whereas/dev/sdarefers to theentiredisk. Consecutive minor numbers are used to
identify partitions so that the driver is able to distinguish between the different versions. A single driver
can reserve more than one major number. If two SATA buses are present in the system, the second SATA
channel gets a different major number from the first one.

The division just described also applies for character devices, which are likewise represented by a major
andaminornumber.Forexample,themajornumberof the driver for the serial interface is 4, and the
individual interfaces have a minor number from 64 onward.

Each major number is allocated tobotha block device and a character device.
Consequently, the information needed to select the correct driver is not unique
unless both the number and the type of the device (block or char) are specified.

In the early days of Linux, major numbers were allocated in a very lax way (at the time, there were
only a small number of drivers), but the allocation of major and minor numbers for new drivers is now
regulated by a more or less official organization. Drivers that did not use the major numbers registered
in this list to identify their devices cannot and are not included in the standard distribution of kernel
sources.

The current list can be obtained athttp://www.lanana.org. This rather strange-sounding URL stands for
Linux assigned name and numbers authority. The standard distribution of kernel sources also includes the
Free download pdf