储蓄卡怎么销户:揭秘linux驱动程序----都是关于模块
来源:百度文库 编辑:中财网 时间:2024/05/12 12:16:54
揭秘linux驱动程序----都是关于模块
在这一篇文章里面,作者讲述了linux系统稳定、方便的原因是-----模块化。然后,简要介绍了对模块的相关操作Tags:编程 | | linux驱动程序 | 模块Linux Device Drivers Demystifiedlinux Device Drivers Demystified
All About Moduless
James AndrewsJames Andrews
Thursday, September 23, 1999 12:49:47 PMThursday, September 23, 1999 12:49:47 PM
Another much-trumpeted advantage of Linux is that it does not need to be rebooted as often as other operating systems. You might think that this is due to its rock solid stability. You may think I am now going to talk about the quality of the device drivers. But you'd be wrong. The reason that Linux device drivers lead to less rebooting is that we can reconfigure, load or unload them without restarting the system.
Linux系统另一种广为人知的优势是-----它并不需要像其他操作系统那样,总是要重启(想一想,我们在windows下安装某些软件或驱动的时候,都是要重启系统才可以使软件完整地生效。)。你或许认为这是因为linux那岩石搬坚固的稳定性造就的。你也许认为,我准备谈论设备驱动程序的质量。如果你那样想的话,那么,你就错了。安装了linux设备驱动程序,然后并不需要重启系统的原因是,我们可以在不用重启动操作系统的基础下重新配置驱动,载入或者是卸掉它们。
To do this modular kernel drivers are used.
要实现上面的那种功能,就必须用到模块化的内核驱动程序。
How to load a module
如何载入一个模块
Most people configure their modules at install time and then leave them alone. All the major distributions have taken to modules because of another advantage they have: size. Distribution makers want to support all the possible cards and devices that Linux can. If we compiled all these into the kernel it would be huge. If several different static kernels for different devices were supplied then they would take up too much space, as well. With the modular system distribution makers supply a stripped down kernel plus a comprehensive set of device drivers. This typically only occupies two or three floppy disks in total.
很多人,在安装他们需要的模块的时候进行配置,完成之后,就不用再去理它们了。所有,主要的linux操作系统发行版,都采用了模块化的机制,因为,这让它们有另外的优势:系统大小(意思是说,在发行系统的时候,只发行核心的部分,其他,驱动程序方面的,你在需要的时候再自行载入。)。发行商,想让他们发行的linux操作系统,尽可能支持所有的扩展卡和设备。
如果发行商的确提供了几种支持一定数量的设备,内核定制好的linux操作系统(就是它支持的设备的驱动程序已经编译进内核了),那么这样的话操作系统的是很大的(很占磁盘空间的)。
采用模块化机制的系统,发行商可以提供一个只包含基本功能的操作系统,外加一系列linux设备驱动程序(这是不编译进内核的)。这种发行的操作系统大小只占两个或三个软盘。
modprobe, lsmod and insmod
if you want to load a module after system setup time, then the easiest way is as follows:
如果你想在系统设置好之后,再添加一个模块到系统中,那么,最简单的办法是:
modprobe hfs
This example loads the Apple Mac disk subsystem driver (called hfs) with the modprobe command. If the module takes parameters, like IRQ numbers, then you can specify them with modprobe too.
这个例子,用modprobe命令为苹果机上的系统,添加一个磁盘子系统驱动模块。如果(在添加)这一个模块时需要用到参数,比如系统中断请求号(每个系统都提供了一组中断请求,每个中断请求都有一个编号),那么你也可以通过modprobe命令来指定相应的中断请求号。
To see what modules are loaded and to see information on how they depend on each other we use lsmod. Here is some example output from lsmod.
我们可以使用lsmod命令来查看系统中都安装了哪些模块,还有这些模块之间的关联性,依赖性。下面是使用lsmod命令后的输出结果:
Module Size Used bygus 45016 0
mad16 6564 0
sb 31416 0
ad1848 15112 0 [mad16]
uart401 5588 0 [mad16 sb]
sound 54368 0 [gus mad16 sb ad1848 uart401]
In this example the mad16 kernel device driver depends on the ad1848 device driver.
在这个例子里面,mad16内核设备驱动程序依赖于ad1848驱动。
Yes, there really is a mad16 device driver. It is a soundcard chipset.
的确,存在一个mad16设备驱动程序,它是驱动一组声卡芯片的。
/etc/modules, /etc/conf.modules
In the normal course of events the modules we asked for when Linux was installed are loaded at boot time. To achieve this the file /etc/modules is used. This is a list of modules to be loaded.
在通常情况下,我们在安装linux系统的时候,会编译一部分我们需要的驱动模块到系统中,这样的模块,在每次系统启动时都会载入(我们可以选择一些驱动模块不载入,在系统启动时)。
要达到这样的功能,我们就要用到/etc目录下的modules文件,这个文件里面列出了在系统启动时要载入的模块(我在自己的fedora系统中,在/etc目录下并没有找到这个modules文件,或许是因为系统版本不同吧。)。
The options for the modules are stored in /etc/conf.modules. Recommended practice is to not edit /etc/conf.modules, however, but to use a script like update-modules; see the man pages for more details.
所有模块的配置信息都存在/etc目录下的conf.modules文件中。建议不要手动去编辑这个conf.modules文件,不过呢,可以通过一个脚本来修改配置conf.modules,比如更新模块的脚本(这个作者点出的脚本update-modules应该是要自己编写的,并没有现成的可以给我们修改)。
要想了解更多的细节,可以查看man手册。