目錄:http://www.cnblogs.com/WuCountry/archive/2008/11/15/1333960.html
[不提供插圖,讀者最好從網上下載源書]
5.6. Module Options 模組選項
Kernel modules define their parameters by means of macros such as module_param; see include/linux/moduleparam.h for a list. module_param requires three input parameters, as shown in the following example from drivers/net/sis900.c:
核心模組通過宏的含義來定義他們的參數,例如module_param,參見include/linux/moduleparam.h裡有一個列表。moule_param需要本三個參數來輸入模組參數,下面是從drivers/net/sis00.c裡的一個例子:
...
module_param(multicast_filter_limit, int 0444);
module_param(max_interrupt_work, int, 0444);
module_param(debug, int, 0444);
...
The first input parameter is the name of the parameter to be offered to the user. The second is the type of the parameter (e.g., integer), and the third represents the permissions assigned to the file in /sys to which the parameter will be exported.
第一個輸入的參數是提供給使用者的使用的模組參數名。第二個參數是模組參數的資料類型,而第三個參數就是指定參數是否暴露給使用者通過/sys檔案來訪問。
This is what you would get when listing the module's directory in /sys:
這些就是你可以從一個模組的目錄裡得到的:
[root@localhost src]# ls -la /sys/module/sis900/parameters/
total 0
drwxr-xr-x 2 root root 0 Apr 9 18:31 .
drwxr-xr-x 4 root root 0 Apr 9 18:31 ..
-r--r--r-- 1 root root 0 Apr 9 18:31 debug
-r--r--r-- 1 root root 4096 Apr 9 18:31 max_interrupt_work
-r--r--r-- 1 root root 4096 Apr 9 18:31 multicast_filter_limit
[root@localhost src]#
Each module is assigned a directory in /sys/modules. The subdirectory /sys/modules/module/parameters holds a file for each parameter exported by module. The previous snapshot from drivers/net/sis900.c shows three options that are readable by anyone, but not writable (they cannot be changed).
每一個模組都在/sys/modules裡給定了一個目錄。/sys/modules/module/parameters這個子目錄就為模組暴露的每個參數儲存了一個檔案,前面的快照就是drivers/net/sis900.c中的,顯示了三個任何人都可以讀取的選項。但不能修改。
Permissions on /sys files (and on /proc files, incidentally) are defined using the same syntax as common files, so you can specify read, write, and execute permissions for the owner, the group, and everybody else. A value of 400 means, for example, read access for the owner (who is the root user) and no other access for anyone. When a value of 0 is assigned, no one has any permissions and you would not even see the file in /sys.
/sys檔案(順便說一下,/proc檔案也一樣)的存取權限可以用普通檔案同樣的文法來定義。所以,你可以為檔案的所有者,組,或者所有人指定讀,寫,以及執行許可權。例如,一個400的值就是指所有者的讀許可權(誰是root使用者),而其它人沒有任何許可權。當一個0值被指定時,沒有人被許可,你甚至連/sys裡的檔案都看不到。
If the component programmer wants the user to be able to read the values of parameters, she must give at least read permission. She can also provide write permission to allow users to modify values. However, take into account that the module that exports the parameter is not notified about any change to the file, so the module must have a mechanism to detect the change or be able to cope with changes.
如果組件的程式員想讓使用者可以讀參數的值,他必須至少給一個讀許可權。他也樣可以通過給定寫入權限讓使用者來修改參數的值。然而,考慮模組暴露給使用者的參數不能通過檔案做任何的修改,所以模組必須有一個機制能檢測到這些修改,從而處理這些改變。
For a detailed description of the /sys interface, refer to Linux Device Drivers.
關於/sys介面的詳細介紹,可以參考Linux Device Drivers.
片語 :
take into account
v.
重視, 考慮