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>
17 #include <asm/semaphore.h>
21 static void remove_files(struct dentry * dir,
22 const struct attribute_group * grp)
24 struct attribute *const* attr;
26 for (attr = grp->attrs; *attr; attr++)
27 sysfs_hash_and_remove(dir,(*attr)->name);
30 static int create_files(struct dentry * dir,
31 const struct attribute_group * grp)
33 struct attribute *const* attr;
36 for (attr = grp->attrs; *attr && !error; attr++) {
37 error = sysfs_add_file(dir, *attr, SYSFS_KOBJ_ATTR);
40 remove_files(dir,grp);
45 int sysfs_create_group(struct kobject * kobj,
46 const struct attribute_group * grp)
51 BUG_ON(!kobj || !kobj->dentry);
54 error = sysfs_create_subdir(kobj,grp->name,&dir);
60 if ((error = create_files(dir,grp))) {
62 sysfs_remove_subdir(dir);
68 void sysfs_remove_group(struct kobject * kobj,
69 const struct attribute_group * grp)
74 dir = lookup_one_len_kern(grp->name, kobj->dentry,
79 dir = dget(kobj->dentry);
81 remove_files(dir,grp);
83 sysfs_remove_subdir(dir);
84 /* release the ref. taken in this routine */
89 EXPORT_SYMBOL_GPL(sysfs_create_group);
90 EXPORT_SYMBOL_GPL(sysfs_remove_group);