读书人

linux之configfs简介跟编程入门

发布时间: 2013-10-01 12:15:56 作者: rapoo

linux之configfs简介和编程入门
转载请注原出处:http://blog.csdn.net/liumangxiong一、什么是configfs是一种基于ram的文件系统二、configfs有什么用处在用户空间配置内核对象三、configfs VS ioctlconfigfs可直接察看,通过用户态目录文件访问接口,适用于内核对象有众多复杂的配置。四、configs VS sysfsconfigfs可以在用户态创建和删除内核对象。五、什么时候用configfs当内核需要很多参数需要配置时;当需要动态创建内核对象并且内核对象需要修改配置时;不想写用户态程序和ioctl时,写shell脚本就可以直接配置configfs。六、怎么知道系统上是否已经安装了configfs,安装在哪个目录执行如下命令,可以看到安装目录为/sys/kernel/configcat /proc/mounts | grep configfs configfs /sys/kernel/config configfs rw,relatime 0 0七、configfs组织结构是怎么样的顶层结构是struct configfs_subsystem,为configfs子系统结构,接着是struct config_group,是configfs目录和属性的容器,struct config_item是configfs目录,代表可配置的内核对象,struct configfs_attribute是目录下面的属性。八、代码示例(来自内核目录Documentation\filesystems\configfs)介绍代码之前,先过一下基本的数据结构:

326static struct config_group *group_children_make_group(struct config_group *group, const char *name)327{328     struct simple_children *simple_children;329330     simple_children = kzalloc(sizeof(struct simple_children),331                      GFP_KERNEL);332     if (!simple_children)333          return ERR_PTR(-ENOMEM);334335     config_group_init_type_name(&simple_children->group, name,336                        &simple_children_type);337338     return &simple_children->group;339}

这份代码非常眼熟,跟示例2中创建config_item太像了,只不过把所有对象由config_item改为config_group类型的。336行,simple_children_type正是示例2中对应的config_item_type。所以这里的创建步骤首先是创建一个为config_group的目录,再在这个目录下创建config_item的目录。到这里为止,简单地了解了一下configfs的实现原理,在某些应用中不失为一种很好的手段。转载请注原出处:http://blog.csdn.net/liumangxiong

读书人网 >编程

热点推荐