转自:http://blog.csdn.net/wavemcu/article/details/7762133

版权声明:本文为博主原创文章,未经博主允许不得转载。

***************************************************************************************************************************
作者:EasyWave                                                                                 时间:2012.07.19

类别:linux驱动开发                                                                           声明:转载,请保留链接

***************************************************************************************************************************

1.引入module_param目的。 
          在用户态下编程可以通过main()来传递命令行参数,而编写一个内核模块则可通过module_param()来传递命令行参数. 也就是内核允许对驱动程序在加载的时候传递参数,e.g.insmod hello who="world" times=5 其中who,times 均为要传递的参数变量。

2.module_param()的定义 。
         module_param宏是Linux 2.6内核中新增的,该宏被定义在include/linux/moduleparam.h文件中,具体定义如下(我从源码那里找来的http://tomoyo.sourceforge.jp/cgi-bin/lxr/source/include/linux/moduleparam.h):
/**
 77  * module_param - typesafe helper for a module/cmdline parameter
 78  * @value: the variable to alter, and exposed parameter name.          
 79  * @type: the type of the parameter
 80  * @perm: visibility in sysfs.
 81  *
 82  * @value becomes the module parameter, or (prefixed by KBUILD_MODNAME and a
 83  * ".") the kernel commandline parameter.  Note that - is changed to _, so
 84  * the user can use "foo-bar=1" even for variable "foo_bar".
 85  *
 86  * @perm is 0 if the the variable is not to appear in sysfs, or 0444
 87  * for world-readable, 0644 for root-writable, etc.  Note that if it
 88  * is writable, you may need to use kparam_block_sysfs_write() around
 89  * accesses (esp. charp, which can be kfreed when it changes).
 90  *
 91  * The @type is simply pasted to refer to a param_ops_##type and a
 92  * param_check_##type: for convenience many standard types are provided but
 93  * you can create your own by defining those variables.
 94  *
 95  * Standard types are:
 96  *      byte, short, ushort, int, uint, long, ulong
 97  *      charp: a character pointer
 98  *      bool: a bool, values 0/1, y/n, Y/N.
 99  *      invbool: the above, only sense-reversed (N = true).
100  */
101 #define module_param(name, type, perm)                          /
102         module_param_named(name, name, type, perm)
103 
104 /**
105  * module_param_named - typesafe helper for a renamed module/cmdline parameter
106  * @name: a valid C identifier which is the parameter name.
107  * @value: the actual lvalue to alter.
108  * @type: the type of the parameter
109  * @perm: visibility in sysfs.
110  *
111  * Usually it's a good idea to have variable names and user-exposed names the
112  * same, but that's harder if the variable must be non-static or is inside a
113  * structure.  This allows exposure under a different name.
114  */
          其中使用了 3 个参数:要传递的参数变量名, 变量的数据类型, 以及访问参数的权限。
          注:宏的第三个参数用于指定访问权限,如果为 0,该参数将不出现在 sysfs 文件系统中,允许的访问权限为      S_IRUSR,S_IWUSR,S_IRGRP,S_IWGRP,S_IROTH 和S_IWOTH 的组合,它们分别对应于用户读,用户写,用户组读,用户组写,其他用户读和其他用户写,因此用文件的访问权限设置是一致的。
而权限的设置可以参考如下:(也可以自己定义,它类似chmod中权限的使用)
          权限在include/linux/stat.h中有定义:
比如:
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100

#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010

#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001

【作者】张昺华
【出处】http://www.cnblogs.com/sky-heaven/
【博客园】 http://www.cnblogs.com/sky-heaven/
【新浪博客】 http://blog.sina.com.cn/u/2049150530
【知乎】 http://www.zhihu.com/people/zhang-bing-hua
【我的作品---旋转倒立摆】 http://v.youku.com/v_show/id_XODM5NDAzNjQw.html?spm=a2hzp.8253869.0.0&from=y1.7-2
【我的作品---自平衡自动循迹车】 http://v.youku.com/v_show/id_XODM5MzYyNTIw.html?spm=a2hzp.8253869.0.0&from=y1.7-2
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

linux下的module_param()解释【转】相关推荐

  1. linux下IIC驱动解释

    原文地址:https://www.cnblogs.com/lifexy/p/7816324.html 1. I2C体系结构分析 1.1首先进入linux内核的driver/i2c目录下,如下图所示: ...

  2. linux jzmq编译,Linux下ps aux解释

    ps aux的功能是打印出所有进程 ps是最基本也是最强大的进程查看命令 aux都是参数 a = show processes for all users 显示所有用户的进程 u = display ...

  3. ps aux含义linux,Linux下ps aux解释

    ps aux的功能是打印出所有进程 ps是最基本也是最强大的进程查看命令 aux都是参数 a = show processes for all users 显示所有用户的进程 u = display ...

  4. linux 安装tcl命令,TCL/TK Linux下安装 | 勤奋的小青蛙

    原创文章,转载请注明: 转载自勤奋的小青蛙 本文链接地址: TCL/TK Linux下安装 在Linux下安装TCL/TK,可以有编译源代码的方式安装,也可以有直接通过二进制压缩包进行解压缩安装,本文 ...

  5. Linux下的用户、组和权限的详细解释

            前言:在linux中一切都是文件(文件夹和硬件设备是特殊的文件),如果有可能尽量使用文本文件.文本文件是人和机器能理解的文件,也成为人和机器进行交流的最好途径.由于所有的配置文件都是文 ...

  6. linux proc 文件系统下 entry 的解释(转)

    linux proc 文件系统下 entry 的解释(转)[@more@] proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以文件系统的方式为访问系统内核数据的操作提供接口.用 ...

  7. Linux ps aux什么含义,Linux下psaux解释

    Linux下psaux解释 ps aux的功能是打印出所有进程 ps是最基本也是最强大的进程查看命令 aux都是参数 a = show processes for all users 显示所有用户的进 ...

  8. 各位高手们谁能帮我解释一下linux下面的squid代理的作用是什么?

    各位高手们谁能帮我解释一下linux下面的squid代理的作用是什么? 各位高手们谁能帮我解释一下linux下面的squid代理的作用是什么? 105 [ 标签: linux, squid, 作用 ] ...

  9. Linux下函数调用堆栈帧的详细解释

    http://www.ibm.com/developerworks/cn/linux/l-overflow/ 本文首先向读者讲解了Linux下进程地址空间的布局以及进程堆栈帧的结构,然后在此基础上介绍 ...

最新文章

  1. 扫码登录是如何实现的?
  2. python 嵌入式 linux 产品 发布_基于嵌入式Linux进行Python应用开发
  3. modelsim仿真
  4. Activiti中的安全脚本如何工作
  5. Ubuntu 查看默认软件安装位置
  6. BZOJ2142: 礼物
  7. kotlin_Kotlin弦
  8. iZotope Ozone 9 Advanced for Mac(臭氧9高级版)
  9. java基础--接口
  10. FluxWeakening_MTPA_FOC
  11. (三-1)随机森林分类器(共3小节,完整代码即文章中所有代码)
  12. B016 - 基于51单片机的公交车语音报站_点阵广告屏
  13. open erp java_OpenERP API 接口
  14. 洛谷(P3373)线段树加乘混合模板
  15. 通过简单的类和接口实现手机套餐办理服务
  16. 面试前夕,我建议你还是先来看看阿里和京东面试都问些啥?
  17. kali终端打不开以及msfconsole打不开
  18. MySQL数据库从入门到入土!
  19. WPF Border 设置只加一边
  20. ZEGO即构科技荣获36氪【WISE2020中国新经济之王最具影响力企业】

热门文章

  1. Quantile Regression,python
  2. python移动窗口函数
  3. 合并多个excel——贼快
  4. LeetCode weekly contest 190 周赛
  5. Python中 sys.argv[]的用法简明解释
  6. python实现随机森林、逻辑回归和朴素贝叶斯的新闻文本分类
  7. [AHOI2005]约数研究
  8. Jzoj3806 小X 的道路修建
  9. Matlab scatter 如何显示不同颜色点状
  10. .net中6个重要的基础概念:Stack, heap, Value types, reference types, boxing and Unboxing.