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>
17 #include <asm/semaphore.h>
21 static void remove_files(struct dentry
*dir
, struct kobject
*kobj
,
22 const struct attribute_group
*grp
)
24 struct attribute
*const* attr
;
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
;
39 for (i
= 0, attr
= grp
->attrs
; *attr
&& !error
; i
++, attr
++)
40 if (!grp
->is_visible
||
41 grp
->is_visible(kobj
, *attr
, i
))
43 sysfs_add_file(dir
, *attr
, SYSFS_KOBJ_ATTR
);
45 remove_files(dir
, kobj
, grp
);
50 int sysfs_create_group(struct kobject
* kobj
,
51 const struct attribute_group
* grp
)
56 BUG_ON(!kobj
|| !kobj
->dentry
);
59 error
= sysfs_create_subdir(kobj
,grp
->name
,&dir
);
65 error
= create_files(dir
, kobj
, grp
);
68 sysfs_remove_subdir(dir
);
74 void sysfs_remove_group(struct kobject
* kobj
,
75 const struct attribute_group
* grp
)
80 dir
= lookup_one_len_kern(grp
->name
, kobj
->dentry
,
85 dir
= dget(kobj
->dentry
);
87 remove_files(dir
, kobj
, grp
);
89 sysfs_remove_subdir(dir
);
90 /* release the ref. taken in this routine */
95 EXPORT_SYMBOL_GPL(sysfs_create_group
);
96 EXPORT_SYMBOL_GPL(sysfs_remove_group
);