aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/group.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/sysfs/group.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/sysfs/group.c')
-rw-r--r--fs/sysfs/group.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
new file mode 100644
index 000000000000..f11ac5ea7021
--- /dev/null
+++ b/fs/sysfs/group.c
@@ -0,0 +1,84 @@
1/*
2 * fs/sysfs/group.c - Operations for adding/removing multiple files at once.
3 *
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 *
7 * This file is released undert the GPL v2.
8 *
9 */
10
11#include <linux/kobject.h>
12#include <linux/module.h>
13#include <linux/dcache.h>
14#include <linux/err.h>
15#include "sysfs.h"
16
17
18static void remove_files(struct dentry * dir,
19 const struct attribute_group * grp)
20{
21 struct attribute *const* attr;
22
23 for (attr = grp->attrs; *attr; attr++)
24 sysfs_hash_and_remove(dir,(*attr)->name);
25}
26
27static int create_files(struct dentry * dir,
28 const struct attribute_group * grp)
29{
30 struct attribute *const* attr;
31 int error = 0;
32
33 for (attr = grp->attrs; *attr && !error; attr++) {
34 error = sysfs_add_file(dir, *attr, SYSFS_KOBJ_ATTR);
35 }
36 if (error)
37 remove_files(dir,grp);
38 return error;
39}
40
41
42int sysfs_create_group(struct kobject * kobj,
43 const struct attribute_group * grp)
44{
45 struct dentry * dir;
46 int error;
47
48 BUG_ON(!kobj || !kobj->dentry);
49
50 if (grp->name) {
51 error = sysfs_create_subdir(kobj,grp->name,&dir);
52 if (error)
53 return error;
54 } else
55 dir = kobj->dentry;
56 dir = dget(dir);
57 if ((error = create_files(dir,grp))) {
58 if (grp->name)
59 sysfs_remove_subdir(dir);
60 }
61 dput(dir);
62 return error;
63}
64
65void sysfs_remove_group(struct kobject * kobj,
66 const struct attribute_group * grp)
67{
68 struct dentry * dir;
69
70 if (grp->name)
71 dir = sysfs_get_dentry(kobj->dentry,grp->name);
72 else
73 dir = dget(kobj->dentry);
74
75 remove_files(dir,grp);
76 if (grp->name)
77 sysfs_remove_subdir(dir);
78 /* release the ref. taken in this routine */
79 dput(dir);
80}
81
82
83EXPORT_SYMBOL_GPL(sysfs_create_group);
84EXPORT_SYMBOL_GPL(sysfs_remove_group);