Device Files

 < Day Day Up > 

Device files are a way to access system devices. An application that uses a device doesn't need to know about the underlying device and how it works. When you access a device file the kernel manages the I/O request and passes it to the device driver. The device driver then performs an operation such as sending data to a tape drive. The device driver is built into the kernel which allows the kernel to manage access to the device.

This section covers some important aspects of device files, including the following:

  • Some commonly used device files.

  • The structure of device files.

  • An example of creating a device file.

Generally speaking, device files on Linux systems are character or block devices. Character devices expect the driver and other aspects of the Linux system to manage input and output buffering of data. Block devices expect the file system and kernel to perform buffering for them. Most hard disk drives have both a block and character device file. This provides flexibility in the way in which the hardware is used.

A device file provides the Linux kernel with important information about a specific device. The Linux kernel needs to know a lot about a device before input/output operations can be performed.

Device files are located in /dev on Linux systems. You've already seen many device files loading the operating system and performing other tasks. For instance, the SCSI disk on which you loaded Linux on an Integrity server is /dev/sda; the IDE drive on which you loaded Linux is /dev/hda. There are many other device files of which you should be aware. There may also be a subdirectory under /dev used to further categorize the device files such as /dev/inet. Table 10-2 lists some of the more commonly used device files along with a comment for each.

Table 10-2. Examples of Linux Device Files

Device

Comments

/dev/hda

First IDE hard drive

/dev/hda1

Primary partition 1 of first IDE hard drive (next is 2 and so on)

/dev/hdb

Second IDE hard drive (next is c and so on)

/dev/hdb1

Primary partition 1 of second IDE hard drive (next is 2 and so on)

/dev/sda

First SCSI hard drive

/dev/sda1

Primary partition 1 of first IDE hard drive (next is 2 and so on)

/dev/sdb

Second SCSI hard drive (next is c and so on)

/dev/sdb1

Primary partition 1 of second SCSI hard drive (next is 2 and so on)

/dev/fd0

First floppy drive (A:)

/dev/st0

SCSI tape drive.

/dev/ttyS0

Serial port on COM1


Although many other device files exist on your system, these are some of the more commonly used ones.

As described earlier, a device file provides the Linux kernel with important information about a specific device. The Linux kernel needs to know a lot about a device before Input/Output operations can be performed.

There is some embedded information that is part of the device file that you need to know should you decide to create your own device file. You need to know some of this information if you were to create your own device file using the mknod command. Before you create a device file, list the installed hardware on an IA-32 system with the lsdev command:

 # lsdev Device              DMA   IRQ   I/O Ports ------------------------------------------------ 00:11.0                         fc80-fcff 3Com                            fc80-fcff cascade               4     2 dma                             0080-008f dma1                            0000-001f dma2                            00c0-00df eth0                        9 fpu                             00f0-00ff ide0                       14   01f0-01f7 03f6-03f6 ffa0-ffa7 ide1                       15   0170-0177 0376-0376 ffa8-ffaf Intel                           ff80-ff9f ffa0-ffaf isapnp                          0213-0213 0a79-0a79 keyboard                    1   0060-006f Mouse                      12 PCI                             0cf8-0cff pic1                            0020-003f pic2                            00a0-00bf rtc                         8   0070-007f serial                          03f8-03ff timer                       0   0040-005f usb-uhci                   10   ff80-ff9f vga+                            03c0-03df # 

This lsdev listing shows installed hardware and some relevant information for each. Notice though, that devices such as hda are not shown. A lot of information about device files is not shown in lsdev.

Looking at the device files in /dev can reveal a lot of information about any given device. The following is the format of the mknod (short for make node) command that is used to manually create device files if they are not already on your system:

 mknod   name   type [major]   [minor] 

Now dissect a device file in /dev. The following is a long listing for a SCSI tape drive device file:

 # ls -al /dev/st0 crw-rw----    1 root      disk       9,   0 Aug 30 19:31 /dev/st0 

This device has a name of /dev/st0. It is a character device as indicated by the c (as opposed to a block device b or a named pipe p,) has a major number of 9 which corresponds to a SCSI tape drive, a minor number of 0 which corresponds to the drive number. If this device did not exist, the mknod command to create it would look like the following:

 # mknod /dev/st0 c 9 0 

After executing this command, you have the SCSI tape device file we need. Figure 10-2 shows the components in our mknod command.

Figure 10-2. mknod Command


You'll see the device name, type of device, major and minor numbers when you view a device in /dev.

You may never have to create a device file on your system; however, it is good to have some background on device files. You will certainly have to use many device files, such as your hard disks, floppy disks, tape drives, and so on. Therefore, at a minimum you need to know the name you'll use to access these devices.

     < Day Day Up > 


    Linux on HP Integrity Servers. A System Administrator's Guide
    Linux on HP Integrity Servers: A System Administrators Guide
    ISBN: 0131400002
    EAN: 2147483647
    Year: 2004
    Pages: 100

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net