Linux 驅動框架---模塊參數
Linux 模塊的參數
通過在內核模塊中定義模塊參數從而可以在安裝模塊時通過insmod module_name paramname=param形式給模塊傳遞參數。如果安裝模塊是傳參數則將使用模塊內定義的缺省值。并且最后的/sys/module/目錄下會呈現出來進行讀寫(當讀寫權限為0時不會出現在目錄中)。
定義方式
定義單個參數
1. 定義變量(像定義普通變量的方式一樣定義變量)。
2. 使用后module_param 聲明模塊變量如module_param(param_name,param_type,RW Authority )。
eg:
static char* param_name="xxxxxxx"
module_param(param_name,charp,S_IRUGO)
定義參數組
1. 定義數組變量(像定義普通數組變量的方式一樣定義變量)。
2. 使用后module_param_array 聲明模塊變量
eg:
static int param_name[cnt]="xxxxxxx"
module_param_array(param_name,cnt,charp,S_IRUGO)
參數類型
- byte 字節參數
- short 有符號半字參數
- ushort 無符號半字參數
- int 有符號整形參數
- uint 無符號整形參數
- long 有符號長整形參數
- ulong 無符號長整形參數
- charp 字符指針
- bool bool值
權限
可以使用Linux定義的權限宏或運算組合,也可以使用權限位的數字如0644來表示。
- S_IRUSR
Permits the file's owner to read it. - S_IWUSR
Permits the file's owner to write to it. - S_IRGRP
Permits the file's group to read it. - S_IWGRP
Permits the file's group to write to it

浙公網安備 33010602011771號