diff options
Diffstat (limited to 'include/linux/sysfs.h')
-rw-r--r-- | include/linux/sysfs.h | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 9d68fed50f11..f0496b3d1811 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/compiler.h> | 15 | #include <linux/compiler.h> |
16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
17 | #include <linux/list.h> | 17 | #include <linux/list.h> |
18 | #include <linux/lockdep.h> | ||
18 | #include <asm/atomic.h> | 19 | #include <asm/atomic.h> |
19 | 20 | ||
20 | struct kobject; | 21 | struct kobject; |
@@ -29,8 +30,33 @@ struct attribute { | |||
29 | const char *name; | 30 | const char *name; |
30 | struct module *owner; | 31 | struct module *owner; |
31 | mode_t mode; | 32 | mode_t mode; |
33 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
34 | struct lock_class_key *key; | ||
35 | struct lock_class_key skey; | ||
36 | #endif | ||
32 | }; | 37 | }; |
33 | 38 | ||
39 | /** | ||
40 | * sysfs_attr_init - initialize a dynamically allocated sysfs attribute | ||
41 | * @attr: struct attribute to initialize | ||
42 | * | ||
43 | * Initialize a dynamically allocated struct attribute so we can | ||
44 | * make lockdep happy. This is a new requirement for attributes | ||
45 | * and initially this is only needed when lockdep is enabled. | ||
46 | * Lockdep gives a nice error when your attribute is added to | ||
47 | * sysfs if you don't have this. | ||
48 | */ | ||
49 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
50 | #define sysfs_attr_init(attr) \ | ||
51 | do { \ | ||
52 | static struct lock_class_key __key; \ | ||
53 | \ | ||
54 | (attr)->key = &__key; \ | ||
55 | } while(0) | ||
56 | #else | ||
57 | #define sysfs_attr_init(attr) do {} while(0) | ||
58 | #endif | ||
59 | |||
34 | struct attribute_group { | 60 | struct attribute_group { |
35 | const char *name; | 61 | const char *name; |
36 | mode_t (*is_visible)(struct kobject *, | 62 | mode_t (*is_visible)(struct kobject *, |
@@ -74,6 +100,18 @@ struct bin_attribute { | |||
74 | struct vm_area_struct *vma); | 100 | struct vm_area_struct *vma); |
75 | }; | 101 | }; |
76 | 102 | ||
103 | /** | ||
104 | * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute | ||
105 | * @attr: struct bin_attribute to initialize | ||
106 | * | ||
107 | * Initialize a dynamically allocated struct bin_attribute so we | ||
108 | * can make lockdep happy. This is a new requirement for | ||
109 | * attributes and initially this is only needed when lockdep is | ||
110 | * enabled. Lockdep gives a nice error when your attribute is | ||
111 | * added to sysfs if you don't have this. | ||
112 | */ | ||
113 | #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) | ||
114 | |||
77 | struct sysfs_ops { | 115 | struct sysfs_ops { |
78 | ssize_t (*show)(struct kobject *, struct attribute *,char *); | 116 | ssize_t (*show)(struct kobject *, struct attribute *,char *); |
79 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); | 117 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); |
@@ -94,13 +132,17 @@ int __must_check sysfs_move_dir(struct kobject *kobj, | |||
94 | 132 | ||
95 | int __must_check sysfs_create_file(struct kobject *kobj, | 133 | int __must_check sysfs_create_file(struct kobject *kobj, |
96 | const struct attribute *attr); | 134 | const struct attribute *attr); |
135 | int __must_check sysfs_create_files(struct kobject *kobj, | ||
136 | const struct attribute **attr); | ||
97 | int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, | 137 | int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, |
98 | mode_t mode); | 138 | mode_t mode); |
99 | void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr); | 139 | void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr); |
140 | void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr); | ||
100 | 141 | ||
101 | int __must_check sysfs_create_bin_file(struct kobject *kobj, | 142 | int __must_check sysfs_create_bin_file(struct kobject *kobj, |
102 | struct bin_attribute *attr); | 143 | const struct bin_attribute *attr); |
103 | void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr); | 144 | void sysfs_remove_bin_file(struct kobject *kobj, |
145 | const struct bin_attribute *attr); | ||
104 | 146 | ||
105 | int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, | 147 | int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, |
106 | const char *name); | 148 | const char *name); |
@@ -109,6 +151,9 @@ int __must_check sysfs_create_link_nowarn(struct kobject *kobj, | |||
109 | const char *name); | 151 | const char *name); |
110 | void sysfs_remove_link(struct kobject *kobj, const char *name); | 152 | void sysfs_remove_link(struct kobject *kobj, const char *name); |
111 | 153 | ||
154 | int sysfs_rename_link(struct kobject *kobj, struct kobject *target, | ||
155 | const char *old_name, const char *new_name); | ||
156 | |||
112 | int __must_check sysfs_create_group(struct kobject *kobj, | 157 | int __must_check sysfs_create_group(struct kobject *kobj, |
113 | const struct attribute_group *grp); | 158 | const struct attribute_group *grp); |
114 | int sysfs_update_group(struct kobject *kobj, | 159 | int sysfs_update_group(struct kobject *kobj, |
@@ -163,6 +208,12 @@ static inline int sysfs_create_file(struct kobject *kobj, | |||
163 | return 0; | 208 | return 0; |
164 | } | 209 | } |
165 | 210 | ||
211 | static inline int sysfs_create_files(struct kobject *kobj, | ||
212 | const struct attribute **attr) | ||
213 | { | ||
214 | return 0; | ||
215 | } | ||
216 | |||
166 | static inline int sysfs_chmod_file(struct kobject *kobj, | 217 | static inline int sysfs_chmod_file(struct kobject *kobj, |
167 | struct attribute *attr, mode_t mode) | 218 | struct attribute *attr, mode_t mode) |
168 | { | 219 | { |
@@ -174,14 +225,19 @@ static inline void sysfs_remove_file(struct kobject *kobj, | |||
174 | { | 225 | { |
175 | } | 226 | } |
176 | 227 | ||
228 | static inline void sysfs_remove_files(struct kobject *kobj, | ||
229 | const struct attribute **attr) | ||
230 | { | ||
231 | } | ||
232 | |||
177 | static inline int sysfs_create_bin_file(struct kobject *kobj, | 233 | static inline int sysfs_create_bin_file(struct kobject *kobj, |
178 | struct bin_attribute *attr) | 234 | const struct bin_attribute *attr) |
179 | { | 235 | { |
180 | return 0; | 236 | return 0; |
181 | } | 237 | } |
182 | 238 | ||
183 | static inline void sysfs_remove_bin_file(struct kobject *kobj, | 239 | static inline void sysfs_remove_bin_file(struct kobject *kobj, |
184 | struct bin_attribute *attr) | 240 | const struct bin_attribute *attr) |
185 | { | 241 | { |
186 | } | 242 | } |
187 | 243 | ||
@@ -202,6 +258,12 @@ static inline void sysfs_remove_link(struct kobject *kobj, const char *name) | |||
202 | { | 258 | { |
203 | } | 259 | } |
204 | 260 | ||
261 | static inline int sysfs_rename_link(struct kobject *k, struct kobject *t, | ||
262 | const char *old_name, const char *new_name) | ||
263 | { | ||
264 | return 0; | ||
265 | } | ||
266 | |||
205 | static inline int sysfs_create_group(struct kobject *kobj, | 267 | static inline int sysfs_create_group(struct kobject *kobj, |
206 | const struct attribute_group *grp) | 268 | const struct attribute_group *grp) |
207 | { | 269 | { |