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