目錄:http://www.cnblogs.com/WuCountry/archive/2008/11/15/1333960.html
[不提供插圖,讀者最好從網上下載源書]
5.5. Initialization Options 初始化選項
Both components built into the kernel and components loaded as modules can be passed input parameters so that users can fine-tune the functionality implemented by the components, override defaults compiled into them, or change them from one system boot to the next. The kernel provides two kinds of macros to define options :
不管是編譯到核心中的組件,還是以模組的形式載入的組件,使用者都可以通過輸入參數來調整組件給我們提供的功能。重載編譯到組件中的預設值,或者在後來的系統啟動時修改它們。核心給我們提供了兩個宏來定義選項:
Module options (macros of the module_param family)
模組選項 module_param家族宏
These define options you can provide when you load a module. When a component is built into the kernel, you cannot provide values for these options at kernel boot time. However, with the introduction of the /sys filesystem, you can configure the options via those files at runtime. The /sys interface is relatively new, compared to the /proc interface. The later section "Module Options" goes into a little more detail on these options.
當你載入一個模組時,可以提供這些定義選項。當一個組件編譯到核心時,你不能在核心啟動時為這些組件提供值。然而,通過介紹/sys檔案系統,你可以在運行時通過這些檔案來配置這些選項。與/proc介面相比,/sys介面相對是新的方法。在後面一節,“模組選項”會進一步詳細的討論這些選項。
Boot-time kernel options (macros of the _ _setup family)
啟動時核心選項(__seup家族宏)
These define options you can provide at boot time with a boot loader. They are used mainly by modules that the user can build into the kernel, and kernel components that cannot be compiled as modules. You will see those macros in the section "Boot-Time Kernel Options" in Chapter 7.
你可以在核心啟動時,通過bootloader提供這些定義選項。這些主要是給那些使用者編譯到核心中的模組使用,以及那些可以編譯成模組的核心組件。你會在第7章的“啟動時核心選項”這一節中看到這些宏。
It is interesting to note that a module can define an initialization option in both ways: one is effective when the module is built-in and the other is effective when the module is loaded separately. This can be a little confusing, especially because different modules can define passing parameters of the same name at module load time without any risk of name collision (i.e., the parameters are passed just to the module being loaded), but if you pass those parameters at kernel boot time, you must make sure there is no name collision between the various modules' options.
值得注意是,當一個模組可以通過兩種方法定義一個初始化選項時:一個是在編譯到時起作用,另一個是在模組獨立載入時起作用。這可能會有些混淆,特別是因為不同的模組可以定義成在載入時傳同樣名字的參數而沒有任何名字衝突的風險(例如,這些被傳遞的參數只是用於模組載入),但如果你在核心啟動時傳遞這些參數,你必須確保這些參數名與模組的選項沒有衝突。
We will not go into detail on the pros and cons of the two approaches. You can look at the drivers/block/loop.c driver for a clear example using both module_param and _ _setup.
我們不會對prod和codns這兩個方法做詳細的討論。你可以在drivers/block/loop.c中看到詳細的驅動例子,它們使用了module_param和__setup.