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>
16 #include <asm/semaphore.h>
20 static void remove_files(struct dentry
* dir
,
21 const struct attribute_group
* grp
)
23 struct attribute
*const* attr
;
25 for (attr
= grp
->attrs
; *attr
; attr
++)
26 sysfs_hash_and_remove(dir
,(*attr
)->name
);
29 static int create_files(struct dentry
* dir
,
30 const struct attribute_group
* grp
)
32 struct attribute
*const* attr
;
35 for (attr
= grp
->attrs
; *attr
&& !error
; attr
++) {
36 error
= sysfs_add_file(dir
, *attr
, SYSFS_KOBJ_ATTR
);
39 remove_files(dir
,grp
);
44 int sysfs_create_group(struct kobject
* kobj
,
45 const struct attribute_group
* grp
)
50 BUG_ON(!kobj
|| !kobj
->dentry
);
53 error
= sysfs_create_subdir(kobj
,grp
->name
,&dir
);
59 if ((error
= create_files(dir
,grp
))) {
61 sysfs_remove_subdir(dir
);
67 void sysfs_remove_group(struct kobject
* kobj
,
68 const struct attribute_group
* grp
)
73 dir
= lookup_one_len(grp
->name
, kobj
->dentry
,
76 dir
= dget(kobj
->dentry
);
78 remove_files(dir
,grp
);
80 sysfs_remove_subdir(dir
);
81 /* release the ref. taken in this routine */
86 EXPORT_SYMBOL_GPL(sysfs_create_group
);
87 EXPORT_SYMBOL_GPL(sysfs_remove_group
);