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