allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / fs / sysfs / group.c
blob23c428c986faa0263e27b5136babadb925cc082e
1 /*
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.
9 */
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>
16 #include <linux/fs.h>
17 #include <asm/semaphore.h>
18 #include "sysfs.h"
21 static void remove_files(struct dentry *dir, struct kobject *kobj,
22 const struct attribute_group *grp)
24 struct attribute *const* attr;
25 int i;
27 for (i = 0, attr = grp->attrs; *attr; i++, attr++)
28 if (!grp->is_visible ||
29 grp->is_visible(kobj, *attr, i))
30 sysfs_hash_and_remove(dir, (*attr)->name);
33 static int create_files(struct dentry *dir, struct kobject *kobj,
34 const struct attribute_group *grp)
36 struct attribute *const* attr;
37 int error = 0, i;
39 for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++)
40 if (!grp->is_visible ||
41 grp->is_visible(kobj, *attr, i))
42 error |=
43 sysfs_add_file(dir, *attr, SYSFS_KOBJ_ATTR);
44 if (error)
45 remove_files(dir, kobj, grp);
46 return error;
50 int sysfs_create_group(struct kobject * kobj,
51 const struct attribute_group * grp)
53 struct dentry * dir;
54 int error;
56 BUG_ON(!kobj || !kobj->dentry);
58 if (grp->name) {
59 error = sysfs_create_subdir(kobj,grp->name,&dir);
60 if (error)
61 return error;
62 } else
63 dir = kobj->dentry;
64 dir = dget(dir);
65 error = create_files(dir, kobj, grp);
66 if (error) {
67 if (grp->name)
68 sysfs_remove_subdir(dir);
70 dput(dir);
71 return error;
74 void sysfs_remove_group(struct kobject * kobj,
75 const struct attribute_group * grp)
77 struct dentry * dir;
79 if (grp->name) {
80 dir = lookup_one_len_kern(grp->name, kobj->dentry,
81 strlen(grp->name));
82 BUG_ON(IS_ERR(dir));
84 else
85 dir = dget(kobj->dentry);
87 remove_files(dir, kobj, grp);
88 if (grp->name)
89 sysfs_remove_subdir(dir);
90 /* release the ref. taken in this routine */
91 dput(dir);
95 EXPORT_SYMBOL_GPL(sysfs_create_group);
96 EXPORT_SYMBOL_GPL(sysfs_remove_group);