2 * fs/sysfs/group.c - Operations for adding/removing multiple files at once.
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
7 * This file is released undert the GPL v2.
11 #include <linux/kobject.h>
12 #include <linux/module.h>
13 #include <linux/dcache.h>
14 #include <linux/namei.h>
15 #include <linux/err.h>
19 static void remove_files(struct dentry * dir,
20 const struct attribute_group * grp)
22 struct attribute *const* attr;
24 for (attr = grp->attrs; *attr; attr++)
25 sysfs_hash_and_remove(dir,(*attr)->name);
28 static int create_files(struct dentry * dir,
29 const struct attribute_group * grp)
31 struct attribute *const* attr;
34 for (attr = grp->attrs; *attr && !error; attr++) {
35 error = sysfs_add_file(dir, *attr, SYSFS_KOBJ_ATTR);
38 remove_files(dir,grp);
43 int sysfs_create_group(struct kobject * kobj,
44 const struct attribute_group * grp)
49 BUG_ON(!kobj || !kobj->dentry);
52 error = sysfs_create_subdir(kobj,grp->name,&dir);
58 if ((error = create_files(dir,grp))) {
60 sysfs_remove_subdir(dir);
66 void sysfs_remove_group(struct kobject * kobj,
67 const struct attribute_group * grp)
72 dir = lookup_one_len(grp->name, kobj->dentry,
75 dir = dget(kobj->dentry);
77 remove_files(dir,grp);
79 sysfs_remove_subdir(dir);
80 /* release the ref. taken in this routine */
85 EXPORT_SYMBOL_GPL(sysfs_create_group);
86 EXPORT_SYMBOL_GPL(sysfs_remove_group);