MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / fs / sysfs / group.c
blob61b2462f6e98a2c46161fe8362963d2c00d3a87e
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/err.h>
15 #include "sysfs.h"
18 static void remove_files(struct dentry * dir,
19 const struct attribute_group * grp)
21 struct attribute *const* attr;
23 for (attr = grp->attrs; *attr; attr++)
24 sysfs_hash_and_remove(dir,(*attr)->name);
27 static int create_files(struct dentry * dir,
28 const struct attribute_group * grp)
30 struct attribute *const* attr;
31 int error = 0;
33 for (attr = grp->attrs; *attr && !error; attr++) {
34 error = sysfs_add_file(dir,*attr);
36 if (error)
37 remove_files(dir,grp);
38 return error;
42 int sysfs_create_group(struct kobject * kobj,
43 const struct attribute_group * grp)
45 struct dentry * dir;
46 int error;
48 if (grp->name) {
49 error = sysfs_create_subdir(kobj,grp->name,&dir);
50 if (error)
51 return error;
52 } else
53 dir = kobj->dentry;
54 dir = dget(dir);
55 if ((error = create_files(dir,grp))) {
56 if (grp->name)
57 sysfs_remove_subdir(dir);
59 dput(dir);
60 return error;
63 void sysfs_remove_group(struct kobject * kobj,
64 const struct attribute_group * grp)
66 struct dentry * dir;
68 if (grp->name)
69 dir = sysfs_get_dentry(kobj->dentry,grp->name);
70 else
71 dir = dget(kobj->dentry);
73 remove_files(dir,grp);
74 if (grp->name)
75 sysfs_remove_subdir(dir);
76 /* release the ref. taken in this routine */
77 dput(dir);
81 EXPORT_SYMBOL(sysfs_create_group);
82 EXPORT_SYMBOL(sysfs_remove_group);