linux驅動開發 模組引數

2021-06-22 12:02:38 字數 950 閱讀 3115

在我們使用模組的時候需要在裝載時傳遞引數給模組,linux 支援在裝載模組的同時傳入引數 。

比如 (num 和who就是傳入模組的引數):

$> insmod hello.ko num=10 who="jack"
模組引數必須用module_parm巨集宣告,這個巨集定義在,剛才連個引數在模組中的定義如下:

static char *who = "world";

static int num = 1;

module_param(num, int, s_irugo);

module_param(who, charp, s_irugo);

核心支援的模組引數型別有:

bool

invbool (true變為false, false變為true)

charp 字元指標

intlong

short

uint

ulong

ushort

s_irugo是訪問許可值,參見中的定義(s_iwugo ,s_ixugo 等)。

示例:

#include #include module_license("gpl");

static int count = 1;

module_param(count, int, s_irugo);

static char *name = "test";

module_param(name, charp, s_irugo);

static __init int a(void)

static __exit void b(void)

module_init(a);

module_exit(b);

$> insmod count=10 name=jacky

linux驅動開發第二帖 模組引數

linux驅動開發之模組引數 1.module param 在使用者態下程式設計可以通過main 的來傳遞命令列引數,而編寫乙個核心模組則通過module param 引數用 module param 巨集定義來宣告,它定義在 moduleparam.h module param name,type...

驅動 模組引數

本例一共三種型別模組引數 無符號整型,字串,字串陣列 include include include include define access 0644 static uint age 24 module param age,uint access static char name netboy ...

Linux驅動程式的模組引數

模組引數 模組引數就是使用者在系統啟動或掛載模組時指定的引數值,相對於驅動程式它是全域性變數。通過module param 定義模組引數 module param name,type,perm name 即為引數名 type 引數的型別,可以是byte 存放在char型變數中 short ushor...