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
原文地址:https://www.cnblogs.com/w-smile/p/14322130.html