Wu.Country@侠缘

勤学似春起之苗,不见其增,日有所长; 辍学如磨刀之石,不见其损,日所有亏!

导航

[译]5.6. Module Options 模块选项

目录: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.
重视, 考虑

 

 

posted on 2009-02-17 22:35  Wu.Country@侠缘  阅读(438)  评论(0编辑  收藏  举报