1 /* SPDX-License-Identifier: GPL-2.0 */
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.
7 * Copyright (c) 2007 SUSE Linux Products GmbH
8 * Copyright (c) 2007 Tejun Heo <[email protected]>
9 *
10 * Please see Documentation/filesystems/sysfs.rst for more information.
11 */
12
13 #ifndef _SYSFS_H_
14 #define _SYSFS_H_
15
16 #include <linux/kernfs.h>
17 #include <linux/compiler.h>
18 #include <linux/errno.h>
19 #include <linux/list.h>
20 #include <linux/lockdep.h>
21 #include <linux/kobject_ns.h>
22 #include <linux/stat.h>
23 #include <linux/atomic.h>
24
25 struct kobject;
26 struct module;
27 struct bin_attribute;
28 enum kobj_ns_type;
29
30 struct attribute {
31 const char *name;
32 umode_t mode;
33 #ifdef CONFIG_DEBUG_LOCK_ALLOC
34 bool ignore_lockdep:1;
35 struct lock_class_key *key;
36 struct lock_class_key skey;
37 #endif
38 };
39
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 */
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; \
56 } while (0)
57 #else
58 #define sysfs_attr_init(attr) do {} while (0)
59 #endif
60
61 /**
62 * struct attribute_group - data structure used to declare an attribute group.
63 * @name: Optional: Attribute group name
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.
69 * @is_visible: Optional: Function to return permissions associated with an
70 * attribute of the group. Will be called repeatedly for
71 * each non-binary attribute in the group. Only read/write
72 * permissions as well as SYSFS_PREALLOC are accepted. Must
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.
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
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.
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.
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 */
99 struct attribute_group {
100 const char *name;
101 umode_t (*is_visible)(struct kobject *,
102 struct attribute *, int);
103 umode_t (*is_bin_visible)(struct kobject *,
104 const struct bin_attribute *, int);
105 size_t (*bin_size)(struct kobject *,
106 const struct bin_attribute *,
107 int);
108 struct attribute **attrs;
109 union {
110 struct bin_attribute **bin_attrs;
111 const struct bin_attribute *const *bin_attrs_new;
112 };
113 };
114
115 #define SYSFS_PREALLOC 010000
116 #define SYSFS_GROUP_INVISIBLE 020000
117
118 /*
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
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().
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
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
199 /*
200 * Same as DEFINE_SYSFS_GROUP_VISIBLE, but for groups with only binary
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()
204 */
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); \
212 }
213
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; \
221 }
222
223 #define SYSFS_GROUP_VISIBLE(fn) sysfs_group_visible_##fn
224
225 /*
226 * Use these macros to make defining attributes easier.
227 * See include/linux/device.h for examples..
228 */
229
230 #define __ATTR(_name, _mode, _show, _store) { \
231 .attr = {.name = __stringify(_name), \
232 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
233 .show = _show, \
234 .store = _store, \
235 }
236
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
244 #define __ATTR_RO(_name) { \
245 .attr = { .name = __stringify(_name), .mode = 0444 }, \
246 .show = _name##_show, \
247 }
248
249 #define __ATTR_RO_MODE(_name, _mode) { \
250 .attr = { .name = __stringify(_name), \
251 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
252 .show = _name##_show, \
253 }
254
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
262 #define __ATTR_WO(_name) { \
263 .attr = { .name = __stringify(_name), .mode = 0200 }, \
264 .store = _name##_store, \
265 }
266
267 #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)
268
269 #define __ATTR_NULL { .attr = { .name = NULL } }
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
281
282 #define __ATTRIBUTE_GROUPS(_name) \
283 static const struct attribute_group *_name##_groups[] = { \
284 &_name##_group, \
285 NULL, \
286 }
287
288 #define ATTRIBUTE_GROUPS(_name) \
289 static const struct attribute_group _name##_group = { \
290 .attrs = _name##_attrs, \
291 }; \
292 __ATTRIBUTE_GROUPS(_name)
293
294 #define BIN_ATTRIBUTE_GROUPS(_name) \
295 static const struct attribute_group _name##_group = { \
296 .bin_attrs_new = _name##_attrs, \
297 }; \
298 __ATTRIBUTE_GROUPS(_name)
299
300 struct file;
301 struct vm_area_struct;
302 struct address_space;
303
304 struct bin_attribute {
305 struct attribute attr;
306 size_t size;
307 void *private;
308 struct address_space *(*f_mapping)(void);
309 ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
310 char *, loff_t, size_t);
311 ssize_t (*read_new)(struct file *, struct kobject *, const struct bin_attribute *,
312 char *, loff_t, size_t);
313 ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
314 char *, loff_t, size_t);
315 ssize_t (*write_new)(struct file *, struct kobject *,
316 const struct bin_attribute *, char *, loff_t, size_t);
317 loff_t (*llseek)(struct file *, struct kobject *, const struct bin_attribute *,
318 loff_t, int);
319 int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *attr,
320 struct vm_area_struct *vma);
321 };
322
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 */
333 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
334
335 typedef ssize_t __sysfs_bin_rw_handler_new(struct file *, struct kobject *,
336 const struct bin_attribute *, char *, loff_t, size_t);
337
338 /* macros to create static binary attributes easier */
339 #define __BIN_ATTR(_name, _mode, _read, _write, _size) { \
340 .attr = { .name = __stringify(_name), .mode = _mode }, \
341 .read = _Generic(_read, \
342 __sysfs_bin_rw_handler_new * : NULL, \
343 default : _read \
344 ), \
345 .read_new = _Generic(_read, \
346 __sysfs_bin_rw_handler_new * : _read, \
347 default : NULL \
348 ), \
349 .write = _Generic(_write, \
350 __sysfs_bin_rw_handler_new * : NULL, \
351 default : _write \
352 ), \
353 .write_new = _Generic(_write, \
354 __sysfs_bin_rw_handler_new * : _write, \
355 default : NULL \
356 ), \
357 .size = _size, \
358 }
359
360 #define __BIN_ATTR_RO(_name, _size) \
361 __BIN_ATTR(_name, 0444, _name##_read, NULL, _size)
362
363 #define __BIN_ATTR_WO(_name, _size) \
364 __BIN_ATTR(_name, 0200, NULL, _name##_write, _size)
365
366 #define __BIN_ATTR_RW(_name, _size) \
367 __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
368
369 #define __BIN_ATTR_NULL __ATTR_NULL
370
371 #define BIN_ATTR(_name, _mode, _read, _write, _size) \
372 struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \
373 _write, _size)
374
375 #define BIN_ATTR_RO(_name, _size) \
376 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
377
378 #define BIN_ATTR_WO(_name, _size) \
379 struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
380
381 #define BIN_ATTR_RW(_name, _size) \
382 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
383
384
385 #define __BIN_ATTR_ADMIN_RO(_name, _size) \
386 __BIN_ATTR(_name, 0400, _name##_read, NULL, _size)
387
388 #define __BIN_ATTR_ADMIN_RW(_name, _size) \
389 __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size)
390
391 #define BIN_ATTR_ADMIN_RO(_name, _size) \
392 struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size)
393
394 #define BIN_ATTR_ADMIN_RW(_name, _size) \
395 struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size)
396
397 #define __BIN_ATTR_SIMPLE_RO(_name, _mode) \
398 __BIN_ATTR(_name, _mode, sysfs_bin_attr_simple_read, NULL, 0)
399
400 #define BIN_ATTR_SIMPLE_RO(_name) \
401 struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0444)
402
403 #define BIN_ATTR_SIMPLE_ADMIN_RO(_name) \
404 struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0400)
405
406 struct sysfs_ops {
407 ssize_t (*show)(struct kobject *, struct attribute *, char *);
408 ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
409 };
410
411 #ifdef CONFIG_SYSFS
412
413 int __must_check sysfs_create_dir_ns(struct kobject *kobj, const void *ns);
414 void sysfs_remove_dir(struct kobject *kobj);
415 int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
416 const void *new_ns);
417 int __must_check sysfs_move_dir_ns(struct kobject *kobj,
418 struct kobject *new_parent_kobj,
419 const void *new_ns);
420 int __must_check sysfs_create_mount_point(struct kobject *parent_kobj,
421 const char *name);
422 void sysfs_remove_mount_point(struct kobject *parent_kobj,
423 const char *name);
424
425 int __must_check sysfs_create_file_ns(struct kobject *kobj,
426 const struct attribute *attr,
427 const void *ns);
428 int __must_check sysfs_create_files(struct kobject *kobj,
429 const struct attribute * const *attr);
430 int __must_check sysfs_chmod_file(struct kobject *kobj,
431 const struct attribute *attr, umode_t mode);
432 struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
433 const struct attribute *attr);
434 void sysfs_unbreak_active_protection(struct kernfs_node *kn);
435 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
436 const void *ns);
437 bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
438 void sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attr);
439
440 int __must_check sysfs_create_bin_file(struct kobject *kobj,
441 const struct bin_attribute *attr);
442 void sysfs_remove_bin_file(struct kobject *kobj,
443 const struct bin_attribute *attr);
444
445 int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
446 const char *name);
447 int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
448 struct kobject *target,
449 const char *name);
450 void sysfs_remove_link(struct kobject *kobj, const char *name);
451
452 int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target,
453 const char *old_name, const char *new_name,
454 const void *new_ns);
455
456 void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
457 const char *name);
458
459 int __must_check sysfs_create_group(struct kobject *kobj,
460 const struct attribute_group *grp);
461 int __must_check sysfs_create_groups(struct kobject *kobj,
462 const struct attribute_group **groups);
463 int __must_check sysfs_update_groups(struct kobject *kobj,
464 const struct attribute_group **groups);
465 int sysfs_update_group(struct kobject *kobj,
466 const struct attribute_group *grp);
467 void sysfs_remove_group(struct kobject *kobj,
468 const struct attribute_group *grp);
469 void sysfs_remove_groups(struct kobject *kobj,
470 const struct attribute_group **groups);
471 int sysfs_add_file_to_group(struct kobject *kobj,
472 const struct attribute *attr, const char *group);
473 void sysfs_remove_file_from_group(struct kobject *kobj,
474 const struct attribute *attr, const char *group);
475 int sysfs_merge_group(struct kobject *kobj,
476 const struct attribute_group *grp);
477 void sysfs_unmerge_group(struct kobject *kobj,
478 const struct attribute_group *grp);
479 int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
480 struct kobject *target, const char *link_name);
481 void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
482 const char *link_name);
483 int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
484 struct kobject *target_kobj,
485 const char *target_name,
486 const char *symlink_name);
487
488 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
489
490 int __must_check sysfs_init(void);
491
sysfs_enable_ns(struct kernfs_node * kn)492 static inline void sysfs_enable_ns(struct kernfs_node *kn)
493 {
494 return kernfs_enable_ns(kn);
495 }
496
497 int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid,
498 kgid_t kgid);
499 int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid);
500 int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ,
501 const char *name, kuid_t kuid, kgid_t kgid);
502 int sysfs_groups_change_owner(struct kobject *kobj,
503 const struct attribute_group **groups,
504 kuid_t kuid, kgid_t kgid);
505 int sysfs_group_change_owner(struct kobject *kobj,
506 const struct attribute_group *groups, kuid_t kuid,
507 kgid_t kgid);
508 __printf(2, 3)
509 int sysfs_emit(char *buf, const char *fmt, ...);
510 __printf(3, 4)
511 int sysfs_emit_at(char *buf, int at, const char *fmt, ...);
512
513 ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj,
514 const struct bin_attribute *attr, char *buf,
515 loff_t off, size_t count);
516
517 #else /* CONFIG_SYSFS */
518
sysfs_create_dir_ns(struct kobject * kobj,const void * ns)519 static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
520 {
521 return 0;
522 }
523
sysfs_remove_dir(struct kobject * kobj)524 static inline void sysfs_remove_dir(struct kobject *kobj)
525 {
526 }
527
sysfs_rename_dir_ns(struct kobject * kobj,const char * new_name,const void * new_ns)528 static inline int sysfs_rename_dir_ns(struct kobject *kobj,
529 const char *new_name, const void *new_ns)
530 {
531 return 0;
532 }
533
sysfs_move_dir_ns(struct kobject * kobj,struct kobject * new_parent_kobj,const void * new_ns)534 static inline int sysfs_move_dir_ns(struct kobject *kobj,
535 struct kobject *new_parent_kobj,
536 const void *new_ns)
537 {
538 return 0;
539 }
540
sysfs_create_mount_point(struct kobject * parent_kobj,const char * name)541 static inline int sysfs_create_mount_point(struct kobject *parent_kobj,
542 const char *name)
543 {
544 return 0;
545 }
546
sysfs_remove_mount_point(struct kobject * parent_kobj,const char * name)547 static inline void sysfs_remove_mount_point(struct kobject *parent_kobj,
548 const char *name)
549 {
550 }
551
sysfs_create_file_ns(struct kobject * kobj,const struct attribute * attr,const void * ns)552 static inline int sysfs_create_file_ns(struct kobject *kobj,
553 const struct attribute *attr,
554 const void *ns)
555 {
556 return 0;
557 }
558
sysfs_create_files(struct kobject * kobj,const struct attribute * const * attr)559 static inline int sysfs_create_files(struct kobject *kobj,
560 const struct attribute * const *attr)
561 {
562 return 0;
563 }
564
sysfs_chmod_file(struct kobject * kobj,const struct attribute * attr,umode_t mode)565 static inline int sysfs_chmod_file(struct kobject *kobj,
566 const struct attribute *attr, umode_t mode)
567 {
568 return 0;
569 }
570
571 static inline struct kernfs_node *
sysfs_break_active_protection(struct kobject * kobj,const struct attribute * attr)572 sysfs_break_active_protection(struct kobject *kobj,
573 const struct attribute *attr)
574 {
575 return NULL;
576 }
577
sysfs_unbreak_active_protection(struct kernfs_node * kn)578 static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
579 {
580 }
581
sysfs_remove_file_ns(struct kobject * kobj,const struct attribute * attr,const void * ns)582 static inline void sysfs_remove_file_ns(struct kobject *kobj,
583 const struct attribute *attr,
584 const void *ns)
585 {
586 }
587
sysfs_remove_file_self(struct kobject * kobj,const struct attribute * attr)588 static inline bool sysfs_remove_file_self(struct kobject *kobj,
589 const struct attribute *attr)
590 {
591 return false;
592 }
593
sysfs_remove_files(struct kobject * kobj,const struct attribute * const * attr)594 static inline void sysfs_remove_files(struct kobject *kobj,
595 const struct attribute * const *attr)
596 {
597 }
598
sysfs_create_bin_file(struct kobject * kobj,const struct bin_attribute * attr)599 static inline int sysfs_create_bin_file(struct kobject *kobj,
600 const struct bin_attribute *attr)
601 {
602 return 0;
603 }
604
sysfs_remove_bin_file(struct kobject * kobj,const struct bin_attribute * attr)605 static inline void sysfs_remove_bin_file(struct kobject *kobj,
606 const struct bin_attribute *attr)
607 {
608 }
609
sysfs_create_link(struct kobject * kobj,struct kobject * target,const char * name)610 static inline int sysfs_create_link(struct kobject *kobj,
611 struct kobject *target, const char *name)
612 {
613 return 0;
614 }
615
sysfs_create_link_nowarn(struct kobject * kobj,struct kobject * target,const char * name)616 static inline int sysfs_create_link_nowarn(struct kobject *kobj,
617 struct kobject *target,
618 const char *name)
619 {
620 return 0;
621 }
622
sysfs_remove_link(struct kobject * kobj,const char * name)623 static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
624 {
625 }
626
sysfs_rename_link_ns(struct kobject * k,struct kobject * t,const char * old_name,const char * new_name,const void * ns)627 static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t,
628 const char *old_name,
629 const char *new_name, const void *ns)
630 {
631 return 0;
632 }
633
sysfs_delete_link(struct kobject * k,struct kobject * t,const char * name)634 static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
635 const char *name)
636 {
637 }
638
sysfs_create_group(struct kobject * kobj,const struct attribute_group * grp)639 static inline int sysfs_create_group(struct kobject *kobj,
640 const struct attribute_group *grp)
641 {
642 return 0;
643 }
644
sysfs_create_groups(struct kobject * kobj,const struct attribute_group ** groups)645 static inline int sysfs_create_groups(struct kobject *kobj,
646 const struct attribute_group **groups)
647 {
648 return 0;
649 }
650
sysfs_update_groups(struct kobject * kobj,const struct attribute_group ** groups)651 static inline int sysfs_update_groups(struct kobject *kobj,
652 const struct attribute_group **groups)
653 {
654 return 0;
655 }
656
sysfs_update_group(struct kobject * kobj,const struct attribute_group * grp)657 static inline int sysfs_update_group(struct kobject *kobj,
658 const struct attribute_group *grp)
659 {
660 return 0;
661 }
662
sysfs_remove_group(struct kobject * kobj,const struct attribute_group * grp)663 static inline void sysfs_remove_group(struct kobject *kobj,
664 const struct attribute_group *grp)
665 {
666 }
667
sysfs_remove_groups(struct kobject * kobj,const struct attribute_group ** groups)668 static inline void sysfs_remove_groups(struct kobject *kobj,
669 const struct attribute_group **groups)
670 {
671 }
672
sysfs_add_file_to_group(struct kobject * kobj,const struct attribute * attr,const char * group)673 static inline int sysfs_add_file_to_group(struct kobject *kobj,
674 const struct attribute *attr, const char *group)
675 {
676 return 0;
677 }
678
sysfs_remove_file_from_group(struct kobject * kobj,const struct attribute * attr,const char * group)679 static inline void sysfs_remove_file_from_group(struct kobject *kobj,
680 const struct attribute *attr, const char *group)
681 {
682 }
683
sysfs_merge_group(struct kobject * kobj,const struct attribute_group * grp)684 static inline int sysfs_merge_group(struct kobject *kobj,
685 const struct attribute_group *grp)
686 {
687 return 0;
688 }
689
sysfs_unmerge_group(struct kobject * kobj,const struct attribute_group * grp)690 static inline void sysfs_unmerge_group(struct kobject *kobj,
691 const struct attribute_group *grp)
692 {
693 }
694
sysfs_add_link_to_group(struct kobject * kobj,const char * group_name,struct kobject * target,const char * link_name)695 static inline int sysfs_add_link_to_group(struct kobject *kobj,
696 const char *group_name, struct kobject *target,
697 const char *link_name)
698 {
699 return 0;
700 }
701
sysfs_remove_link_from_group(struct kobject * kobj,const char * group_name,const char * link_name)702 static inline void sysfs_remove_link_from_group(struct kobject *kobj,
703 const char *group_name, const char *link_name)
704 {
705 }
706
compat_only_sysfs_link_entry_to_kobj(struct kobject * kobj,struct kobject * target_kobj,const char * target_name,const char * symlink_name)707 static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
708 struct kobject *target_kobj,
709 const char *target_name,
710 const char *symlink_name)
711 {
712 return 0;
713 }
714
sysfs_notify(struct kobject * kobj,const char * dir,const char * attr)715 static inline void sysfs_notify(struct kobject *kobj, const char *dir,
716 const char *attr)
717 {
718 }
719
sysfs_init(void)720 static inline int __must_check sysfs_init(void)
721 {
722 return 0;
723 }
724
sysfs_enable_ns(struct kernfs_node * kn)725 static inline void sysfs_enable_ns(struct kernfs_node *kn)
726 {
727 }
728
sysfs_file_change_owner(struct kobject * kobj,const char * name,kuid_t kuid,kgid_t kgid)729 static inline int sysfs_file_change_owner(struct kobject *kobj,
730 const char *name, kuid_t kuid,
731 kgid_t kgid)
732 {
733 return 0;
734 }
735
sysfs_link_change_owner(struct kobject * kobj,struct kobject * targ,const char * name,kuid_t kuid,kgid_t kgid)736 static inline int sysfs_link_change_owner(struct kobject *kobj,
737 struct kobject *targ,
738 const char *name, kuid_t kuid,
739 kgid_t kgid)
740 {
741 return 0;
742 }
743
sysfs_change_owner(struct kobject * kobj,kuid_t kuid,kgid_t kgid)744 static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid)
745 {
746 return 0;
747 }
748
sysfs_groups_change_owner(struct kobject * kobj,const struct attribute_group ** groups,kuid_t kuid,kgid_t kgid)749 static inline int sysfs_groups_change_owner(struct kobject *kobj,
750 const struct attribute_group **groups,
751 kuid_t kuid, kgid_t kgid)
752 {
753 return 0;
754 }
755
sysfs_group_change_owner(struct kobject * kobj,const struct attribute_group * groups,kuid_t kuid,kgid_t kgid)756 static inline int sysfs_group_change_owner(struct kobject *kobj,
757 const struct attribute_group *groups,
758 kuid_t kuid, kgid_t kgid)
759 {
760 return 0;
761 }
762
763 __printf(2, 3)
sysfs_emit(char * buf,const char * fmt,...)764 static inline int sysfs_emit(char *buf, const char *fmt, ...)
765 {
766 return 0;
767 }
768
769 __printf(3, 4)
sysfs_emit_at(char * buf,int at,const char * fmt,...)770 static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
771 {
772 return 0;
773 }
774
sysfs_bin_attr_simple_read(struct file * file,struct kobject * kobj,const struct bin_attribute * attr,char * buf,loff_t off,size_t count)775 static inline ssize_t sysfs_bin_attr_simple_read(struct file *file,
776 struct kobject *kobj,
777 const struct bin_attribute *attr,
778 char *buf, loff_t off,
779 size_t count)
780 {
781 return 0;
782 }
783 #endif /* CONFIG_SYSFS */
784
sysfs_create_file(struct kobject * kobj,const struct attribute * attr)785 static inline int __must_check sysfs_create_file(struct kobject *kobj,
786 const struct attribute *attr)
787 {
788 return sysfs_create_file_ns(kobj, attr, NULL);
789 }
790
sysfs_remove_file(struct kobject * kobj,const struct attribute * attr)791 static inline void sysfs_remove_file(struct kobject *kobj,
792 const struct attribute *attr)
793 {
794 sysfs_remove_file_ns(kobj, attr, NULL);
795 }
796
sysfs_rename_link(struct kobject * kobj,struct kobject * target,const char * old_name,const char * new_name)797 static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
798 const char *old_name, const char *new_name)
799 {
800 return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
801 }
802
sysfs_notify_dirent(struct kernfs_node * kn)803 static inline void sysfs_notify_dirent(struct kernfs_node *kn)
804 {
805 kernfs_notify(kn);
806 }
807
sysfs_get_dirent(struct kernfs_node * parent,const char * name)808 static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent,
809 const char *name)
810 {
811 return kernfs_find_and_get(parent, name);
812 }
813
sysfs_get(struct kernfs_node * kn)814 static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn)
815 {
816 kernfs_get(kn);
817 return kn;
818 }
819
sysfs_put(struct kernfs_node * kn)820 static inline void sysfs_put(struct kernfs_node *kn)
821 {
822 kernfs_put(kn);
823 }
824
825 #endif /* _SYSFS_H_ */
826