Devices

Since everything in Linux is represented as file, the devices are no exception. Every device file in Linux resides in the /dev directory. These device files are needed to direct input and output through them. The device files actually contain no data, they serve only as a linking bridge between the user and the device itself. They only inform about the location of the device and communicate with it.

Device names

Here is a list of common device names in Linux systems:

  • CD-ROM: /dev/cdrom, /dev/cdroms/cdrom, if SCSI possible /dev/sda1/2.
  • Floppy disk: /dev/fd0, /dev/floppy
  • SCSI drives: /dev/sda, the first SCSI drive.
  • IDE Hard drive 1: /dev/hda. The partitions are added as numbers. The first partition would be /dev/hda0, the second /dev/hda1 and so on.
  • IDE Hard drive 2: /dev/hdb. The partition numbering is same as in the upper example.
  • Mouse: /dev/mouse, /dev/psaux for ps2 device, /dev/cua for serial device, /dev/ttyS0
  • Printers: /dev/lp0 (lpt1)

And the usual disk device names:

  • Primary IDE master: /dev/hda
  • Primary IDE slave: /dev/hdb
  • Secondary IDE master: /dev/hdc
  • Secondary IDE slave: /dev/hdd

Types of devices

There are four types of devices:

  • c: character
  • u: unbuffered character
  • b: block
  • p: FIFO

Unbuffered/character devices are the devices which transfer data as a stream of bytes. Such devices would be a terminal or a printer. Block devices transfer data in blocks of fixed length. They are opposite of the character devices. The disk drives are example of block devices. FIFO stands for First In First Out. When using a FIFO device, the data which first got in, will be the first which will get out. FIFO devices allow simultaneous memory data write and read operations.

Installation

In order for some device to work, it has to be supported by the kernel. So, when building your kernel, make sure that the appropriate support is enabled. For instance, if you use USB devices, enable USB support and so on. If the kernel support is enabled, and the device is plugged in, then the device modules should be loaded automatically. If not, then you can load the appropriate modules using the insmod command. Insmod actually installs a loadable module into the kernel. For instance:

$insmod module_name.o

should load the specified module name into the kernel. Software like hotplug and coldplug help in recognizing devices and loading the modules into the kernel automatically.

Device Drivers

In order to explain the device drivers, the term controller should be well understood. Controller is the hardware which controls and observe the communication between the system and the device itself. It does usually low-level operations, like error checking, data transfer, location of data etc. For the controller to operate successfully, the device drivers must be installed. A driver is nothing more then a software which controls the controller. The driver software must match the type and the version of the device you would like to use. Device driver performs: probe, attach, open, close, read, write, reset, stop, timeout, select, strategy, dump, psize, ioctl, process transmit and receive interrupts to the device in use.

Making a device

A device could be made with the mknod command. It takes several parameters:

$mknod device device_type major_number minor_number

A real-life example:

$mknod /devices/psaux c 10 1.

The first parameter is the device name ( in the example, psaux). The second parameter is the type of device, already discussed ( c - character type). The last two parameters are the major and the minor number. The major number identifies the kernel driver which communicates with the device, while the minor number specifies the location of the device, it identifies which particular instance of the given device type is to be addressed. The major number directs the user to the proper controller and mode. The minor number is divided in ranges. If its value is from 0 up to 7, then it directs to portions of drive 0, from 8 to 15 it directs to portions of drive 1 and so on.

handbook/handbook/device.txt · Last modified: 2014/11/21 12:10 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: GNU Free Documentation License 1.3
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki