SYSFS以及设备文件或kobject目录创建的关系

 

 

 sysfs_create_group()定义的文件 kernel/fs/sysfs/group.c:

 

static int internal_create_group(struct kobject *kobj, int update,
                 const struct attribute_group *grp)
{
    struct sysfs_dirent *sd;
    int error;

    BUG_ON(!kobj || (!update && !kobj->sd));

    /* Updates may happen before the object has been instantiated */
    if (unlikely(update && !kobj->sd))
        return -EINVAL;

    if (grp->name) {
        error = sysfs_create_subdir(kobj, grp->name, &sd);
        if (error)
            return error;
    } else
        sd = kobj->sd;
    sysfs_get(sd);
    error = create_files(sd, kobj, grp, update);
    if (error) {
        if (grp->name)
            sysfs_remove_subdir(sd);
    }
    sysfs_put(sd);
    return error;
}


 sysfs_create_group()定义
 

/**
 * sysfs_create_group - given a directory kobject, create an attribute group
 * @kobj:   The kobject to create the group on
 * @grp:    The attribute group to create
 *
 * This function creates a group for the first time.  It will explicitly
 * warn and error if any of the attribute files being created already exist.
 *
 * Returns 0 on success or error.
 */
int sysfs_create_group(struct kobject *kobj,
               const struct attribute_group *grp)
{
    return internal_create_group(kobj, 0, grp);
}


 

 attribute 结构位于 kernel/include/linux/sysfs.h

 

/* FIXME
 * The *owner field is no longer used.
 * x86 tree has been cleaned up. The owner
 * attribute is still left for other arches.
 */
struct attribute {
    const char      *name;
    struct module       *owner;
    mode_t          mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
    struct lock_class_key   *key;
    struct lock_class_key   skey;
#endif
};


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值