linux下的module_param()解释【转】
转自: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
linux下的module_param()解释【转】的更多相关文章
- Linux下top订购具体解释
Linux下top订购具体解释 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvempmMjgwNDQxNTg5/font/5a6L5L2T/fontsize ...
- Linux下的压缩zip,解压缩unzip命令具体解释及实例
实例:压缩server上当前文件夹的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前文件夹 unzip filename.zip ================= ...
- linux下getsockopt和setsockopt具体解释及測试
linux下getsockopt和setsockopt具体解释及測试 NAME 名字 getsockopt, setsockopt - get and set options on sockets 获 ...
- Linux下函数调用堆栈帧的详细解释【转】
转自:http://blog.chinaunix.net/uid-30339363-id-5116170.html 原文地址:Linux下函数调用堆栈帧的详细解释 作者:cssjtuer http:/ ...
- Linux 下几个重要目录解释
linux下把所有的东西都当作文件的,,一个分区想要使用就需要挂载到一个文件夹上,那这个文件夹就叫挂载点,像常用的把 设备/dev/cdrom挂载到/mnt,,,你想问的应该是linux的各目录的解释 ...
- Linux下查看进程的命令输出的内容解释
Linux下查看进程的命令输出的内容解释 ps (process status) ps -e 或者ps -A (-e和-A完全一样) PID TTY TIME ...
- linux 下通过源代码安装程序 ./configure 解释
大家 都知道在 linux 通过源代码 安装程序 1. 下载源码 2.解压缩 3. 执行 ./configure 4. make 5 make install make 命令 是对 makefile ...
- 环境变量解释以及在Linux下的环境变量设置
一.环境变量解释 环境变量是什么? 引用百度百科里面的解释:环境变量是操作系统中一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息.例如Windows系统中的path环境变量,当要求 ...
- linux下alias命令具体解释
linux下alias命令具体解释 用途说明 设置命令的别名.在linux系统中假设命令太长又不符合用户的习惯,那么我们能够为它指定一个别名. 尽管能够为命令建立"链接" 解决长文 ...
随机推荐
- mysql中文乱码问题
1.mysql客户端在插入中文字符的时候可能出现乱码问题. 原因: 要解决字符集的问题,首先要知道现在的系统.数据库.表.客户端等使用什么样的字符集,以及系统支持什么字符集等. 2.我百度了好多,说 ...
- 智能硬件+App移动新生态【11.01深圳】
活动概况 时间:2015年11月01日13:30-16:30 地点:深圳腾讯大厦(南山区科技园科技中一路)2楼多功能厅 主办:APICloud.庆科.信鸽 费用:免费 活动背景 智能电视.智能汽车.智 ...
- 使用 tox flake8 pytest 规范 python 项目
使用 tox flake8 pytest 规范 python 项目 python 中有些很好的工作来规范整个项目的开发,而其中使用较多的就是使用 tox . flake8 . pytest . tox ...
- [BS-16] 尽量将View的Opaque属性设置为YES(默认就是YES)
尽量将View的Opaque属性设置为YES(默认就是YES) UIView控件都有一个Opaque属性,如果不会更改view的透明度,那么应该将其opaque属性设置为YES.为什么要这样做呢?其实 ...
- OC面向对象—多态
OC面向对象—多态 一.基本概念 多态是基于继承的基础之上的,多态可以使得父类的指针指向子类的对象.如果函数或参数中使用的是父类类型,可以传入父类.子类对象,但是父类类型的变量不能直接调用子类特有的方 ...
- 缩进, Tab 还是空格?(转)
圣战 圣战个毛线 Android 好还是 iOS 好,Windows 好还是 Mac 好,编辑器好还是 IDE好,中划线好还是下划线好…写代码这么多年,会遇到很多奇葩的毫无意义的所谓脑残粉的争论 昨天 ...
- javascript表单操作方法
一.Form元素 相关属性: 1,action属性 2,elements属性 3,length属性 4,name属性 5, method属性 如果多个表单字段的name属性相同,那么提交的value就 ...
- HTTPS and the TLS handshake protocol阅读笔记
目的 为能够透彻理解HTTPS报文交互过程,做此笔记. 本文大部分内容来自 : http://albertx.mx/blog/https-handshake/ http://www.cnblogs.c ...
- Linux和Windows之间传递文件
由于自己的计算机的性能不足,代码只能在服务器上运行,要把代码搬到服务器上运行在没有root权限的情况下,本身就是一件不太容易的事情,我准备下次再写一下这方面的技巧.这篇博客,我只说比较一下几种在不同操 ...
- 收集一些java相关的文章
有些文章看了,以后想再看已经忘了在哪里了.故在此一一记录下那些值得看的文章. 1:如何确定Java对象的大小 中文版本 :http://article.yeeyan.org/view/104091/6 ...