Still another responsibility for the kernel is hardware management. Any device that the Linux system must communicate with needs driver code inside the kernel code. The driver code allows the kernel to pass data back and forth to the device, acting as a intermediary between applications and the hardware. Two methods are used for inserting device driver code in the Linux kernel:
• ompiled in the kernel
• Driver modules added to the kernel
Previously, the only way to insert a device driver code was to recompile the kernel. Each time you added a new device to the system, you had to recompile the kernel code. This process became even more inefficient as Linux kernels supported more hardware. Fortunately, Linux developers devised a better method to insert driver code into the running kernel.
Programmers developed the concept of kernel modules to allow you to insert driver code into a running kernel without having to recompile the kernel. Also, a kernel module can be removed from the kernel when the device is finished being used. This improvement greatly simplified and expanded the use of hardware with Linux.
The Linux system identifies hardware devices as special files, called device files. There are three classifications of device files:
• Character
• Block
• Network
Character device files are for devices that can handle data only one character at a time. Most types of modems and terminals are created as character files. Block files are for devices that can handle data in large blocks at a time, such as disk drives.
The network file types are used for devices that use packets to send and receive data. These devices include network cards and a special loopback mechanism that allows the Linux system to communicate with itself using common network programming protocols.
Linux creates special files, called nodes, for each device on the system. All communication with the device is performed through the device node. Each node has a unique number pair that identifies it to the Linux kernel. The number pair includes a major and a minor device number. Similar devices are grouped into the same major device number. The minor device number is used to identify a specific device within the major device group. This is an example of device files on a Linux server:
test@testbox~$ ls -al sda*
brw-rw---- 1 root disk 8, 0 2008-05-07 11:42 /dev/sda
brw-rw---- 1 root disk 8, 1 2008-05-07 11:42 /dev/sda1
brw-rw---- 1 root disk 8, 2 2008-05-07 11:42 /dev/sda2
brw-rw---- 1 root disk 8, 5 2008-05-07 11:42 /dev/sda5
test@testbox~$ ls -al ttyS*
crw-rw---- 1 root dialout 4, 64 2008-05-07 11:42 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 2008-05-07 11:42 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 2008-05-07 11:42 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 2008-05-07 11:42 /dev/ttyS3
test@testbox~$
The sda device is the first SCSI hard drive, and the ttyS devices are the standard IBM-PC COM ports. The list shows all of the sda devices that were created on the sample Ubuntu system. Similarly, the list shows all of the ttyS devices created.
The fifth column is the major device node number. Notice that all of the sda devices have the same major device node, 8, while all of the ttyS devices use 4. The sixth column is the minor device node number. Each device within a major number has a unique minor device node number.
The first column indicates the permissions for the device file. The first character of the permissions indicates the type of file. Notice that the SCSI hard drive files are all marked as block (b) device, while the COM port device files are marked as character (c) devices.
Source of information : Wiley Ubuntu Linux Secrets
No comments:
Post a Comment