proc_mkdir与proc_create
2016-05-09 22:13
537 查看
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入口使读取访问。我想你可以通过改变使其他类型的访问的
您可以检查这个例子的更多细节: 希望这会有所帮助。
(2):这里是一个'hello_proc“代码,它较新的'proc_create()接口。
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);
相关文章推荐
- LeetCode之二叉树作题java
- Metal 着色语言编程指南 十九
- android源码网
- Gnome桌面的下拉式终端: Guake
- hdu1071Nightmare(BFS+优先队列)
- 算法实现之简单选择排序、二元选择排序和堆排序
- Spring IOC容器-自动装配
- php http请求 curl方法
- 算法练习4.Median of Two Sorted Arrays两个有序数组的中位数(递归、分治)
- webstorm定位如何在代码后面?
- ContentProvider 之 短信数据库和表结构
- 【翻译】 Unity3D VR 教程:4.VR中的用户界面
- Spring AOP 自动创建代理
- [乐意黎原创] PHP的增加时间
- 第10周项目2-存储班长信息的学生类
- 在Windows环境下搭建DNS
- 最大上升子列
- redis学习笔记(12)---server基本流程
- STM32_SPI主从通信
- 利用Abot 抓取博客园新闻数据