Messages in this thread Patch in this message | | | Date | Mon, 6 Oct 2003 14:32:14 +0530 | From | Maneesh Soni <> | Subject | [RFC 5/6] sysfs-attr_group.patch |
| |
o This patch creates attribute group for the given kobject. Again here we don;t create the sysfs directory but just links the struct attribute_group to the kobject.
fs/sysfs/group.c | 46 ++++++++++++++++------------------------------ 1 files changed, 16 insertions(+), 30 deletions(-)
diff -puN fs/sysfs/group.c~sysfs-attr_group fs/sysfs/group.c --- linux-2.6.0-test6/fs/sysfs/group.c~sysfs-attr_group 2003-10-06 12:00:23.000000000 +0530 +++ linux-2.6.0-test6-maneesh/fs/sysfs/group.c 2003-10-06 12:00:35.000000000 +0530 @@ -24,40 +24,26 @@ static void remove_files(struct dentry * sysfs_hash_and_remove(dir,(*attr)->name); } -static int create_files(struct dentry * dir, - const struct attribute_group * grp) -{ - struct attribute *const* attr; - int error = 0; - - for (attr = grp->attrs; *attr && !error; attr++) { - error = sysfs_add_file(dir,*attr); - } - if (error) - remove_files(dir,grp); - return error; -} - - int sysfs_create_group(struct kobject * kobj, const struct attribute_group * grp) { - struct dentry * dir; - int error; + struct kobject_attr_group * k_attr_group; - if (grp->name) { - error = sysfs_create_subdir(kobj,grp->name,&dir); - if (error) - return error; - } else - dir = kobj->dentry; - dir = dget(dir); - if ((error = create_files(dir,grp))) { - if (grp->name) - sysfs_remove_subdir(dir); - dput(dir); - } - return error; + if (!kobj || !grp) + return -EINVAL; + + k_attr_group = kmalloc(sizeof(k_attr_group), GFP_KERNEL); + if (!k_attr_group) + return -ENOMEM; + memset(k_attr_group, 0, sizeof(k_attr_group)); + INIT_LIST_HEAD(&k_attr_group->list); + k_attr_group->attr_group = grp; + + down_write(&kobj->k_rwsem); + list_add(&k_attr_group->list, &kobj->attr_group); + up_write(&kobj->k_rwsem); + + return 0; } void sysfs_remove_group(struct kobject * kobj, _ -- Maneesh Soni Linux Technology Center, IBM Software Lab, Bangalore, India email: maneesh@in.ibm.com Phone: 91-80-5044999 Fax: 91-80-5268553 T/L : 9243696 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |