• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Introduction to device drivers and device nodes

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 21次 | 进入软件测试论坛讨论

领测软件测试网
[size=18:e903ff3585][b:e903ff3585]Introduction to device drivers and device nodes[/b:e903ff3585][/size:e903ff3585]

This section provides an overview of the way in which peripheral components use the Unix Input/Output (I/O) subsystem. 

Physical devices, such as disk drives and modems, have a varied command interface and command interpretation. For this reason the Unix operating system defines a standard method of I/O that is used on any type of device that is attached to the system. As we discussed earlier in the course, for the Unix operating system "[b:e903ff3585]everything is a file[/b:e903ff3585]", so devices have special files. 

Adding hardware to a Unix system is essentially a two part problem. The first is a hardware problem; "How do I attach this to the system?" and the second is a software problem "How do I make use of this new hardware from my application?" 

[b:e903ff3585]Hardware connectivity [/b:e903ff3585]
To connect new hardware to Unix systems, the architecture of the Unix system must be considered. Most Unix systems are manufactured with standard interfaces, such as a serial port, a parallel port and an external SCSI bus. These allow many peripherals to be installed without adding additional hardware (or software). However, some peripherals devices will require the addition of an interface card or a controller. 

Interface cards are manufactured for specific bus types. Therefore, when preparing to purchase them, it is good to know the type of bus that is supported by the target Unix system. 

Here are the I/O bus types supported by each vendor's workstations. More specific information about the bus type and other hardware options is distributed by the vendors. 

Sun Microsystems- SparcStations   SBUS, MBUS, and XDBUS
Silicon Graphics- Indy           GIO
Silicon Graphics- Indigo2,Onyx   GIO and EISA
Silicon Graphics- Challenge      HIO and VME64
[b:e903ff3585]Hewlett-Packard 9000 series-    EISA[/b:e903ff3585]
[b:e903ff3585]Intel-based systems (Linux)     ISA, EISA, VESA Local Bus,PCI[/b:e903ff3585]Digital Equipment Corp.-         PCI, TurboChannel

For more optional information about hardware please refer to this Introduction to PC Hardware article which reviews computer hardware in a general way. Contact Unix system vendors for more specific information about hardware support. 

Most systems have a keyboard, mouse and video (framebuffer) interface, but these are not commonly used to add peripherals to the system and will not be considered standard. Some systems have built-in audio and video jacks available but most do not; we will not be covering audio and video peripherals at this time. 

[b:e903ff3585]Standard Unix system interfaces: [/b:e903ff3585]

SparcStations have 2 serial ports for connecting a modem, a printer or an ASCII terminal, a single parallel port for connecting printers, an external micro SCSI connector for connecting disk drives, or removable media drives and a 10BaseT Ethe.net port. 
[b:e903ff3585]HP 9000 Series systems have 2 serial ports, a single parallel port, an external micro SCSI connector and an AUI Ethernet port. [/b:e903ff3585]
SGI Indys have 2 serial ports, a single parallel port, a external micro SCSI connector and both a 10BaseT and AUI Ethernet port. 
[b:e903ff3585]Intel (Linux) systems are very diverse; there is no standard. Most commonly you will find 2 serial ports, a single parallel port, an IDE hard disk controller and a 10BaseT Ethernet port. [/b:e903ff3585]

[b:e903ff3585]Software connectivity [/b:e903ff3585]

A device driver is required as the first step in connecting with a new hardware device. 

The device driver is the software that operates the controller. This software must be available to the kernel if you wish to use the device. The device drivers must match the device that you wish to use. 

When a program attempts to access a device, via the device file, the kernel looks up the appropriate information in its tables, and transfers control to the device driver. The device driver then performs the access request for the device and returns control back to the kernel. 

For more recommend information on device drivers review the following reference.
[i:e903ff3585]Linux Kernel Hackers Guide [/i:e903ff3585]

[b:e903ff3585]Basics of device drivers[/b:e903ff3585]

There are two main types of devices and therefore device nodes, character and block. 

[b:e903ff3585]A block device is one that stores information in fixed size blocks. Common block sizes are between 128 bytes and 1k bytes. Each block may be read independently of the others, so the device allows random access to each block. [/b:e903ff3585]

[b:e903ff3585]Character devices deliver or accept a stream of characters (bytes) without regard to any other structure. Some character devices are keyboards and terminals. [/b:e903ff3585]

Character devices are read from and written to with the functions: [i:e903ff3585]mydev_read() [/i:e903ff3585]and [i:e903ff3585]mydev_write(). [/i:e903ff3585]The [i:e903ff3585]read() [/i:e903ff3585]and [i:e903ff3585]write() [/i:e903ff3585]calls do not return until the operation has been completed. By contrast, block devices do not implement the [i:e903ff3585]read() [/i:e903ff3585]and [i:e903ff3585]write() [/i:e903ff3585]functions; instead they have a strategy function. The strategy function is used to both read and write blocks to the device. 

[b:e903ff3585]Common device file naming conventions [/b:e903ff3585]

In order for the operating system to recognize the hardware device, the device must have a software name, usually referred to as a device special file or device node. The node number on the special file connects it to a specific device driver in the Unix kernel. A device node is created with the command [i:e903ff3585]mknod [/i:e903ff3585]

The device nodes are stored in or have links to the [i:e903ff3585]/dev [/i:e903ff3585]directory. When the [i:e903ff3585]ls -l [/i:e903ff3585]command is used to list these files, their major and minor numbers are displayed. The major number instructs the kernel to call the device specific code associated with the device, and the minor number is passed by the kernel to the device driver to further control the action of the device driver. 

[b:e903ff3585]Special File Names [/b:e903ff3585]
The standard devices for each system and a semi-standard names. For example, in Unix systems: 

[b:e903ff3585]/dev/tty*       terminals
/dev/fd*        floppy disk
/dev/mt*        magnetic tape
/dev/st*        streaming tape
/dev/mouse      mouse[/b:e903ff3585]

A block device can be accessed through an associated "raw" device special file. This allows diagnostics and checks to be performed on the data the device is offering. For example here are a block and character device special file under HP-UX.


brw-r-----   1 root     sys       31 0x002000 Apr  4 08:23 /dev/dsk/c0t2d0
crw-r-----   1 root     sys      188 0x002000 Apr  4 08:23 /dev/rdsk/c0t2d0

Examples of device special files for disk drives for common Unix systems are: 


SunOS 4.x - /dev/{r}sdAP 
SunOS 5.x - /dev/{r}dsk/cCtAd0sS 
IRIX 5.3 - /dev/{r}dsk/dksCdA{sS|vh|vol} 
[b:e903ff3585]HPUX 10.X - /dev/{r}dsk/cCtAd0{sS} [/b:e903ff3585]
Digital Unix - /dev/{r}rzNP 
[b:e903ff3585]Linux - /dev/sdLK [/b:e903ff3585]
Where: A = SCSI address, 
       C = SCSI Controller number, 
       K = DOS primary/extended partition, 
       L = drive letter "a" through "h", 
       N = 8 * controller # + SCSI address, 
       P = BSD-style partition: (a,b,c,d,e,f,g), 
       S = System V-style slice (0,1,2,3,4,5,6).

[Note: Linux device names  and partitioning is quite different 
       from other flavors of Unix. Partition 0, or no partition 
       number, refers to the whole drive. 
       Partitions 1-4 are DOS primary partitions, while partitions 
       5-8 are extended DOS partitions.]



--------------------------------------------------------------------------------
[b:e903ff3585][/b:e903ff3585]

 hpux 回复于:2003-02-21 08:32:57
谁给翻译一下就更好~~~

 Janson-Chen 回复于:2003-02-21 09:12:51
搞小型机的,肯定会看懂吧。

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网