http://www.ruixuedz.com.cn/article/dc/155.html
---------------------------------------------------------------------
module_param(name, type, perm)是一個宏,向當前模塊傳入參數,對源碼分析如下
在include\linux\moduleparam.h中
#define module_param(name, type, perm) \
module_param_named(name, name, type, perm)
#define module_param_named(name, value, type, perm) \
param_check_##type(name, &(value)); \
module_param_call(name, param_set_##type, param_get_##type, &value, perm); \
__MODULE_PARM_TYPE(name, #type)
#define module_param_call(name, set, get, arg, perm) \
__module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm)
#define __module_param_call(prefix, name, set, get, arg, perm) \
/* Default value instead of permissions? */ \
static int __param_perm_check_##name __attribute__((unused)) = \
BUILD_BUG_ON_ZERO((perm) < 0 || (perm) > 0777 || ((perm) & 2)); \
static char __param_str_##name[] = prefix #name; \
static struct kernel_param const __param_##name \
__attribute_used__ \
__attribute__ ((unused,__section__ ("__param"),aligned(sizeof(void *)))) \
= { __param_str_##name, perm, set, get, arg }
__attibute__ 是gcc的關鍵字,可參考
http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Variable-Attributes.html
__attibute__將參數編譯到__param段中,
module_param是一步一步展開的,
上面幾個宏在include\linux\moduleparam.h中的順序剛好相反
module_param宏的類似函數調用的順序
module_param->module_param_named->module_param_call->__module_param_call
展開的順序正好相反
__module_param_call->module_param_call->module_param_named->module_param
type類型可以是byte,short,ushort,int,
uint,long,ulong,charp(注:字符指針),bool,invbool,
perm表示此參數在sysfs文件系統中所對應的文件節點的屬性。
權限在include/linux/stat.h中有定義
比如:
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
當perm為0時,表示此參數不存在 sysfs文件系統下對應的文件節點。