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 <teheo@suse.de>
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
25struct kobject;
26struct module;
27struct bin_attribute;
28enum kobj_ns_type;
29
30struct 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) \
52do { \
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 */
99struct 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 const struct bin_attribute *const *bin_attrs;
110};
111
112#define SYSFS_PREALLOC 010000
113#define SYSFS_GROUP_INVISIBLE 020000
114
115/*
116 * DEFINE_SYSFS_GROUP_VISIBLE(name):
117 * A helper macro to pair with the assignment of ".is_visible =
118 * SYSFS_GROUP_VISIBLE(name)", that arranges for the directory
119 * associated with a named attribute_group to optionally be hidden.
120 * This allows for static declaration of attribute_groups, and the
121 * simplification of attribute visibility lifetime that implies,
122 * without polluting sysfs with empty attribute directories.
123 * Ex.
124 *
125 * static umode_t example_attr_visible(struct kobject *kobj,
126 * struct attribute *attr, int n)
127 * {
128 * if (example_attr_condition)
129 * return 0;
130 * else if (ro_attr_condition)
131 * return 0444;
132 * return a->mode;
133 * }
134 *
135 * static bool example_group_visible(struct kobject *kobj)
136 * {
137 * if (example_group_condition)
138 * return false;
139 * return true;
140 * }
141 *
142 * DEFINE_SYSFS_GROUP_VISIBLE(example);
143 *
144 * static struct attribute_group example_group = {
145 * .name = "example",
146 * .is_visible = SYSFS_GROUP_VISIBLE(example),
147 * .attrs = &example_attrs,
148 * };
149 *
150 * Note that it expects <name>_attr_visible and <name>_group_visible to
151 * be defined. For cases where individual attributes do not need
152 * separate visibility consideration, only entire group visibility at
153 * once, see DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE().
154 */
155#define DEFINE_SYSFS_GROUP_VISIBLE(name) \
156 static inline umode_t sysfs_group_visible_##name( \
157 struct kobject *kobj, struct attribute *attr, int n) \
158 { \
159 if (n == 0 && !name##_group_visible(kobj)) \
160 return SYSFS_GROUP_INVISIBLE; \
161 return name##_attr_visible(kobj, attr, n); \
162 }
163
164/*
165 * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name):
166 * A helper macro to pair with SYSFS_GROUP_VISIBLE() that like
167 * DEFINE_SYSFS_GROUP_VISIBLE() controls group visibility, but does
168 * not require the implementation of a per-attribute visibility
169 * callback.
170 * Ex.
171 *
172 * static bool example_group_visible(struct kobject *kobj)
173 * {
174 * if (example_group_condition)
175 * return false;
176 * return true;
177 * }
178 *
179 * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(example);
180 *
181 * static struct attribute_group example_group = {
182 * .name = "example",
183 * .is_visible = SYSFS_GROUP_VISIBLE(example),
184 * .attrs = &example_attrs,
185 * };
186 */
187#define DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name) \
188 static inline umode_t sysfs_group_visible_##name( \
189 struct kobject *kobj, struct attribute *a, int n) \
190 { \
191 if (n == 0 && !name##_group_visible(kobj)) \
192 return SYSFS_GROUP_INVISIBLE; \
193 return a->mode; \
194 }
195
196/*
197 * Same as DEFINE_SYSFS_GROUP_VISIBLE, but for groups with only binary
198 * attributes. If an attribute_group defines both text and binary
199 * attributes, the group visibility is determined by the function
200 * specified to is_visible() not is_bin_visible()
201 */
202#define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) \
203 static inline umode_t sysfs_group_visible_##name( \
204 struct kobject *kobj, const struct bin_attribute *attr, int n) \
205 { \
206 if (n == 0 && !name##_group_visible(kobj)) \
207 return SYSFS_GROUP_INVISIBLE; \
208 return name##_attr_visible(kobj, attr, n); \
209 }
210
211#define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) \
212 static inline umode_t sysfs_group_visible_##name( \
213 struct kobject *kobj, const struct bin_attribute *a, int n) \
214 { \
215 if (n == 0 && !name##_group_visible(kobj)) \
216 return SYSFS_GROUP_INVISIBLE; \
217 return a->mode; \
218 }
219
220#define SYSFS_GROUP_VISIBLE(fn) sysfs_group_visible_##fn
221
222/*
223 * Use these macros to make defining attributes easier.
224 * See include/linux/device.h for examples..
225 */
226
227#define __ATTR(_name, _mode, _show, _store) { \
228 .attr = {.name = __stringify(_name), \
229 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
230 .show = _show, \
231 .store = _store, \
232}
233
234#define __ATTR_PREALLOC(_name, _mode, _show, _store) { \
235 .attr = {.name = __stringify(_name), \
236 .mode = SYSFS_PREALLOC | VERIFY_OCTAL_PERMISSIONS(_mode) },\
237 .show = _show, \
238 .store = _store, \
239}
240
241#define __ATTR_RO(_name) { \
242 .attr = { .name = __stringify(_name), .mode = 0444 }, \
243 .show = _name##_show, \
244}
245
246#define __ATTR_RO_MODE(_name, _mode) { \
247 .attr = { .name = __stringify(_name), \
248 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
249 .show = _name##_show, \
250}
251
252#define __ATTR_RW_MODE(_name, _mode) { \
253 .attr = { .name = __stringify(_name), \
254 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
255 .show = _name##_show, \
256 .store = _name##_store, \
257}
258
259#define __ATTR_WO(_name) { \
260 .attr = { .name = __stringify(_name), .mode = 0200 }, \
261 .store = _name##_store, \
262}
263
264#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)
265
266#define __ATTR_NULL { .attr = { .name = NULL } }
267
268#ifdef CONFIG_DEBUG_LOCK_ALLOC
269#define __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) { \
270 .attr = {.name = __stringify(_name), .mode = _mode, \
271 .ignore_lockdep = true }, \
272 .show = _show, \
273 .store = _store, \
274}
275#else
276#define __ATTR_IGNORE_LOCKDEP __ATTR
277#endif
278
279#define __ATTRIBUTE_GROUPS(_name) \
280static const struct attribute_group *_name##_groups[] = { \
281 &_name##_group, \
282 NULL, \
283}
284
285#define ATTRIBUTE_GROUPS(_name) \
286static const struct attribute_group _name##_group = { \
287 .attrs = _name##_attrs, \
288}; \
289__ATTRIBUTE_GROUPS(_name)
290
291#define BIN_ATTRIBUTE_GROUPS(_name) \
292static const struct attribute_group _name##_group = { \
293 .bin_attrs = _name##_attrs, \
294}; \
295__ATTRIBUTE_GROUPS(_name)
296
297struct file;
298struct vm_area_struct;
299struct address_space;
300
301struct bin_attribute {
302 struct attribute attr;
303 size_t size;
304 void *private;
305 struct address_space *(*f_mapping)(void);
306 ssize_t (*read)(struct file *, struct kobject *, const struct bin_attribute *,
307 char *, loff_t, size_t);
308 ssize_t (*write)(struct file *, struct kobject *, const struct bin_attribute *,
309 char *, loff_t, size_t);
310 loff_t (*llseek)(struct file *, struct kobject *, const struct bin_attribute *,
311 loff_t, int);
312 int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *attr,
313 struct vm_area_struct *vma);
314};
315
316/**
317 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
318 * @attr: struct bin_attribute to initialize
319 *
320 * Initialize a dynamically allocated struct bin_attribute so we
321 * can make lockdep happy. This is a new requirement for
322 * attributes and initially this is only needed when lockdep is
323 * enabled. Lockdep gives a nice error when your attribute is
324 * added to sysfs if you don't have this.
325 */
326#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
327
328/* macros to create static binary attributes easier */
329#define __BIN_ATTR(_name, _mode, _read, _write, _size) { \
330 .attr = { .name = __stringify(_name), .mode = _mode }, \
331 .read = _read, \
332 .write = _write, \
333 .size = _size, \
334}
335
336#define __BIN_ATTR_RO(_name, _size) \
337 __BIN_ATTR(_name, 0444, _name##_read, NULL, _size)
338
339#define __BIN_ATTR_WO(_name, _size) \
340 __BIN_ATTR(_name, 0200, NULL, _name##_write, _size)
341
342#define __BIN_ATTR_RW(_name, _size) \
343 __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
344
345#define __BIN_ATTR_NULL __ATTR_NULL
346
347#define BIN_ATTR(_name, _mode, _read, _write, _size) \
348struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \
349 _write, _size)
350
351#define BIN_ATTR_RO(_name, _size) \
352struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
353
354#define BIN_ATTR_WO(_name, _size) \
355struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
356
357#define BIN_ATTR_RW(_name, _size) \
358struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
359
360
361#define __BIN_ATTR_ADMIN_RO(_name, _size) \
362 __BIN_ATTR(_name, 0400, _name##_read, NULL, _size)
363
364#define __BIN_ATTR_ADMIN_RW(_name, _size) \
365 __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size)
366
367#define BIN_ATTR_ADMIN_RO(_name, _size) \
368struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size)
369
370#define BIN_ATTR_ADMIN_RW(_name, _size) \
371struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size)
372
373#define __BIN_ATTR_SIMPLE_RO(_name, _mode) \
374 __BIN_ATTR(_name, _mode, sysfs_bin_attr_simple_read, NULL, 0)
375
376#define BIN_ATTR_SIMPLE_RO(_name) \
377struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0444)
378
379#define BIN_ATTR_SIMPLE_ADMIN_RO(_name) \
380struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0400)
381
382struct sysfs_ops {
383 ssize_t (*show)(struct kobject *, struct attribute *, char *);
384 ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
385};
386
387#ifdef CONFIG_SYSFS
388
389int __must_check sysfs_create_dir_ns(struct kobject *kobj, const void *ns);
390void sysfs_remove_dir(struct kobject *kobj);
391int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
392 const void *new_ns);
393int __must_check sysfs_move_dir_ns(struct kobject *kobj,
394 struct kobject *new_parent_kobj,
395 const void *new_ns);
396int __must_check sysfs_create_mount_point(struct kobject *parent_kobj,
397 const char *name);
398void sysfs_remove_mount_point(struct kobject *parent_kobj,
399 const char *name);
400
401int __must_check sysfs_create_file_ns(struct kobject *kobj,
402 const struct attribute *attr,
403 const void *ns);
404int __must_check sysfs_create_files(struct kobject *kobj,
405 const struct attribute * const *attr);
406int __must_check sysfs_chmod_file(struct kobject *kobj,
407 const struct attribute *attr, umode_t mode);
408struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
409 const struct attribute *attr);
410void sysfs_unbreak_active_protection(struct kernfs_node *kn);
411void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
412 const void *ns);
413bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
414void sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attr);
415
416int __must_check sysfs_create_bin_file(struct kobject *kobj,
417 const struct bin_attribute *attr);
418void sysfs_remove_bin_file(struct kobject *kobj,
419 const struct bin_attribute *attr);
420
421int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
422 const char *name);
423int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
424 struct kobject *target,
425 const char *name);
426void sysfs_remove_link(struct kobject *kobj, const char *name);
427
428int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target,
429 const char *old_name, const char *new_name,
430 const void *new_ns);
431
432void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
433 const char *name);
434
435int __must_check sysfs_create_group(struct kobject *kobj,
436 const struct attribute_group *grp);
437int __must_check sysfs_create_groups(struct kobject *kobj,
438 const struct attribute_group **groups);
439int __must_check sysfs_update_groups(struct kobject *kobj,
440 const struct attribute_group **groups);
441int sysfs_update_group(struct kobject *kobj,
442 const struct attribute_group *grp);
443void sysfs_remove_group(struct kobject *kobj,
444 const struct attribute_group *grp);
445void sysfs_remove_groups(struct kobject *kobj,
446 const struct attribute_group **groups);
447int sysfs_add_file_to_group(struct kobject *kobj,
448 const struct attribute *attr, const char *group);
449void sysfs_remove_file_from_group(struct kobject *kobj,
450 const struct attribute *attr, const char *group);
451int sysfs_merge_group(struct kobject *kobj,
452 const struct attribute_group *grp);
453void sysfs_unmerge_group(struct kobject *kobj,
454 const struct attribute_group *grp);
455int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
456 struct kobject *target, const char *link_name);
457void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
458 const char *link_name);
459int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
460 struct kobject *target_kobj,
461 const char *target_name,
462 const char *symlink_name);
463
464void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
465
466int __must_check sysfs_init(void);
467
468static inline void sysfs_enable_ns(struct kernfs_node *kn)
469{
470 return kernfs_enable_ns(kn);
471}
472
473int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid,
474 kgid_t kgid);
475int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid);
476int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ,
477 const char *name, kuid_t kuid, kgid_t kgid);
478int sysfs_groups_change_owner(struct kobject *kobj,
479 const struct attribute_group **groups,
480 kuid_t kuid, kgid_t kgid);
481int sysfs_group_change_owner(struct kobject *kobj,
482 const struct attribute_group *groups, kuid_t kuid,
483 kgid_t kgid);
484__printf(2, 3)
485int sysfs_emit(char *buf, const char *fmt, ...);
486__printf(3, 4)
487int sysfs_emit_at(char *buf, int at, const char *fmt, ...);
488
489ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj,
490 const struct bin_attribute *attr, char *buf,
491 loff_t off, size_t count);
492
493#else /* CONFIG_SYSFS */
494
495static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
496{
497 return 0;
498}
499
500static inline void sysfs_remove_dir(struct kobject *kobj)
501{
502}
503
504static inline int sysfs_rename_dir_ns(struct kobject *kobj,
505 const char *new_name, const void *new_ns)
506{
507 return 0;
508}
509
510static inline int sysfs_move_dir_ns(struct kobject *kobj,
511 struct kobject *new_parent_kobj,
512 const void *new_ns)
513{
514 return 0;
515}
516
517static inline int sysfs_create_mount_point(struct kobject *parent_kobj,
518 const char *name)
519{
520 return 0;
521}
522
523static inline void sysfs_remove_mount_point(struct kobject *parent_kobj,
524 const char *name)
525{
526}
527
528static inline int sysfs_create_file_ns(struct kobject *kobj,
529 const struct attribute *attr,
530 const void *ns)
531{
532 return 0;
533}
534
535static inline int sysfs_create_files(struct kobject *kobj,
536 const struct attribute * const *attr)
537{
538 return 0;
539}
540
541static inline int sysfs_chmod_file(struct kobject *kobj,
542 const struct attribute *attr, umode_t mode)
543{
544 return 0;
545}
546
547static inline struct kernfs_node *
548sysfs_break_active_protection(struct kobject *kobj,
549 const struct attribute *attr)
550{
551 return NULL;
552}
553
554static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
555{
556}
557
558static inline void sysfs_remove_file_ns(struct kobject *kobj,
559 const struct attribute *attr,
560 const void *ns)
561{
562}
563
564static inline bool sysfs_remove_file_self(struct kobject *kobj,
565 const struct attribute *attr)
566{
567 return false;
568}
569
570static inline void sysfs_remove_files(struct kobject *kobj,
571 const struct attribute * const *attr)
572{
573}
574
575static inline int sysfs_create_bin_file(struct kobject *kobj,
576 const struct bin_attribute *attr)
577{
578 return 0;
579}
580
581static inline void sysfs_remove_bin_file(struct kobject *kobj,
582 const struct bin_attribute *attr)
583{
584}
585
586static inline int sysfs_create_link(struct kobject *kobj,
587 struct kobject *target, const char *name)
588{
589 return 0;
590}
591
592static inline int sysfs_create_link_nowarn(struct kobject *kobj,
593 struct kobject *target,
594 const char *name)
595{
596 return 0;
597}
598
599static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
600{
601}
602
603static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t,
604 const char *old_name,
605 const char *new_name, const void *ns)
606{
607 return 0;
608}
609
610static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
611 const char *name)
612{
613}
614
615static inline int sysfs_create_group(struct kobject *kobj,
616 const struct attribute_group *grp)
617{
618 return 0;
619}
620
621static inline int sysfs_create_groups(struct kobject *kobj,
622 const struct attribute_group **groups)
623{
624 return 0;
625}
626
627static inline int sysfs_update_groups(struct kobject *kobj,
628 const struct attribute_group **groups)
629{
630 return 0;
631}
632
633static inline int sysfs_update_group(struct kobject *kobj,
634 const struct attribute_group *grp)
635{
636 return 0;
637}
638
639static inline void sysfs_remove_group(struct kobject *kobj,
640 const struct attribute_group *grp)
641{
642}
643
644static inline void sysfs_remove_groups(struct kobject *kobj,
645 const struct attribute_group **groups)
646{
647}
648
649static inline int sysfs_add_file_to_group(struct kobject *kobj,
650 const struct attribute *attr, const char *group)
651{
652 return 0;
653}
654
655static inline void sysfs_remove_file_from_group(struct kobject *kobj,
656 const struct attribute *attr, const char *group)
657{
658}
659
660static inline int sysfs_merge_group(struct kobject *kobj,
661 const struct attribute_group *grp)
662{
663 return 0;
664}
665
666static inline void sysfs_unmerge_group(struct kobject *kobj,
667 const struct attribute_group *grp)
668{
669}
670
671static inline int sysfs_add_link_to_group(struct kobject *kobj,
672 const char *group_name, struct kobject *target,
673 const char *link_name)
674{
675 return 0;
676}
677
678static inline void sysfs_remove_link_from_group(struct kobject *kobj,
679 const char *group_name, const char *link_name)
680{
681}
682
683static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
684 struct kobject *target_kobj,
685 const char *target_name,
686 const char *symlink_name)
687{
688 return 0;
689}
690
691static inline void sysfs_notify(struct kobject *kobj, const char *dir,
692 const char *attr)
693{
694}
695
696static inline int __must_check sysfs_init(void)
697{
698 return 0;
699}
700
701static inline void sysfs_enable_ns(struct kernfs_node *kn)
702{
703}
704
705static inline int sysfs_file_change_owner(struct kobject *kobj,
706 const char *name, kuid_t kuid,
707 kgid_t kgid)
708{
709 return 0;
710}
711
712static inline int sysfs_link_change_owner(struct kobject *kobj,
713 struct kobject *targ,
714 const char *name, kuid_t kuid,
715 kgid_t kgid)
716{
717 return 0;
718}
719
720static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid)
721{
722 return 0;
723}
724
725static inline int sysfs_groups_change_owner(struct kobject *kobj,
726 const struct attribute_group **groups,
727 kuid_t kuid, kgid_t kgid)
728{
729 return 0;
730}
731
732static inline int sysfs_group_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__printf(2, 3)
740static inline int sysfs_emit(char *buf, const char *fmt, ...)
741{
742 return 0;
743}
744
745__printf(3, 4)
746static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
747{
748 return 0;
749}
750
751static inline ssize_t sysfs_bin_attr_simple_read(struct file *file,
752 struct kobject *kobj,
753 const struct bin_attribute *attr,
754 char *buf, loff_t off,
755 size_t count)
756{
757 return 0;
758}
759#endif /* CONFIG_SYSFS */
760
761static inline int __must_check sysfs_create_file(struct kobject *kobj,
762 const struct attribute *attr)
763{
764 return sysfs_create_file_ns(kobj, attr, NULL);
765}
766
767static inline void sysfs_remove_file(struct kobject *kobj,
768 const struct attribute *attr)
769{
770 sysfs_remove_file_ns(kobj, attr, NULL);
771}
772
773static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
774 const char *old_name, const char *new_name)
775{
776 return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
777}
778
779static inline void sysfs_notify_dirent(struct kernfs_node *kn)
780{
781 kernfs_notify(kn);
782}
783
784static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent,
785 const char *name)
786{
787 return kernfs_find_and_get(kn: parent, name);
788}
789
790static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn)
791{
792 kernfs_get(kn);
793 return kn;
794}
795
796static inline void sysfs_put(struct kernfs_node *kn)
797{
798 kernfs_put(kn);
799}
800
801#endif /* _SYSFS_H_ */
802