]> Pileus Git - ~andy/linux/blob - fs/sysfs/group.c
sysfs: cleanup semaphore.h
[~andy/linux] / fs / sysfs / group.c
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/namei.h>
15 #include <linux/err.h>
16 #include <linux/fs.h>
17 #include "sysfs.h"
18
19
20 static void remove_files(struct sysfs_dirent *dir_sd,
21                          const struct attribute_group *grp)
22 {
23         struct attribute *const* attr;
24
25         for (attr = grp->attrs; *attr; attr++)
26                 sysfs_hash_and_remove(dir_sd, (*attr)->name);
27 }
28
29 static int create_files(struct sysfs_dirent *dir_sd,
30                         const struct attribute_group *grp)
31 {
32         struct attribute *const* attr;
33         int error = 0;
34
35         for (attr = grp->attrs; *attr && !error; attr++)
36                 error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
37         if (error)
38                 remove_files(dir_sd, grp);
39         return error;
40 }
41
42
43 int sysfs_create_group(struct kobject * kobj, 
44                        const struct attribute_group * grp)
45 {
46         struct sysfs_dirent *sd;
47         int error;
48
49         BUG_ON(!kobj || !kobj->sd);
50
51         if (grp->name) {
52                 error = sysfs_create_subdir(kobj, grp->name, &sd);
53                 if (error)
54                         return error;
55         } else
56                 sd = kobj->sd;
57         sysfs_get(sd);
58         error = create_files(sd, grp);
59         if (error) {
60                 if (grp->name)
61                         sysfs_remove_subdir(sd);
62         }
63         sysfs_put(sd);
64         return error;
65 }
66
67 void sysfs_remove_group(struct kobject * kobj, 
68                         const struct attribute_group * grp)
69 {
70         struct sysfs_dirent *dir_sd = kobj->sd;
71         struct sysfs_dirent *sd;
72
73         if (grp->name) {
74                 sd = sysfs_get_dirent(dir_sd, grp->name);
75                 BUG_ON(!sd);
76         } else
77                 sd = sysfs_get(dir_sd);
78
79         remove_files(sd, grp);
80         if (grp->name)
81                 sysfs_remove_subdir(sd);
82
83         sysfs_put(sd);
84 }
85
86
87 EXPORT_SYMBOL_GPL(sysfs_create_group);
88 EXPORT_SYMBOL_GPL(sysfs_remove_group);