PROC文件系统驱动开发应用.ppt
文本预览下载声明
PROC文件系统使用 通过proc来动态调试内核 PROC简介 /proc 文件系统是一个虚拟文件系统,通过它可以使用一种新的方法在内核空间和用户空间之间进行通信。在 /proc 文件系统中,我们可以将对虚拟文件的读写作为与内核中实体进行通信的一种手段,但是与普通文件不同的是,这些虚拟文件的内容都是动态创建的,或者说动态生成的。 PROC的存在与使用 存在: Proc文件系统在内核编译时需要选中,选中后存在于/proc下面,其中包含很多的设备项。 使用: Proc是一个虚拟文件系统,它并不存在于一个具体的存储器中,甚至于内存都不算,只不过在文件的读接口中将相应的变量提取出来,当然我们可以像操作普通文件一样操作,对于应用来说,看来就象一个文件一样。 用户操作PROC文件的方法 程序实现: 可以在代码中使用file接口来进行读写相应的项。 使用linux shell命令: Cat命令可以读文件,echo命令可以写文件。我们可以通过这两个来读写我们的proc fs,达到与内核通讯的目的,从而动态修改内核参数。 Cat的使用:cat /proc/vsdev00/host 读取相应的文件。 name value min max mode h264cfg 10 0 8 r/w debug_level 2 0 4 r/w Echo的使用:echo “debug_level:3” /proc/vsdev00/host 说明:将debug_level的值修改成3 PROC文件创建举例 创建与销毁目录: 创建目录: sprintf(tmp, vsdev%02d, 0); vs_proc_root[0] = proc_mkdir(tmp, NULL); /*create proc dir for dev 0*/ 销毁目录: if(vs_proc_root[slot]) /*if device in this slot had been create a proc dir*/ { sprintf(tmp, vsdev%02d, slot); remove_proc_entry(tmp, NULL); /*remove proc dir for dev 0*/ vs_proc_root[slot] = NULL; return; } PROC的存在与使用 创建与销毁文件: 创建文件: if(vs_proc_host[slot] != 0) /*if host in this slot had not been create*/ { vs_proc_host[slot]-mode = S_IFREG|S_IRUSR|S_IWUSR;//0444; vs_proc_host[slot]-size = 0; vs_proc_host[slot]-read_proc = vs_proc_read; /*read func for all vs proc file*/ vs_proc_host[slot]-write_proc = vs_proc_write; /*write func for all vs proc file*/ vs_proc_host[slot]-data = host_proc_list; /*host_proc_list is special for a file*/ } 销毁文件: if(vs_proc_host[slot]) /*if host in this slot had been create*/ { remove_proc_entry(“host”, vs_proc_root[slot]); /*remove proc file for dev slot*/ vs_proc_host[slot] = NULL; return; } VS设备中PROC的使用(一) 关键结构体: typedef struct vs_proc_info { /*This must in the first address , because I will use it to show the vs_proc_info addres
显示全部