xref: /linux-6.15/include/linux/sysfs.h (revision eb2e6c3a)
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 	struct bin_attribute	**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)				\
280 static const struct attribute_group *_name##_groups[] = {	\
281 	&_name##_group,						\
282 	NULL,							\
283 }
284 
285 #define ATTRIBUTE_GROUPS(_name)					\
286 static const struct attribute_group _name##_group = {		\
287 	.attrs = _name##_attrs,					\
288 };								\
289 __ATTRIBUTE_GROUPS(_name)
290 
291 #define BIN_ATTRIBUTE_GROUPS(_name)				\
292 static const struct attribute_group _name##_group = {		\
293 	.bin_attrs = _name##_attrs,				\
294 };								\
295 __ATTRIBUTE_GROUPS(_name)
296 
297 struct file;
298 struct vm_area_struct;
299 struct address_space;
300 
301 struct 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 *, struct bin_attribute *,
307 			char *, loff_t, size_t);
308 	ssize_t (*read_new)(struct file *, struct kobject *, const struct bin_attribute *,
309 			    char *, loff_t, size_t);
310 	ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
311 			 char *, loff_t, size_t);
312 	ssize_t (*write_new)(struct file *, struct kobject *,
313 			     const struct bin_attribute *, char *, loff_t, size_t);
314 	loff_t (*llseek)(struct file *, struct kobject *, const struct bin_attribute *,
315 			 loff_t, int);
316 	int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *attr,
317 		    struct vm_area_struct *vma);
318 };
319 
320 /**
321  *	sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
322  *	@attr: struct bin_attribute to initialize
323  *
324  *	Initialize a dynamically allocated struct bin_attribute so we
325  *	can make lockdep happy.  This is a new requirement for
326  *	attributes and initially this is only needed when lockdep is
327  *	enabled.  Lockdep gives a nice error when your attribute is
328  *	added to sysfs if you don't have this.
329  */
330 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
331 
332 typedef ssize_t __sysfs_bin_rw_handler_new(struct file *, struct kobject *,
333 					   const struct bin_attribute *, char *, loff_t, size_t);
334 
335 /* macros to create static binary attributes easier */
336 #define __BIN_ATTR(_name, _mode, _read, _write, _size) {		\
337 	.attr = { .name = __stringify(_name), .mode = _mode },		\
338 	.read = _Generic(_read,						\
339 		__sysfs_bin_rw_handler_new * : NULL,			\
340 		default : _read						\
341 	),								\
342 	.read_new = _Generic(_read,					\
343 		__sysfs_bin_rw_handler_new * : _read,			\
344 		default : NULL						\
345 	),								\
346 	.write = _Generic(_write,					\
347 		__sysfs_bin_rw_handler_new * : NULL,			\
348 		default : _write					\
349 	),								\
350 	.write_new = _Generic(_write,					\
351 		__sysfs_bin_rw_handler_new * : _write,			\
352 		default : NULL						\
353 	),								\
354 	.size	= _size,						\
355 }
356 
357 #define __BIN_ATTR_RO(_name, _size)					\
358 	__BIN_ATTR(_name, 0444, _name##_read, NULL, _size)
359 
360 #define __BIN_ATTR_WO(_name, _size)					\
361 	__BIN_ATTR(_name, 0200, NULL, _name##_write, _size)
362 
363 #define __BIN_ATTR_RW(_name, _size)					\
364 	__BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
365 
366 #define __BIN_ATTR_NULL __ATTR_NULL
367 
368 #define BIN_ATTR(_name, _mode, _read, _write, _size)			\
369 struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read,	\
370 					_write, _size)
371 
372 #define BIN_ATTR_RO(_name, _size)					\
373 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
374 
375 #define BIN_ATTR_WO(_name, _size)					\
376 struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
377 
378 #define BIN_ATTR_RW(_name, _size)					\
379 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
380 
381 
382 #define __BIN_ATTR_ADMIN_RO(_name, _size)				\
383 	__BIN_ATTR(_name, 0400, _name##_read, NULL, _size)
384 
385 #define __BIN_ATTR_ADMIN_RW(_name, _size)					\
386 	__BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size)
387 
388 #define BIN_ATTR_ADMIN_RO(_name, _size)					\
389 struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size)
390 
391 #define BIN_ATTR_ADMIN_RW(_name, _size)					\
392 struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size)
393 
394 #define __BIN_ATTR_SIMPLE_RO(_name, _mode)				\
395 	__BIN_ATTR(_name, _mode, sysfs_bin_attr_simple_read, NULL, 0)
396 
397 #define BIN_ATTR_SIMPLE_RO(_name)					\
398 struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0444)
399 
400 #define BIN_ATTR_SIMPLE_ADMIN_RO(_name)					\
401 struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0400)
402 
403 struct sysfs_ops {
404 	ssize_t	(*show)(struct kobject *, struct attribute *, char *);
405 	ssize_t	(*store)(struct kobject *, struct attribute *, const char *, size_t);
406 };
407 
408 #ifdef CONFIG_SYSFS
409 
410 int __must_check sysfs_create_dir_ns(struct kobject *kobj, const void *ns);
411 void sysfs_remove_dir(struct kobject *kobj);
412 int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
413 				     const void *new_ns);
414 int __must_check sysfs_move_dir_ns(struct kobject *kobj,
415 				   struct kobject *new_parent_kobj,
416 				   const void *new_ns);
417 int __must_check sysfs_create_mount_point(struct kobject *parent_kobj,
418 					  const char *name);
419 void sysfs_remove_mount_point(struct kobject *parent_kobj,
420 			      const char *name);
421 
422 int __must_check sysfs_create_file_ns(struct kobject *kobj,
423 				      const struct attribute *attr,
424 				      const void *ns);
425 int __must_check sysfs_create_files(struct kobject *kobj,
426 				   const struct attribute * const *attr);
427 int __must_check sysfs_chmod_file(struct kobject *kobj,
428 				  const struct attribute *attr, umode_t mode);
429 struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
430 						  const struct attribute *attr);
431 void sysfs_unbreak_active_protection(struct kernfs_node *kn);
432 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
433 			  const void *ns);
434 bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
435 void sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attr);
436 
437 int __must_check sysfs_create_bin_file(struct kobject *kobj,
438 				       const struct bin_attribute *attr);
439 void sysfs_remove_bin_file(struct kobject *kobj,
440 			   const struct bin_attribute *attr);
441 
442 int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
443 				   const char *name);
444 int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
445 					  struct kobject *target,
446 					  const char *name);
447 void sysfs_remove_link(struct kobject *kobj, const char *name);
448 
449 int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target,
450 			 const char *old_name, const char *new_name,
451 			 const void *new_ns);
452 
453 void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
454 			const char *name);
455 
456 int __must_check sysfs_create_group(struct kobject *kobj,
457 				    const struct attribute_group *grp);
458 int __must_check sysfs_create_groups(struct kobject *kobj,
459 				     const struct attribute_group **groups);
460 int __must_check sysfs_update_groups(struct kobject *kobj,
461 				     const struct attribute_group **groups);
462 int sysfs_update_group(struct kobject *kobj,
463 		       const struct attribute_group *grp);
464 void sysfs_remove_group(struct kobject *kobj,
465 			const struct attribute_group *grp);
466 void sysfs_remove_groups(struct kobject *kobj,
467 			 const struct attribute_group **groups);
468 int sysfs_add_file_to_group(struct kobject *kobj,
469 			const struct attribute *attr, const char *group);
470 void sysfs_remove_file_from_group(struct kobject *kobj,
471 			const struct attribute *attr, const char *group);
472 int sysfs_merge_group(struct kobject *kobj,
473 		       const struct attribute_group *grp);
474 void sysfs_unmerge_group(struct kobject *kobj,
475 		       const struct attribute_group *grp);
476 int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
477 			    struct kobject *target, const char *link_name);
478 void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
479 				  const char *link_name);
480 int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
481 					 struct kobject *target_kobj,
482 					 const char *target_name,
483 					 const char *symlink_name);
484 
485 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
486 
487 int __must_check sysfs_init(void);
488 
489 static inline void sysfs_enable_ns(struct kernfs_node *kn)
490 {
491 	return kernfs_enable_ns(kn);
492 }
493 
494 int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid,
495 			    kgid_t kgid);
496 int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid);
497 int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ,
498 			    const char *name, kuid_t kuid, kgid_t kgid);
499 int sysfs_groups_change_owner(struct kobject *kobj,
500 			      const struct attribute_group **groups,
501 			      kuid_t kuid, kgid_t kgid);
502 int sysfs_group_change_owner(struct kobject *kobj,
503 			     const struct attribute_group *groups, kuid_t kuid,
504 			     kgid_t kgid);
505 __printf(2, 3)
506 int sysfs_emit(char *buf, const char *fmt, ...);
507 __printf(3, 4)
508 int sysfs_emit_at(char *buf, int at, const char *fmt, ...);
509 
510 ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj,
511 				   struct bin_attribute *attr, char *buf,
512 				   loff_t off, size_t count);
513 
514 #else /* CONFIG_SYSFS */
515 
516 static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
517 {
518 	return 0;
519 }
520 
521 static inline void sysfs_remove_dir(struct kobject *kobj)
522 {
523 }
524 
525 static inline int sysfs_rename_dir_ns(struct kobject *kobj,
526 				      const char *new_name, const void *new_ns)
527 {
528 	return 0;
529 }
530 
531 static inline int sysfs_move_dir_ns(struct kobject *kobj,
532 				    struct kobject *new_parent_kobj,
533 				    const void *new_ns)
534 {
535 	return 0;
536 }
537 
538 static inline int sysfs_create_mount_point(struct kobject *parent_kobj,
539 					   const char *name)
540 {
541 	return 0;
542 }
543 
544 static inline void sysfs_remove_mount_point(struct kobject *parent_kobj,
545 					    const char *name)
546 {
547 }
548 
549 static inline int sysfs_create_file_ns(struct kobject *kobj,
550 				       const struct attribute *attr,
551 				       const void *ns)
552 {
553 	return 0;
554 }
555 
556 static inline int sysfs_create_files(struct kobject *kobj,
557 				    const struct attribute * const *attr)
558 {
559 	return 0;
560 }
561 
562 static inline int sysfs_chmod_file(struct kobject *kobj,
563 				   const struct attribute *attr, umode_t mode)
564 {
565 	return 0;
566 }
567 
568 static inline struct kernfs_node *
569 sysfs_break_active_protection(struct kobject *kobj,
570 			      const struct attribute *attr)
571 {
572 	return NULL;
573 }
574 
575 static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
576 {
577 }
578 
579 static inline void sysfs_remove_file_ns(struct kobject *kobj,
580 					const struct attribute *attr,
581 					const void *ns)
582 {
583 }
584 
585 static inline bool sysfs_remove_file_self(struct kobject *kobj,
586 					  const struct attribute *attr)
587 {
588 	return false;
589 }
590 
591 static inline void sysfs_remove_files(struct kobject *kobj,
592 				     const struct attribute * const *attr)
593 {
594 }
595 
596 static inline int sysfs_create_bin_file(struct kobject *kobj,
597 					const struct bin_attribute *attr)
598 {
599 	return 0;
600 }
601 
602 static inline void sysfs_remove_bin_file(struct kobject *kobj,
603 					 const struct bin_attribute *attr)
604 {
605 }
606 
607 static inline int sysfs_create_link(struct kobject *kobj,
608 				    struct kobject *target, const char *name)
609 {
610 	return 0;
611 }
612 
613 static inline int sysfs_create_link_nowarn(struct kobject *kobj,
614 					   struct kobject *target,
615 					   const char *name)
616 {
617 	return 0;
618 }
619 
620 static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
621 {
622 }
623 
624 static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t,
625 				       const char *old_name,
626 				       const char *new_name, const void *ns)
627 {
628 	return 0;
629 }
630 
631 static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
632 				     const char *name)
633 {
634 }
635 
636 static inline int sysfs_create_group(struct kobject *kobj,
637 				     const struct attribute_group *grp)
638 {
639 	return 0;
640 }
641 
642 static inline int sysfs_create_groups(struct kobject *kobj,
643 				      const struct attribute_group **groups)
644 {
645 	return 0;
646 }
647 
648 static inline int sysfs_update_groups(struct kobject *kobj,
649 				      const struct attribute_group **groups)
650 {
651 	return 0;
652 }
653 
654 static inline int sysfs_update_group(struct kobject *kobj,
655 				const struct attribute_group *grp)
656 {
657 	return 0;
658 }
659 
660 static inline void sysfs_remove_group(struct kobject *kobj,
661 				      const struct attribute_group *grp)
662 {
663 }
664 
665 static inline void sysfs_remove_groups(struct kobject *kobj,
666 				       const struct attribute_group **groups)
667 {
668 }
669 
670 static inline int sysfs_add_file_to_group(struct kobject *kobj,
671 		const struct attribute *attr, const char *group)
672 {
673 	return 0;
674 }
675 
676 static inline void sysfs_remove_file_from_group(struct kobject *kobj,
677 		const struct attribute *attr, const char *group)
678 {
679 }
680 
681 static inline int sysfs_merge_group(struct kobject *kobj,
682 		       const struct attribute_group *grp)
683 {
684 	return 0;
685 }
686 
687 static inline void sysfs_unmerge_group(struct kobject *kobj,
688 		       const struct attribute_group *grp)
689 {
690 }
691 
692 static inline int sysfs_add_link_to_group(struct kobject *kobj,
693 		const char *group_name, struct kobject *target,
694 		const char *link_name)
695 {
696 	return 0;
697 }
698 
699 static inline void sysfs_remove_link_from_group(struct kobject *kobj,
700 		const char *group_name, const char *link_name)
701 {
702 }
703 
704 static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
705 						       struct kobject *target_kobj,
706 						       const char *target_name,
707 						       const char *symlink_name)
708 {
709 	return 0;
710 }
711 
712 static inline void sysfs_notify(struct kobject *kobj, const char *dir,
713 				const char *attr)
714 {
715 }
716 
717 static inline int __must_check sysfs_init(void)
718 {
719 	return 0;
720 }
721 
722 static inline void sysfs_enable_ns(struct kernfs_node *kn)
723 {
724 }
725 
726 static inline int sysfs_file_change_owner(struct kobject *kobj,
727 					  const char *name, kuid_t kuid,
728 					  kgid_t kgid)
729 {
730 	return 0;
731 }
732 
733 static inline int sysfs_link_change_owner(struct kobject *kobj,
734 					  struct kobject *targ,
735 					  const char *name, kuid_t kuid,
736 					  kgid_t kgid)
737 {
738 	return 0;
739 }
740 
741 static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid)
742 {
743 	return 0;
744 }
745 
746 static inline int sysfs_groups_change_owner(struct kobject *kobj,
747 			  const struct attribute_group **groups,
748 			  kuid_t kuid, kgid_t kgid)
749 {
750 	return 0;
751 }
752 
753 static inline int sysfs_group_change_owner(struct kobject *kobj,
754 					   const struct attribute_group *groups,
755 					   kuid_t kuid, kgid_t kgid)
756 {
757 	return 0;
758 }
759 
760 __printf(2, 3)
761 static inline int sysfs_emit(char *buf, const char *fmt, ...)
762 {
763 	return 0;
764 }
765 
766 __printf(3, 4)
767 static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
768 {
769 	return 0;
770 }
771 
772 static inline ssize_t sysfs_bin_attr_simple_read(struct file *file,
773 						 struct kobject *kobj,
774 						 struct bin_attribute *attr,
775 						 char *buf, loff_t off,
776 						 size_t count)
777 {
778 	return 0;
779 }
780 #endif /* CONFIG_SYSFS */
781 
782 static inline int __must_check sysfs_create_file(struct kobject *kobj,
783 						 const struct attribute *attr)
784 {
785 	return sysfs_create_file_ns(kobj, attr, NULL);
786 }
787 
788 static inline void sysfs_remove_file(struct kobject *kobj,
789 				     const struct attribute *attr)
790 {
791 	sysfs_remove_file_ns(kobj, attr, NULL);
792 }
793 
794 static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
795 				    const char *old_name, const char *new_name)
796 {
797 	return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
798 }
799 
800 static inline void sysfs_notify_dirent(struct kernfs_node *kn)
801 {
802 	kernfs_notify(kn);
803 }
804 
805 static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent,
806 						   const char *name)
807 {
808 	return kernfs_find_and_get(parent, name);
809 }
810 
811 static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn)
812 {
813 	kernfs_get(kn);
814 	return kn;
815 }
816 
817 static inline void sysfs_put(struct kernfs_node *kn)
818 {
819 	kernfs_put(kn);
820 }
821 
822 #endif /* _SYSFS_H_ */
823