你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux之configfs简介和编程入门

[日期:2014-01-23] 来源:Linux社区  作者:liumangxiong [字体:大 中 小]

示例3:创建group
之前我们讲过,config_group是可以嵌套的,那么现在就来看一下嵌套之后是什么样的:
# cd /sys/kernel/config/03-group-children/
# ls
description
# mkdir test
# mkdir test/test1
# mkdir test/test2
# mkdir test/test3
# tree
.
|-- description
`-- test
    |-- description
    |-- test1
    |  `-- storeme
    |-- test2
    |  `-- storeme
    `-- test3
        `-- storeme

看出与示例2的区别了吗?
首先看子系统定义

382static struct configfs_subsystem group_children_subsys = {
383    .su_group = {
384          .cg_item = {
385              .ci_namebuf = "03-group-children",
386              .ci_type = &group_children_type,
387          },
388    },
389};

386行,config_item_type与之前的不一样,跟过去看看

371static struct configfs_group_operations group_children_group_ops = {
372    .make_group    = group_children_make_group,
373};
374
375static struct config_item_type group_children_type = {
376    .ct_item_ops    = &group_children_item_ops,
377    .ct_group_ops    = &group_children_group_ops,
378    .ct_attrs    = group_children_attrs,
379    .ct_owner    = THIS_MODULE,
380};

375行,定义新的config_item_type,其根本区别在377行configfs_group_operations
371行,定义了configfs_group_operations,这里定义了make_group函数,在子系统下mkdir就会调用这个函数。

326static struct config_group *group_children_make_group(struct config_group *group, const char *name)
327{
328    struct simple_children *simple_children;
329
330    simple_children = kzalloc(sizeof(struct simple_children),
331                      GFP_KERNEL);
332    if (!simple_children)
333          return ERR_PTR(-ENOMEM);
334
335    config_group_init_type_name(&simple_children->group, name,
336                        &simple_children_type);
337
338    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的实现原理,在某些应用中不失为一种很好的手段。

linux
相关资讯       configfs 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款