首页 > 代码库 > linux kernel with param
linux kernel with param
Linux kernel support pass param to kernel, this params can be assigned at load time by insmod or modprobe. or later read from /etc/modprobe.conf file.
There are two macro : module_param and module_param_array,
To declare an param or array param ,use:
module_param(name, type, perm) module_param_array(name, type, num, perm)
name is the name of your param or array.
type can be : bool ,invbool,charp, int, long, short, uint, ulong, ushort
num is the array num , array param where the values are supplied as a comma-separated list.
perm : S_IRUGO , S_IWUSR and so on .
int num = 0;static char* array[10] = {NULL};static int ntime = 0;static char* pstring = NULL;module_param_array(array, charp, &num, S_IRUGO);module_param(ntime, int, S_IRUGO);module_param(pstring, charp, S_IRUGO);static int __init init_func(void){ int i = 0; printk("string :%s, int :%d\n", pstring, ntime); printk("Array\n"); for(; i < num; ++i) printk("%s\n", array[i]); return 0;}
执行:
sudo insmod ./hello.ko array="hello,world" pstring="test" ntime=10
linux kernel with param
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。