Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* |
3 | * sysfs.h - definitions for the device driver filesystem | |
4 | * | |
5 | * Copyright (c) 2001,2002 Patrick Mochel | |
6 | * Copyright (c) 2004 Silicon Graphics, Inc. | |
6d66f5cd TH |
7 | * Copyright (c) 2007 SUSE Linux Products GmbH |
8 | * Copyright (c) 2007 Tejun Heo <teheo@suse.de> | |
1da177e4 | 9 | * |
0c1bc6b8 | 10 | * Please see Documentation/filesystems/sysfs.rst for more information. |
1da177e4 LT |
11 | */ |
12 | ||
13 | #ifndef _SYSFS_H_ | |
14 | #define _SYSFS_H_ | |
15 | ||
b8441ed2 | 16 | #include <linux/kernfs.h> |
4a7fb636 | 17 | #include <linux/compiler.h> |
5851fadc | 18 | #include <linux/errno.h> |
bf0acc33 | 19 | #include <linux/list.h> |
6992f533 | 20 | #include <linux/lockdep.h> |
8488a38f | 21 | #include <linux/kobject_ns.h> |
3493f69f | 22 | #include <linux/stat.h> |
60063497 | 23 | #include <linux/atomic.h> |
1da177e4 LT |
24 | |
25 | struct kobject; | |
26 | struct module; | |
6ab9cea1 | 27 | struct bin_attribute; |
3ff195b0 | 28 | enum kobj_ns_type; |
1da177e4 LT |
29 | |
30 | struct attribute { | |
59f69015 | 31 | const char *name; |
9104e427 | 32 | umode_t mode; |
6992f533 | 33 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
356c05d5 | 34 | bool ignore_lockdep:1; |
6992f533 EB |
35 | struct lock_class_key *key; |
36 | struct lock_class_key skey; | |
37 | #endif | |
1da177e4 LT |
38 | }; |
39 | ||
35960258 EB |
40 | /** |
41 | * sysfs_attr_init - initialize a dynamically allocated sysfs attribute | |
42 | * @attr: struct attribute to initialize | |
43 | * | |
44 | * Initialize a dynamically allocated struct attribute so we can | |
45 | * make lockdep happy. This is a new requirement for attributes | |
46 | * and initially this is only needed when lockdep is enabled. | |
47 | * Lockdep gives a nice error when your attribute is added to | |
48 | * sysfs if you don't have this. | |
49 | */ | |
6992f533 EB |
50 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
51 | #define sysfs_attr_init(attr) \ | |
52 | do { \ | |
53 | static struct lock_class_key __key; \ | |
54 | \ | |
55 | (attr)->key = &__key; \ | |
5da5c9c8 | 56 | } while (0) |
6992f533 | 57 | #else |
5da5c9c8 | 58 | #define sysfs_attr_init(attr) do {} while (0) |
6992f533 EB |
59 | #endif |
60 | ||
ba61af6f GR |
61 | /** |
62 | * struct attribute_group - data structure used to declare an attribute group. | |
63 | * @name: Optional: Attribute group name | |
d87c295f DW |
64 | * If specified, the attribute group will be created in a |
65 | * new subdirectory with this name. Additionally when a | |
66 | * group is named, @is_visible and @is_bin_visible may | |
67 | * return SYSFS_GROUP_INVISIBLE to control visibility of | |
68 | * the directory itself. | |
ba61af6f | 69 | * @is_visible: Optional: Function to return permissions associated with an |
d87c295f DW |
70 | * attribute of the group. Will be called repeatedly for |
71 | * each non-binary attribute in the group. Only read/write | |
7f5028cf | 72 | * permissions as well as SYSFS_PREALLOC are accepted. Must |
d87c295f DW |
73 | * return 0 if an attribute is not visible. The returned |
74 | * value will replace static permissions defined in struct | |
75 | * attribute. Use SYSFS_GROUP_VISIBLE() when assigning this | |
76 | * callback to specify separate _group_visible() and | |
77 | * _attr_visible() handlers. | |
7f5028cf EL |
78 | * @is_bin_visible: |
79 | * Optional: Function to return permissions associated with a | |
80 | * binary attribute of the group. Will be called repeatedly | |
81 | * for each binary attribute in the group. Only read/write | |
d87c295f DW |
82 | * permissions as well as SYSFS_PREALLOC (and the |
83 | * visibility flags for named groups) are accepted. Must | |
84 | * return 0 if a binary attribute is not visible. The | |
85 | * returned value will replace static permissions defined | |
86 | * in struct bin_attribute. If @is_visible is not set, Use | |
87 | * SYSFS_GROUP_VISIBLE() when assigning this callback to | |
88 | * specify separate _group_visible() and _attr_visible() | |
89 | * handlers. | |
bebf29b1 TW |
90 | * @bin_size: |
91 | * Optional: Function to return the size of a binary attribute | |
92 | * of the group. Will be called repeatedly for each binary | |
93 | * attribute in the group. Overwrites the size field embedded | |
94 | * inside the attribute itself. | |
ba61af6f GR |
95 | * @attrs: Pointer to NULL terminated list of attributes. |
96 | * @bin_attrs: Pointer to NULL terminated list of binary attributes. | |
97 | * Either attrs or bin_attrs or both must be provided. | |
98 | */ | |
1da177e4 | 99 | struct attribute_group { |
59f69015 | 100 | const char *name; |
587a1f16 | 101 | umode_t (*is_visible)(struct kobject *, |
d4acd722 | 102 | struct attribute *, int); |
7f5028cf | 103 | umode_t (*is_bin_visible)(struct kobject *, |
b626816f | 104 | const struct bin_attribute *, int); |
bebf29b1 TW |
105 | size_t (*bin_size)(struct kobject *, |
106 | const struct bin_attribute *, | |
107 | int); | |
59f69015 | 108 | struct attribute **attrs; |
906c508a | 109 | union { |
9bec9445 | 110 | const struct bin_attribute *const *bin_attrs; |
906c508a TW |
111 | const struct bin_attribute *const *bin_attrs_new; |
112 | }; | |
1da177e4 LT |
113 | }; |
114 | ||
d87c295f DW |
115 | #define SYSFS_PREALLOC 010000 |
116 | #define SYSFS_GROUP_INVISIBLE 020000 | |
117 | ||
118 | /* | |
aa3c8899 DW |
119 | * DEFINE_SYSFS_GROUP_VISIBLE(name): |
120 | * A helper macro to pair with the assignment of ".is_visible = | |
121 | * SYSFS_GROUP_VISIBLE(name)", that arranges for the directory | |
122 | * associated with a named attribute_group to optionally be hidden. | |
123 | * This allows for static declaration of attribute_groups, and the | |
124 | * simplification of attribute visibility lifetime that implies, | |
125 | * without polluting sysfs with empty attribute directories. | |
126 | * Ex. | |
127 | * | |
128 | * static umode_t example_attr_visible(struct kobject *kobj, | |
129 | * struct attribute *attr, int n) | |
130 | * { | |
131 | * if (example_attr_condition) | |
132 | * return 0; | |
133 | * else if (ro_attr_condition) | |
134 | * return 0444; | |
135 | * return a->mode; | |
136 | * } | |
137 | * | |
138 | * static bool example_group_visible(struct kobject *kobj) | |
139 | * { | |
140 | * if (example_group_condition) | |
141 | * return false; | |
142 | * return true; | |
143 | * } | |
144 | * | |
145 | * DEFINE_SYSFS_GROUP_VISIBLE(example); | |
146 | * | |
147 | * static struct attribute_group example_group = { | |
148 | * .name = "example", | |
149 | * .is_visible = SYSFS_GROUP_VISIBLE(example), | |
150 | * .attrs = &example_attrs, | |
151 | * }; | |
152 | * | |
153 | * Note that it expects <name>_attr_visible and <name>_group_visible to | |
04edfa7f DW |
154 | * be defined. For cases where individual attributes do not need |
155 | * separate visibility consideration, only entire group visibility at | |
156 | * once, see DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(). | |
d87c295f DW |
157 | */ |
158 | #define DEFINE_SYSFS_GROUP_VISIBLE(name) \ | |
159 | static inline umode_t sysfs_group_visible_##name( \ | |
160 | struct kobject *kobj, struct attribute *attr, int n) \ | |
161 | { \ | |
162 | if (n == 0 && !name##_group_visible(kobj)) \ | |
163 | return SYSFS_GROUP_INVISIBLE; \ | |
164 | return name##_attr_visible(kobj, attr, n); \ | |
165 | } | |
166 | ||
04edfa7f DW |
167 | /* |
168 | * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name): | |
169 | * A helper macro to pair with SYSFS_GROUP_VISIBLE() that like | |
170 | * DEFINE_SYSFS_GROUP_VISIBLE() controls group visibility, but does | |
171 | * not require the implementation of a per-attribute visibility | |
172 | * callback. | |
173 | * Ex. | |
174 | * | |
175 | * static bool example_group_visible(struct kobject *kobj) | |
176 | * { | |
177 | * if (example_group_condition) | |
178 | * return false; | |
179 | * return true; | |
180 | * } | |
181 | * | |
182 | * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(example); | |
183 | * | |
184 | * static struct attribute_group example_group = { | |
185 | * .name = "example", | |
186 | * .is_visible = SYSFS_GROUP_VISIBLE(example), | |
187 | * .attrs = &example_attrs, | |
188 | * }; | |
189 | */ | |
190 | #define DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name) \ | |
191 | static inline umode_t sysfs_group_visible_##name( \ | |
192 | struct kobject *kobj, struct attribute *a, int n) \ | |
193 | { \ | |
194 | if (n == 0 && !name##_group_visible(kobj)) \ | |
195 | return SYSFS_GROUP_INVISIBLE; \ | |
196 | return a->mode; \ | |
197 | } | |
198 | ||
d87c295f DW |
199 | /* |
200 | * Same as DEFINE_SYSFS_GROUP_VISIBLE, but for groups with only binary | |
aa3c8899 DW |
201 | * attributes. If an attribute_group defines both text and binary |
202 | * attributes, the group visibility is determined by the function | |
203 | * specified to is_visible() not is_bin_visible() | |
d87c295f | 204 | */ |
b626816f TW |
205 | #define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) \ |
206 | static inline umode_t sysfs_group_visible_##name( \ | |
207 | struct kobject *kobj, const struct bin_attribute *attr, int n) \ | |
208 | { \ | |
209 | if (n == 0 && !name##_group_visible(kobj)) \ | |
210 | return SYSFS_GROUP_INVISIBLE; \ | |
211 | return name##_attr_visible(kobj, attr, n); \ | |
d87c295f DW |
212 | } |
213 | ||
b626816f TW |
214 | #define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) \ |
215 | static inline umode_t sysfs_group_visible_##name( \ | |
216 | struct kobject *kobj, const struct bin_attribute *a, int n) \ | |
217 | { \ | |
218 | if (n == 0 && !name##_group_visible(kobj)) \ | |
219 | return SYSFS_GROUP_INVISIBLE; \ | |
220 | return a->mode; \ | |
04edfa7f DW |
221 | } |
222 | ||
d87c295f DW |
223 | #define SYSFS_GROUP_VISIBLE(fn) sysfs_group_visible_##fn |
224 | ||
3ec78790 RD |
225 | /* |
226 | * Use these macros to make defining attributes easier. | |
227 | * See include/linux/device.h for examples.. | |
1da177e4 LT |
228 | */ |
229 | ||
5da5c9c8 | 230 | #define __ATTR(_name, _mode, _show, _store) { \ |
58f86cc8 RR |
231 | .attr = {.name = __stringify(_name), \ |
232 | .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ | |
aa01aa3c OS |
233 | .show = _show, \ |
234 | .store = _store, \ | |
1da177e4 LT |
235 | } |
236 | ||
2b75869b N |
237 | #define __ATTR_PREALLOC(_name, _mode, _show, _store) { \ |
238 | .attr = {.name = __stringify(_name), \ | |
239 | .mode = SYSFS_PREALLOC | VERIFY_OCTAL_PERMISSIONS(_mode) },\ | |
240 | .show = _show, \ | |
241 | .store = _store, \ | |
242 | } | |
243 | ||
aa01aa3c | 244 | #define __ATTR_RO(_name) { \ |
353c6dda | 245 | .attr = { .name = __stringify(_name), .mode = 0444 }, \ |
aa01aa3c | 246 | .show = _name##_show, \ |
1da177e4 LT |
247 | } |
248 | ||
af97a77b GKH |
249 | #define __ATTR_RO_MODE(_name, _mode) { \ |
250 | .attr = { .name = __stringify(_name), \ | |
251 | .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ | |
252 | .show = _name##_show, \ | |
253 | } | |
254 | ||
3022c6a1 DW |
255 | #define __ATTR_RW_MODE(_name, _mode) { \ |
256 | .attr = { .name = __stringify(_name), \ | |
257 | .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ | |
258 | .show = _name##_show, \ | |
259 | .store = _name##_store, \ | |
260 | } | |
261 | ||
a65fcce7 | 262 | #define __ATTR_WO(_name) { \ |
353c6dda | 263 | .attr = { .name = __stringify(_name), .mode = 0200 }, \ |
a65fcce7 GKH |
264 | .store = _name##_store, \ |
265 | } | |
266 | ||
353c6dda | 267 | #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) |
b9b32597 | 268 | |
1da177e4 | 269 | #define __ATTR_NULL { .attr = { .name = NULL } } |
356c05d5 AS |
270 | |
271 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | |
272 | #define __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) { \ | |
273 | .attr = {.name = __stringify(_name), .mode = _mode, \ | |
274 | .ignore_lockdep = true }, \ | |
275 | .show = _show, \ | |
276 | .store = _store, \ | |
277 | } | |
278 | #else | |
279 | #define __ATTR_IGNORE_LOCKDEP __ATTR | |
280 | #endif | |
1da177e4 | 281 | |
3493f69f OS |
282 | #define __ATTRIBUTE_GROUPS(_name) \ |
283 | static const struct attribute_group *_name##_groups[] = { \ | |
284 | &_name##_group, \ | |
f2f37f58 GKH |
285 | NULL, \ |
286 | } | |
287 | ||
3493f69f OS |
288 | #define ATTRIBUTE_GROUPS(_name) \ |
289 | static const struct attribute_group _name##_group = { \ | |
290 | .attrs = _name##_attrs, \ | |
291 | }; \ | |
292 | __ATTRIBUTE_GROUPS(_name) | |
293 | ||
46ad0572 HK |
294 | #define BIN_ATTRIBUTE_GROUPS(_name) \ |
295 | static const struct attribute_group _name##_group = { \ | |
92d6254f | 296 | .bin_attrs_new = _name##_attrs, \ |
46ad0572 HK |
297 | }; \ |
298 | __ATTRIBUTE_GROUPS(_name) | |
299 | ||
2c3c8bea | 300 | struct file; |
1da177e4 | 301 | struct vm_area_struct; |
74b30195 | 302 | struct address_space; |
1da177e4 LT |
303 | |
304 | struct bin_attribute { | |
305 | struct attribute attr; | |
306 | size_t size; | |
307 | void *private; | |
f06aff92 | 308 | struct address_space *(*f_mapping)(void); |
97d06802 | 309 | ssize_t (*read)(struct file *, struct kobject *, const struct bin_attribute *, |
91a69029 | 310 | char *, loff_t, size_t); |
eb2e6c3a TW |
311 | ssize_t (*read_new)(struct file *, struct kobject *, const struct bin_attribute *, |
312 | char *, loff_t, size_t); | |
97d06802 | 313 | ssize_t (*write)(struct file *, struct kobject *, const struct bin_attribute *, |
91a69029 | 314 | char *, loff_t, size_t); |
eb2e6c3a TW |
315 | ssize_t (*write_new)(struct file *, struct kobject *, |
316 | const struct bin_attribute *, char *, loff_t, size_t); | |
699e7b85 | 317 | loff_t (*llseek)(struct file *, struct kobject *, const struct bin_attribute *, |
0fedefd4 | 318 | loff_t, int); |
94a20fb9 | 319 | int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *attr, |
1da177e4 LT |
320 | struct vm_area_struct *vma); |
321 | }; | |
322 | ||
35960258 EB |
323 | /** |
324 | * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute | |
325 | * @attr: struct bin_attribute to initialize | |
326 | * | |
327 | * Initialize a dynamically allocated struct bin_attribute so we | |
328 | * can make lockdep happy. This is a new requirement for | |
329 | * attributes and initially this is only needed when lockdep is | |
330 | * enabled. Lockdep gives a nice error when your attribute is | |
331 | * added to sysfs if you don't have this. | |
332 | */ | |
62e877b8 | 333 | #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) |
6992f533 | 334 | |
3493f69f OS |
335 | /* macros to create static binary attributes easier */ |
336 | #define __BIN_ATTR(_name, _mode, _read, _write, _size) { \ | |
337 | .attr = { .name = __stringify(_name), .mode = _mode }, \ | |
97d06802 TW |
338 | .read = _read, \ |
339 | .write = _write, \ | |
3493f69f OS |
340 | .size = _size, \ |
341 | } | |
342 | ||
ae587a50 TW |
343 | #define __BIN_ATTR_RO(_name, _size) \ |
344 | __BIN_ATTR(_name, 0444, _name##_read, NULL, _size) | |
e4b63603 | 345 | |
ae587a50 TW |
346 | #define __BIN_ATTR_WO(_name, _size) \ |
347 | __BIN_ATTR(_name, 0200, NULL, _name##_write, _size) | |
7f905761 | 348 | |
353c6dda JP |
349 | #define __BIN_ATTR_RW(_name, _size) \ |
350 | __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size) | |
3493f69f OS |
351 | |
352 | #define __BIN_ATTR_NULL __ATTR_NULL | |
353 | ||
354 | #define BIN_ATTR(_name, _mode, _read, _write, _size) \ | |
355 | struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \ | |
356 | _write, _size) | |
357 | ||
358 | #define BIN_ATTR_RO(_name, _size) \ | |
359 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size) | |
360 | ||
7f905761 GKH |
361 | #define BIN_ATTR_WO(_name, _size) \ |
362 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size) | |
363 | ||
3493f69f OS |
364 | #define BIN_ATTR_RW(_name, _size) \ |
365 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) | |
366 | ||
9d6794fe | 367 | |
ae587a50 TW |
368 | #define __BIN_ATTR_ADMIN_RO(_name, _size) \ |
369 | __BIN_ATTR(_name, 0400, _name##_read, NULL, _size) | |
9d6794fe IW |
370 | |
371 | #define __BIN_ATTR_ADMIN_RW(_name, _size) \ | |
372 | __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size) | |
373 | ||
374 | #define BIN_ATTR_ADMIN_RO(_name, _size) \ | |
375 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size) | |
376 | ||
377 | #define BIN_ATTR_ADMIN_RW(_name, _size) \ | |
378 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size) | |
379 | ||
ae587a50 TW |
380 | #define __BIN_ATTR_SIMPLE_RO(_name, _mode) \ |
381 | __BIN_ATTR(_name, _mode, sysfs_bin_attr_simple_read, NULL, 0) | |
d48c0319 LW |
382 | |
383 | #define BIN_ATTR_SIMPLE_RO(_name) \ | |
384 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0444) | |
385 | ||
386 | #define BIN_ATTR_SIMPLE_ADMIN_RO(_name) \ | |
387 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0400) | |
388 | ||
1da177e4 | 389 | struct sysfs_ops { |
5da5c9c8 GKH |
390 | ssize_t (*show)(struct kobject *, struct attribute *, char *); |
391 | ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); | |
1da177e4 LT |
392 | }; |
393 | ||
1da177e4 LT |
394 | #ifdef CONFIG_SYSFS |
395 | ||
e34ff490 | 396 | int __must_check sysfs_create_dir_ns(struct kobject *kobj, const void *ns); |
59f69015 | 397 | void sysfs_remove_dir(struct kobject *kobj); |
e34ff490 TH |
398 | int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, |
399 | const void *new_ns); | |
400 | int __must_check sysfs_move_dir_ns(struct kobject *kobj, | |
401 | struct kobject *new_parent_kobj, | |
402 | const void *new_ns); | |
87d2846f EB |
403 | int __must_check sysfs_create_mount_point(struct kobject *parent_kobj, |
404 | const char *name); | |
405 | void sysfs_remove_mount_point(struct kobject *parent_kobj, | |
406 | const char *name); | |
31e5abe9 | 407 | |
58292cbe TH |
408 | int __must_check sysfs_create_file_ns(struct kobject *kobj, |
409 | const struct attribute *attr, | |
410 | const void *ns); | |
1c205ae1 | 411 | int __must_check sysfs_create_files(struct kobject *kobj, |
9ee4685c | 412 | const struct attribute * const *attr); |
49c19400 | 413 | int __must_check sysfs_chmod_file(struct kobject *kobj, |
48176a97 | 414 | const struct attribute *attr, umode_t mode); |
2afc9166 BVA |
415 | struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj, |
416 | const struct attribute *attr); | |
417 | void sysfs_unbreak_active_protection(struct kernfs_node *kn); | |
58292cbe TH |
418 | void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, |
419 | const void *ns); | |
6b0afc2a | 420 | bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr); |
9ee4685c | 421 | void sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attr); |
1da177e4 | 422 | |
4a7fb636 | 423 | int __must_check sysfs_create_bin_file(struct kobject *kobj, |
66ecb92b PC |
424 | const struct bin_attribute *attr); |
425 | void sysfs_remove_bin_file(struct kobject *kobj, | |
426 | const struct bin_attribute *attr); | |
1da177e4 | 427 | |
59f69015 TH |
428 | int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, |
429 | const char *name); | |
36ce6dad CH |
430 | int __must_check sysfs_create_link_nowarn(struct kobject *kobj, |
431 | struct kobject *target, | |
432 | const char *name); | |
59f69015 TH |
433 | void sysfs_remove_link(struct kobject *kobj, const char *name); |
434 | ||
4b30ee58 TH |
435 | int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target, |
436 | const char *old_name, const char *new_name, | |
437 | const void *new_ns); | |
7cb32942 | 438 | |
746edb7a EB |
439 | void sysfs_delete_link(struct kobject *dir, struct kobject *targ, |
440 | const char *name); | |
441 | ||
59f69015 TH |
442 | int __must_check sysfs_create_group(struct kobject *kobj, |
443 | const struct attribute_group *grp); | |
3e9b2bae GKH |
444 | int __must_check sysfs_create_groups(struct kobject *kobj, |
445 | const struct attribute_group **groups); | |
aac1f7f9 JO |
446 | int __must_check sysfs_update_groups(struct kobject *kobj, |
447 | const struct attribute_group **groups); | |
0f423895 JB |
448 | int sysfs_update_group(struct kobject *kobj, |
449 | const struct attribute_group *grp); | |
59f69015 TH |
450 | void sysfs_remove_group(struct kobject *kobj, |
451 | const struct attribute_group *grp); | |
3e9b2bae GKH |
452 | void sysfs_remove_groups(struct kobject *kobj, |
453 | const struct attribute_group **groups); | |
dfa87c82 | 454 | int sysfs_add_file_to_group(struct kobject *kobj, |
59f69015 | 455 | const struct attribute *attr, const char *group); |
dfa87c82 | 456 | void sysfs_remove_file_from_group(struct kobject *kobj, |
59f69015 | 457 | const struct attribute *attr, const char *group); |
69d44ffb AS |
458 | int sysfs_merge_group(struct kobject *kobj, |
459 | const struct attribute_group *grp); | |
460 | void sysfs_unmerge_group(struct kobject *kobj, | |
461 | const struct attribute_group *grp); | |
0bb8f3d6 RW |
462 | int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, |
463 | struct kobject *target, const char *link_name); | |
464 | void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, | |
465 | const char *link_name); | |
9255782f SJ |
466 | int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, |
467 | struct kobject *target_kobj, | |
468 | const char *target_name, | |
469 | const char *symlink_name); | |
dfa87c82 | 470 | |
8c0e3998 | 471 | void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); |
3ff195b0 | 472 | |
f1282c84 | 473 | int __must_check sysfs_init(void); |
f20a9ead | 474 | |
fa4cd451 TH |
475 | static inline void sysfs_enable_ns(struct kernfs_node *kn) |
476 | { | |
477 | return kernfs_enable_ns(kn); | |
478 | } | |
479 | ||
f70ce185 CB |
480 | int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid, |
481 | kgid_t kgid); | |
2c4f9401 | 482 | int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid); |
0666a3ae CB |
483 | int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ, |
484 | const char *name, kuid_t kuid, kgid_t kgid); | |
303a4276 CB |
485 | int sysfs_groups_change_owner(struct kobject *kobj, |
486 | const struct attribute_group **groups, | |
487 | kuid_t kuid, kgid_t kgid); | |
488 | int sysfs_group_change_owner(struct kobject *kobj, | |
489 | const struct attribute_group *groups, kuid_t kuid, | |
490 | kgid_t kgid); | |
2efc459d JP |
491 | __printf(2, 3) |
492 | int sysfs_emit(char *buf, const char *fmt, ...); | |
493 | __printf(3, 4) | |
494 | int sysfs_emit_at(char *buf, int at, const char *fmt, ...); | |
f70ce185 | 495 | |
d48c0319 | 496 | ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj, |
3675a926 | 497 | const struct bin_attribute *attr, char *buf, |
d48c0319 LW |
498 | loff_t off, size_t count); |
499 | ||
1da177e4 LT |
500 | #else /* CONFIG_SYSFS */ |
501 | ||
e34ff490 | 502 | static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) |
1da177e4 LT |
503 | { |
504 | return 0; | |
505 | } | |
506 | ||
59f69015 | 507 | static inline void sysfs_remove_dir(struct kobject *kobj) |
1da177e4 | 508 | { |
1da177e4 LT |
509 | } |
510 | ||
e34ff490 TH |
511 | static inline int sysfs_rename_dir_ns(struct kobject *kobj, |
512 | const char *new_name, const void *new_ns) | |
1da177e4 | 513 | { |
0b4a4fea | 514 | return 0; |
1da177e4 LT |
515 | } |
516 | ||
e34ff490 TH |
517 | static inline int sysfs_move_dir_ns(struct kobject *kobj, |
518 | struct kobject *new_parent_kobj, | |
519 | const void *new_ns) | |
8a82472f CH |
520 | { |
521 | return 0; | |
522 | } | |
523 | ||
87d2846f EB |
524 | static inline int sysfs_create_mount_point(struct kobject *parent_kobj, |
525 | const char *name) | |
526 | { | |
527 | return 0; | |
528 | } | |
529 | ||
530 | static inline void sysfs_remove_mount_point(struct kobject *parent_kobj, | |
531 | const char *name) | |
532 | { | |
533 | } | |
534 | ||
58292cbe TH |
535 | static inline int sysfs_create_file_ns(struct kobject *kobj, |
536 | const struct attribute *attr, | |
537 | const void *ns) | |
1da177e4 LT |
538 | { |
539 | return 0; | |
540 | } | |
541 | ||
1c205ae1 | 542 | static inline int sysfs_create_files(struct kobject *kobj, |
9ee4685c | 543 | const struct attribute * const *attr) |
1c205ae1 AK |
544 | { |
545 | return 0; | |
546 | } | |
547 | ||
59f69015 | 548 | static inline int sysfs_chmod_file(struct kobject *kobj, |
48176a97 | 549 | const struct attribute *attr, umode_t mode) |
31e5abe9 KS |
550 | { |
551 | return 0; | |
552 | } | |
1da177e4 | 553 | |
2afc9166 BVA |
554 | static inline struct kernfs_node * |
555 | sysfs_break_active_protection(struct kobject *kobj, | |
556 | const struct attribute *attr) | |
557 | { | |
558 | return NULL; | |
559 | } | |
560 | ||
561 | static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn) | |
562 | { | |
563 | } | |
564 | ||
58292cbe TH |
565 | static inline void sysfs_remove_file_ns(struct kobject *kobj, |
566 | const struct attribute *attr, | |
567 | const void *ns) | |
1da177e4 | 568 | { |
1da177e4 LT |
569 | } |
570 | ||
6b0afc2a TH |
571 | static inline bool sysfs_remove_file_self(struct kobject *kobj, |
572 | const struct attribute *attr) | |
573 | { | |
574 | return false; | |
575 | } | |
576 | ||
1c205ae1 | 577 | static inline void sysfs_remove_files(struct kobject *kobj, |
9ee4685c | 578 | const struct attribute * const *attr) |
1c205ae1 AK |
579 | { |
580 | } | |
581 | ||
59f69015 | 582 | static inline int sysfs_create_bin_file(struct kobject *kobj, |
66ecb92b | 583 | const struct bin_attribute *attr) |
1da177e4 LT |
584 | { |
585 | return 0; | |
586 | } | |
587 | ||
3612e06b | 588 | static inline void sysfs_remove_bin_file(struct kobject *kobj, |
66ecb92b | 589 | const struct bin_attribute *attr) |
1da177e4 | 590 | { |
1da177e4 LT |
591 | } |
592 | ||
59f69015 TH |
593 | static inline int sysfs_create_link(struct kobject *kobj, |
594 | struct kobject *target, const char *name) | |
1da177e4 LT |
595 | { |
596 | return 0; | |
597 | } | |
598 | ||
36ce6dad CH |
599 | static inline int sysfs_create_link_nowarn(struct kobject *kobj, |
600 | struct kobject *target, | |
601 | const char *name) | |
602 | { | |
603 | return 0; | |
604 | } | |
605 | ||
59f69015 | 606 | static inline void sysfs_remove_link(struct kobject *kobj, const char *name) |
1da177e4 | 607 | { |
1da177e4 LT |
608 | } |
609 | ||
4b30ee58 TH |
610 | static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t, |
611 | const char *old_name, | |
612 | const char *new_name, const void *ns) | |
7cb32942 EB |
613 | { |
614 | return 0; | |
615 | } | |
616 | ||
746edb7a EB |
617 | static inline void sysfs_delete_link(struct kobject *k, struct kobject *t, |
618 | const char *name) | |
619 | { | |
620 | } | |
621 | ||
59f69015 TH |
622 | static inline int sysfs_create_group(struct kobject *kobj, |
623 | const struct attribute_group *grp) | |
1da177e4 LT |
624 | { |
625 | return 0; | |
626 | } | |
627 | ||
f7998780 GKH |
628 | static inline int sysfs_create_groups(struct kobject *kobj, |
629 | const struct attribute_group **groups) | |
630 | { | |
574979c6 | 631 | return 0; |
f7998780 GKH |
632 | } |
633 | ||
aac1f7f9 JO |
634 | static inline int sysfs_update_groups(struct kobject *kobj, |
635 | const struct attribute_group **groups) | |
636 | { | |
637 | return 0; | |
638 | } | |
639 | ||
1cbfb7a5 RD |
640 | static inline int sysfs_update_group(struct kobject *kobj, |
641 | const struct attribute_group *grp) | |
642 | { | |
643 | return 0; | |
644 | } | |
645 | ||
59f69015 TH |
646 | static inline void sysfs_remove_group(struct kobject *kobj, |
647 | const struct attribute_group *grp) | |
1da177e4 | 648 | { |
1da177e4 LT |
649 | } |
650 | ||
f7998780 GKH |
651 | static inline void sysfs_remove_groups(struct kobject *kobj, |
652 | const struct attribute_group **groups) | |
653 | { | |
654 | } | |
655 | ||
dfa87c82 AS |
656 | static inline int sysfs_add_file_to_group(struct kobject *kobj, |
657 | const struct attribute *attr, const char *group) | |
658 | { | |
659 | return 0; | |
660 | } | |
661 | ||
662 | static inline void sysfs_remove_file_from_group(struct kobject *kobj, | |
d701d8a3 | 663 | const struct attribute *attr, const char *group) |
dfa87c82 | 664 | { |
dfa87c82 AS |
665 | } |
666 | ||
69d44ffb AS |
667 | static inline int sysfs_merge_group(struct kobject *kobj, |
668 | const struct attribute_group *grp) | |
669 | { | |
670 | return 0; | |
671 | } | |
672 | ||
673 | static inline void sysfs_unmerge_group(struct kobject *kobj, | |
674 | const struct attribute_group *grp) | |
675 | { | |
676 | } | |
677 | ||
0bb8f3d6 RW |
678 | static inline int sysfs_add_link_to_group(struct kobject *kobj, |
679 | const char *group_name, struct kobject *target, | |
680 | const char *link_name) | |
681 | { | |
682 | return 0; | |
683 | } | |
684 | ||
685 | static inline void sysfs_remove_link_from_group(struct kobject *kobj, | |
686 | const char *group_name, const char *link_name) | |
687 | { | |
688 | } | |
689 | ||
9255782f SJ |
690 | static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, |
691 | struct kobject *target_kobj, | |
692 | const char *target_name, | |
693 | const char *symlink_name) | |
694 | { | |
695 | return 0; | |
696 | } | |
697 | ||
8c0e3998 TP |
698 | static inline void sysfs_notify(struct kobject *kobj, const char *dir, |
699 | const char *attr) | |
4508a7a7 N |
700 | { |
701 | } | |
702 | ||
f20a9ead AM |
703 | static inline int __must_check sysfs_init(void) |
704 | { | |
705 | return 0; | |
706 | } | |
707 | ||
fa4cd451 TH |
708 | static inline void sysfs_enable_ns(struct kernfs_node *kn) |
709 | { | |
710 | } | |
711 | ||
f70ce185 CB |
712 | static inline int sysfs_file_change_owner(struct kobject *kobj, |
713 | const char *name, kuid_t kuid, | |
0666a3ae CB |
714 | kgid_t kgid) |
715 | { | |
716 | return 0; | |
717 | } | |
718 | ||
719 | static inline int sysfs_link_change_owner(struct kobject *kobj, | |
720 | struct kobject *targ, | |
721 | const char *name, kuid_t kuid, | |
f70ce185 CB |
722 | kgid_t kgid) |
723 | { | |
724 | return 0; | |
725 | } | |
726 | ||
2c4f9401 CB |
727 | static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid) |
728 | { | |
729 | return 0; | |
730 | } | |
731 | ||
303a4276 CB |
732 | static inline int sysfs_groups_change_owner(struct kobject *kobj, |
733 | const struct attribute_group **groups, | |
734 | kuid_t kuid, kgid_t kgid) | |
735 | { | |
736 | return 0; | |
737 | } | |
738 | ||
739 | static inline int sysfs_group_change_owner(struct kobject *kobj, | |
8511d72f CB |
740 | const struct attribute_group *groups, |
741 | kuid_t kuid, kgid_t kgid) | |
303a4276 CB |
742 | { |
743 | return 0; | |
744 | } | |
745 | ||
2efc459d JP |
746 | __printf(2, 3) |
747 | static inline int sysfs_emit(char *buf, const char *fmt, ...) | |
748 | { | |
749 | return 0; | |
750 | } | |
751 | ||
752 | __printf(3, 4) | |
753 | static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...) | |
754 | { | |
755 | return 0; | |
756 | } | |
44a45be5 LW |
757 | |
758 | static inline ssize_t sysfs_bin_attr_simple_read(struct file *file, | |
759 | struct kobject *kobj, | |
3675a926 | 760 | const struct bin_attribute *attr, |
44a45be5 LW |
761 | char *buf, loff_t off, |
762 | size_t count) | |
763 | { | |
764 | return 0; | |
765 | } | |
1da177e4 LT |
766 | #endif /* CONFIG_SYSFS */ |
767 | ||
58292cbe TH |
768 | static inline int __must_check sysfs_create_file(struct kobject *kobj, |
769 | const struct attribute *attr) | |
770 | { | |
771 | return sysfs_create_file_ns(kobj, attr, NULL); | |
772 | } | |
773 | ||
774 | static inline void sysfs_remove_file(struct kobject *kobj, | |
775 | const struct attribute *attr) | |
776 | { | |
78e1da62 | 777 | sysfs_remove_file_ns(kobj, attr, NULL); |
58292cbe TH |
778 | } |
779 | ||
4b30ee58 TH |
780 | static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target, |
781 | const char *old_name, const char *new_name) | |
782 | { | |
783 | return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL); | |
784 | } | |
785 | ||
324a56e1 | 786 | static inline void sysfs_notify_dirent(struct kernfs_node *kn) |
ccf73cf3 | 787 | { |
324a56e1 | 788 | kernfs_notify(kn); |
ccf73cf3 TH |
789 | } |
790 | ||
324a56e1 | 791 | static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent, |
89cf2a20 | 792 | const char *name) |
388975cc | 793 | { |
324a56e1 | 794 | return kernfs_find_and_get(parent, name); |
388975cc TH |
795 | } |
796 | ||
324a56e1 | 797 | static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn) |
024f6471 | 798 | { |
324a56e1 TH |
799 | kernfs_get(kn); |
800 | return kn; | |
ccf73cf3 TH |
801 | } |
802 | ||
324a56e1 | 803 | static inline void sysfs_put(struct kernfs_node *kn) |
ccf73cf3 | 804 | { |
324a56e1 | 805 | kernfs_put(kn); |
024f6471 TH |
806 | } |
807 | ||
1da177e4 | 808 | #endif /* _SYSFS_H_ */ |