1:创建proc文件夹
struct proc_dir_entry *proc_mkdir(const char *name, struct proc_dir_entry *parent);
参数1:name就是要创建的文件夹名称。
参数2:parent是要创建节点的父节点。也就是要在哪个文件夹之下创建新文件夹,需要将那个文件夹的

             proc_dir_entry传入。
    如果是在/proc目录下创建文件夹,parent为NULL。
  例如:  struct proc_dir_entry *mytest_dir = proc_mkdir("mytest", NULL);
 
2:proc文件的创建:
static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
 
struct proc_dir_entry *parent, const struct file_operations *proc_fops);
参数1:name就是要创建的文件名。
参数2:mode是文件的访问权限,以UGO的模式表示(如0666)。
参数3:parent与proc_mkdir中的parent类似。也是父文件夹的proc_dir_entry对象。
参数4:proc_fops就是该文件的操作函数了。

 
例如:struct proc_dir_entry *mytest_file = proc_create("mytest", 0x0644, mytest_dir, mytest_proc_fops);
 
3:proc_create()例子内核模块

(1):这个例子将创建一个proc入口使读取访问。我想你可以通过改变使其他类型的访问的mode传递给该函数。我没有通过一个父目录下有没有必要。结构file_operations在这里您设置您的阅读和写作的回调。

struct proc_dir_entry *proc_file_entry;
static const struct file_operations proc_file_fops = {
.owner = THIS_MODULE,
.open = open_callback,
.read = read_callback,
};
int __init init_module(void){
proc_file_entry = proc_create("proc_file_name", 0, NULL, &proc_file_fops);
if(proc_file_entry == NULL)
return -ENOMEM;
return 0;
}

您可以检查这个例子的更多细节: 希望这会有所帮助。

(2):这里是一个'hello_proc“代码,它较新的'proc_create()接口。

#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
static int hello_proc_show(struct seq_file *m, void *v) {
seq_printf(m, "Hello proc!\n");
return 0;
}
static int hello_proc_open(struct inode *inode, struct file *file) {
return single_open(file, hello_proc_show, NULL);
}
static const struct file_operations hello_proc_fops = {
.owner = THIS_MODULE,
.open = hello_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static int __init hello_proc_init(void) {
proc_create("hello_proc", 0, NULL, &hello_proc_fops);
return 0;
}
static void __exit hello_proc_exit(void) {
remove_proc_entry("hello_proc", NULL);
}
MODULE_LICENSE("GPL");
module_init(hello_proc_init);
module_exit(hello_proc_exit);

[转载]proc_mkdir与proc_create的更多相关文章

  1. Linux proc_mkdir和proc_create的用法

    //功能:在proc中创建一个文件夹 //参数1:创建的文件夹名称 //参数2:创建的文件夹路径,就是在哪个文件夹中创建,如果是proc根目录,此参数为NULL //返回值:创建的文件夹路径 stru ...

  2. proc_create函数内幕初探

    一直以为PROC文件系统很是晦涩难懂,平时仅仅是使用它,不愿意去触碰内核中的具体实现.今天突发奇想,想看看里面究竟是怎么实现的,结果……真是大跌眼镜,没想到里面并不复杂 关于PROC文件系统的功能以及 ...

  3. proc_create的使用方法

    proc_create的使用方法 proc文件系统是个有用的东东.创建一个proc虚拟文件,应用层通过读写该文件,即可实现与内核的交互.proc虚拟文件是如何创建的呢? 先看看比较简单的,创建proc ...

  4. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  5. RTP与RTCP协议介绍(转载)

    RTSP发起/终结流媒体.RTP传输流媒体数据 .RTCP对RTP进行控制,同步.RTP中没有连接的概念,本身并不能为按序传输数据包提供可靠的保证,也不提供流量控制和拥塞控制,这些都由RTCP来负责完 ...

  6. 《Walking the callstack(转载)》

    本文转载自:https://www.codeproject.com/articles/11132/walking-the-callstack Download demo project with so ...

  7. [转载]MVVM模式原理分析及实践

    没有找到很好的MVVM模式介绍文章,简单找了一篇,分享一下.MVVM实现了UI\UE设计师(Expression Blend 4设计界面)和软件工程师的合理分工,在SilverLight.WPF.Wi ...

  8. [转载]:STM32为什么必须先配置时钟再配置GPIO

    转载来源 :http://blog.csdn.net/fushiqianxun/article/details/7926442 [原创]:我来添两句,就是很多同学(包括我)之前搞低端单片机,到了stm ...

  9. [转载]从MyEclipse到IntelliJ IDEA-让你摆脱鼠标,全键盘操作

    从MyEclipse转战到IntelliJ IDEA的经历 注转载址:http://blog.csdn.net/luoweifu/article/details/13985835 我一个朋友写了一篇“ ...

随机推荐

  1. CentOS 7卸载mariadb安装mysql

    CentOS 7已经将默认集成mariadb而不是mysql,这对于多数还是依赖于mysql的应用来说,需要手动的进行更新. 可能会遇到这样错误,换成MySQL就好了. error 2002 (hy0 ...

  2. Centos7 关闭Ipv6

  3. Request对象介绍(客户端到服务器)

    1.处理请求和响应的过程request,response,关于request可以从三个方面着手学习.1:如何获取请求头  行  体   2:请求中文处理     3:请求对象的其它常用方法 1.1:r ...

  4. js中出现问题--Type Syntax error on token "catch", Identifier expected jquery.js

    解决方案: 1.选中jQuery报错的web工程: 2.右键-->Myeclipse-->Exclude From Validation,选中: 3.继续右键Myeclipse--> ...

  5. get、post请求的区别

    get.post请求 自己接触前端也是许久时间了,但是对get和post请求的认识也还只是停留在网络上大多数人流传的那样: post比get安全 post可以传大数据,get传的数据量较少: 就这样, ...

  6. jenkins自动发送邮件配置

    一. 前提:确保插件存在 在一切开始之前,必须得确保任务配置里有两个插件:E-mail Notification(邮件通知) 和 Editable Email Notification(可编辑的邮件通 ...

  7. android 取mac若干问题

    问题一:Error:Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak o ...

  8. python MySQLdb连接mysql失败(转载)

    最近了解了一下django,数据库选用了mysql, 在连接数据库的过程中,遇到一点小问题,在这里记录一下,希望能够对遇到同样的问题的朋友有所帮助,少走一些弯路.关于django,想在这里也额外说一句 ...

  9. 25 python socket网络编程

    一 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构 互联网中处处是C/S架构 如黄色网站是服务端,你的浏览器是客户端(B/S架构也是C/S架构的一种) 腾讯作为服务端为你提供视频 ...

  10. sass语法(1)

    文件后缀名 sass有两种后缀名文件:一种后缀名为sass,不使用大括号和分号:另一种就是我们这里使用的scss文件,这种和我们平时写的css文件格式差不多,使用大括号和分号 //文件后缀名为sass ...