Linux 驅動框架---模塊參數

Linux 模塊的參數

經過在內核模塊中定義模塊參數從而能夠在安裝模塊時經過insmod module_name paramname=param形式給模塊傳遞參數。若是安裝模塊是傳參數則將使用模塊內定義的缺省值。而且最後的/sys/module/目錄下會呈現出來進行讀寫(當讀寫權限爲0時不會出如今目錄中)。linux

定義方式

定義單個參數

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
相關文章
相關標籤/搜索