Linux 将参数传递给内核模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11035119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing parameter to a kernel module
提问by boffin
I have some custom hardware that uses a kernel module called foo.ko
. This has to be insmod
from the Linux kernel.
我有一些使用名为foo.ko
. 这必须insmod
来自Linux内核。
Is there is a way to pass a parameter to the kernel module during insmod, something like:
有没有办法在 insmod 期间将参数传递给内核模块,例如:
insmod foo.ko <parameter>
?
?
采纳答案by Preet Sangha
Name the parameters like this:
像这样命名参数:
insmod foo.ko mystring="bebop" mybyte=255
From Passing Command Line Arguments to a Module : The Linux Kernel Module Programming Guide
回答by Se7so
You can set any needed parameters at load time this way:
您可以通过这种方式在加载时设置任何需要的参数:
insmod param_name=param_value
and set it in your source code this way:
并以这种方式在您的源代码中设置它:
module_param(param_name, param_type, permission);
param types supported:
支持的参数类型:
int -> integer value
charp -> character pointer
....
Permission is a mask like S_IRUGO
, you may need to check moduleparam.h
.
权限就像一个面具S_IRUGO
,你可能需要检查moduleparam.h
。