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 sysfs_dirent *dir_sd,
22 const struct attribute_group *grp)
24 struct attribute *const* attr;
26 for (attr = grp->attrs; *attr; attr++)
27 sysfs_hash_and_remove(dir_sd, (*attr)->name);
30 static int create_files(struct sysfs_dirent *dir_sd,
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_sd, *attr, SYSFS_KOBJ_ATTR);
39 remove_files(dir_sd, grp);
44 int sysfs_create_group(struct kobject * kobj,
45 const struct attribute_group * grp)
47 struct sysfs_dirent *sd;
50 BUG_ON(!kobj || !kobj->sd);
53 error = sysfs_create_subdir(kobj, grp->name, &sd);
59 error = create_files(sd, grp);
62 sysfs_remove_subdir(sd);
68 void sysfs_remove_group(struct kobject * kobj,
69 const struct attribute_group * grp)
71 struct sysfs_dirent *dir_sd = kobj->sd;
72 struct sysfs_dirent *sd;
75 sd = sysfs_get_dirent(dir_sd, grp->name);
78 sd = sysfs_get(dir_sd);
80 remove_files(sd, grp);
82 sysfs_remove_subdir(sd);
88 EXPORT_SYMBOL_GPL(sysfs_create_group);
89 EXPORT_SYMBOL_GPL(sysfs_remove_group);