//功能:在proc中创建一个文件夹

//参数1:创建的文件夹名称

//参数2:创建的文件夹路径,就是在哪个文件夹中创建,如果是proc根目录,此参数为NULL

//返回值:创建的文件夹路径

struct proc_dir_entry *proc_mkdir(const char *name, struct proc_dir_entry *parent);

//功能:在proc中创建一个文件

//参数1:创建的文件的名称

//参数2:文件的读写权限

//参数3:创建的文件路径,即在哪个文件夹中创建,如果是proc根目录,此参数为NULL

//参数4:此文件的操作函数file_operations

//返回值:创建的文件路径

static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);

//功能:删除proc中的文件或文件夹

//参数:删除的文件或文件夹路径

//返回:无

void proc_remove(struct proc_dir_entry *de);

#define BASE_DIR_NAME     "led"

struct file_operations led_ops = {
.owner = THIS_MODULE,
.open = led_ctl_open,
.release = led_ctl_release,
.write = led_ctl_write,
}; static int led_ctl_probe(struct platform_device *pdev)
{
printk("%s\n", __func__); // 在 proc 根目录创建 led 文件夹
base = proc_mkdir(BASE_DIR_NAME, NULL);
if(base == NULL){
printk("%s proc create %s failed\n", __func__, BASE_DIR_NAME);
return -EINVAL;
} // 在 led 文件夹中创建文件 led_ctl,文件操作函数为 led_ops
led_ctl = proc_create("led_ctl", , base, &led_ops);
if (led_ctl == NULL) {
printk("proc_create failed!\n");
// led_ctl 文件创建失败,删除上一步创建的文件夹 led
proc_remove(base);
return -EINVAL;
} return ;
} static int led_ctl_remove(struct platform_device *pdev)
{
printk("%s\n", __func__); // 删除 led_ctl 文件
proc_remove(led_ctl);
// 删除 led 文件夹
proc_remove(base); return ;
}

Linux proc_mkdir和proc_create的用法的更多相关文章

  1. linux mount命令参数及用法详解

    linux mount命令参数及用法详解 非原创,主要来自 http://www.360doc.com/content/13/0608/14/12600778_291501907.shtml. htt ...

  2. 【转】linux expr命令参数及用法详解

    在抓包过程中,查看某个设定时间内,数据上下行多少,用命令expr 计算! --------------------------------------------------------------- ...

  3. linux dmesg命令参数及用法详解(linux显示开机信息命令)

    linux dmesg命令参数及用法详解(linux显示开机信息命令) http://blog.csdn.net/zhongyhc/article/details/8909905 功能说明:显示开机信 ...

  4. linux sed命令参数及用法详解

    linux sed命令参数及用法详解 http://blog.csdn.net/namecyf/article/details/7336308 1. Sed简介 sed 是一种在线编辑器,它一次处理一 ...

  5. Linux中yum和apt-get用法及区别

    Linux中yum和apt-get用法及区别   一般来说著名的linux系统基本上分两大类:   1.RedHat系列:Redhat.Centos.Fedora等   2.Debian系列:Debi ...

  6. linux下find查找命令用法

    Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所以它的选项也很多,其中大部分选项都值得我们花时 ...

  7. linux dd命令参数及用法详解---用指定大小的块拷贝一个文件(也可整盘备份)

    linux dd命令参数及用法详解---用指定大小的块拷贝一个文件 日期:2010-06-14 点击:3830 来源: 未知 分享至:            linux dd命令使用详解 dd 的主要 ...

  8. linux c语言 select函数用法

    linux c语言 select函数用法 表头文件 #i nclude<sys/time.h> #i nclude<sys/types.h> #i nclude<unis ...

  9. Linux中find命令的用法汇总

    Linux中find命令的用法汇总 https://www.jb51.net/article/108198.htm

随机推荐

  1. 通过一道面试题了解Condition线程通信

    Condition Condition接口描述了可能会与锁有关联的条件变量.这些变量在用法与使用Object.wait访问的隐式监视器类似,但提供了更强大的功能.需要特别指出的是,单个Lock可能与多 ...

  2. sql 日志统计-日、周、月活跃数

    近日网站需求:统计日志表的 日.周.月活跃数.最终研究了出来了,分享给大家看下.  如果有更好的sql语句也可以评论下方. --日活跃量 ), cr.AddTime, )as addtimt,COUN ...

  3. 【Html 学习笔记】第七节——表单

    文本框:<form> <input> </form> 密码域-文本框:<input type ="password" > 复选框:& ...

  4. LeetCode OJ:Implement Stack using Queues(队列实现栈)

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  5. 解决xadmin下设置“use_bootswatch = True”无效的问题

    环境:python 2.7django 1.9xadmin采用源代码的方式引入到项目中QQ群交流:697028234 1.安装requests pip install requests 2./xadm ...

  6. 用国内镜像源pip加速安装模块

    记住,如果使用了virtualenv,一定要先workon进入虚拟环境再执行包安装命令. pip install -i https://pypi.douban.com/simple/ 模块名(如:dj ...

  7. qml自定义带文字的button tabbutton

    https://blog.csdn.net/u014416260/article/details/54579480

  8. make笔记

    Makefile基本格式如下: target ... : prerequisites ... command ... ... 其中, target - 目标文件, 可以是 Object File, 也 ...

  9. 在servlet中的中文乱码,相对路径和绝对路径

    默认情况下在servlet中的中文是显示不出来的,解决问题就是加resp.setContentType("text/html;charset=gbk"); 而且这句加的话必须写在P ...

  10. iOS NSRunloop

    什么是Runloop Runloop即运行循环.为什么你的APP放在那里不去动它,在某个时间点去操作它,它还会给你反馈.就是因为Runloop的存在. 总结一下,因为Runloop的存在,保证你的程序 ...