1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * sysfs.h - definitions for the device driver filesystem
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (c) 2001,2002 Patrick Mochel
61da177e4SLinus Torvalds * Copyright (c) 2004 Silicon Graphics, Inc.
76d66f5cdSTejun Heo * Copyright (c) 2007 SUSE Linux Products GmbH
86d66f5cdSTejun Heo * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
91da177e4SLinus Torvalds *
100c1bc6b8SMauro Carvalho Chehab * Please see Documentation/filesystems/sysfs.rst for more information.
111da177e4SLinus Torvalds */
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds #ifndef _SYSFS_H_
141da177e4SLinus Torvalds #define _SYSFS_H_
151da177e4SLinus Torvalds
16b8441ed2STejun Heo #include <linux/kernfs.h>
174a7fb636SAndrew Morton #include <linux/compiler.h>
185851fadcSRalf Baechle #include <linux/errno.h>
19bf0acc33SFrank Haverkamp #include <linux/list.h>
206992f533SEric W. Biederman #include <linux/lockdep.h>
218488a38fSDavid Howells #include <linux/kobject_ns.h>
223493f69fSOliver Schinagl #include <linux/stat.h>
2360063497SArun Sharma #include <linux/atomic.h>
241da177e4SLinus Torvalds
251da177e4SLinus Torvalds struct kobject;
261da177e4SLinus Torvalds struct module;
276ab9cea1SGreg Kroah-Hartman struct bin_attribute;
283ff195b0SEric W. Biederman enum kobj_ns_type;
291da177e4SLinus Torvalds
301da177e4SLinus Torvalds struct attribute {
31d48593bfSDmitry Torokhov const char *name;
329104e427SAl Viro umode_t mode;
336992f533SEric W. Biederman #ifdef CONFIG_DEBUG_LOCK_ALLOC
34356c05d5SAlan Stern bool ignore_lockdep:1;
356992f533SEric W. Biederman struct lock_class_key *key;
366992f533SEric W. Biederman struct lock_class_key skey;
376992f533SEric W. Biederman #endif
381da177e4SLinus Torvalds };
391da177e4SLinus Torvalds
4035960258SEric W. Biederman /**
4135960258SEric W. Biederman * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
4235960258SEric W. Biederman * @attr: struct attribute to initialize
4335960258SEric W. Biederman *
4435960258SEric W. Biederman * Initialize a dynamically allocated struct attribute so we can
4535960258SEric W. Biederman * make lockdep happy. This is a new requirement for attributes
4635960258SEric W. Biederman * and initially this is only needed when lockdep is enabled.
4735960258SEric W. Biederman * Lockdep gives a nice error when your attribute is added to
4835960258SEric W. Biederman * sysfs if you don't have this.
4935960258SEric W. Biederman */
506992f533SEric W. Biederman #ifdef CONFIG_DEBUG_LOCK_ALLOC
516992f533SEric W. Biederman #define sysfs_attr_init(attr) \
526992f533SEric W. Biederman do { \
536992f533SEric W. Biederman static struct lock_class_key __key; \
546992f533SEric W. Biederman \
556992f533SEric W. Biederman (attr)->key = &__key; \
566992f533SEric W. Biederman } while (0)
576992f533SEric W. Biederman #else
586992f533SEric W. Biederman #define sysfs_attr_init(attr) do {} while (0)
596992f533SEric W. Biederman #endif
606992f533SEric W. Biederman
61ba61af6fSGuenter Roeck /**
62ba61af6fSGuenter Roeck * struct attribute_group - data structure used to declare an attribute group.
63ba61af6fSGuenter Roeck * @name: Optional: Attribute group name
64ba61af6fSGuenter Roeck * If specified, the attribute group will be created in
65ba61af6fSGuenter Roeck * a new subdirectory with this name.
66ba61af6fSGuenter Roeck * @is_visible: Optional: Function to return permissions associated with an
67ba61af6fSGuenter Roeck * attribute of the group. Will be called repeatedly for each
687f5028cfSEmilio López * non-binary attribute in the group. Only read/write
697f5028cfSEmilio López * permissions as well as SYSFS_PREALLOC are accepted. Must
707f5028cfSEmilio López * return 0 if an attribute is not visible. The returned value
717f5028cfSEmilio López * will replace static permissions defined in struct attribute.
727f5028cfSEmilio López * @is_bin_visible:
737f5028cfSEmilio López * Optional: Function to return permissions associated with a
747f5028cfSEmilio López * binary attribute of the group. Will be called repeatedly
757f5028cfSEmilio López * for each binary attribute in the group. Only read/write
767f5028cfSEmilio López * permissions as well as SYSFS_PREALLOC are accepted. Must
777f5028cfSEmilio López * return 0 if a binary attribute is not visible. The returned
787f5028cfSEmilio López * value will replace static permissions defined in
797f5028cfSEmilio López * struct bin_attribute.
80ba61af6fSGuenter Roeck * @attrs: Pointer to NULL terminated list of attributes.
81ba61af6fSGuenter Roeck * @bin_attrs: Pointer to NULL terminated list of binary attributes.
82ba61af6fSGuenter Roeck * Either attrs or bin_attrs or both must be provided.
83ba61af6fSGuenter Roeck */
841da177e4SLinus Torvalds struct attribute_group {
85d48593bfSDmitry Torokhov const char *name;
86587a1f16SAl Viro umode_t (*is_visible)(struct kobject *,
87d4acd722SJames Bottomley struct attribute *, int);
887f5028cfSEmilio López umode_t (*is_bin_visible)(struct kobject *,
897f5028cfSEmilio López struct bin_attribute *, int);
901da177e4SLinus Torvalds struct attribute **attrs;
916ab9cea1SGreg Kroah-Hartman struct bin_attribute **bin_attrs;
921da177e4SLinus Torvalds };
931da177e4SLinus Torvalds
943ec78790SRandy Dunlap /*
953ec78790SRandy Dunlap * Use these macros to make defining attributes easier.
963ec78790SRandy Dunlap * See include/linux/device.h for examples..
971da177e4SLinus Torvalds */
981da177e4SLinus Torvalds
992b75869bSNeilBrown #define SYSFS_PREALLOC 010000
1002b75869bSNeilBrown
1011da177e4SLinus Torvalds #define __ATTR(_name, _mode, _show, _store) { \
10258f86cc8SRusty Russell .attr = {.name = __stringify(_name), \
10358f86cc8SRusty Russell .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
1041da177e4SLinus Torvalds .show = _show, \
1051da177e4SLinus Torvalds .store = _store, \
1061da177e4SLinus Torvalds }
1071da177e4SLinus Torvalds
1082b75869bSNeilBrown #define __ATTR_PREALLOC(_name, _mode, _show, _store) { \
1092b75869bSNeilBrown .attr = {.name = __stringify(_name), \
1102b75869bSNeilBrown .mode = SYSFS_PREALLOC | VERIFY_OCTAL_PERMISSIONS(_mode) },\
1112b75869bSNeilBrown .show = _show, \
1122b75869bSNeilBrown .store = _store, \
1132b75869bSNeilBrown }
1142b75869bSNeilBrown
1151da177e4SLinus Torvalds #define __ATTR_RO(_name) { \
116353c6ddaSJoe Perches .attr = { .name = __stringify(_name), .mode = 0444 }, \
1171da177e4SLinus Torvalds .show = _name##_show, \
1181da177e4SLinus Torvalds }
1191da177e4SLinus Torvalds
120af97a77bSGreg Kroah-Hartman #define __ATTR_RO_MODE(_name, _mode) { \
121af97a77bSGreg Kroah-Hartman .attr = { .name = __stringify(_name), \
122af97a77bSGreg Kroah-Hartman .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
123af97a77bSGreg Kroah-Hartman .show = _name##_show, \
124af97a77bSGreg Kroah-Hartman }
125af97a77bSGreg Kroah-Hartman
1263022c6a1SDan Williams #define __ATTR_RW_MODE(_name, _mode) { \
1273022c6a1SDan Williams .attr = { .name = __stringify(_name), \
1283022c6a1SDan Williams .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \
1293022c6a1SDan Williams .show = _name##_show, \
1303022c6a1SDan Williams .store = _name##_store, \
1313022c6a1SDan Williams }
1323022c6a1SDan Williams
133a65fcce7SGreg Kroah-Hartman #define __ATTR_WO(_name) { \
134353c6ddaSJoe Perches .attr = { .name = __stringify(_name), .mode = 0200 }, \
135a65fcce7SGreg Kroah-Hartman .store = _name##_store, \
136a65fcce7SGreg Kroah-Hartman }
137a65fcce7SGreg Kroah-Hartman
138353c6ddaSJoe Perches #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)
139b9b32597SGreg Kroah-Hartman
1401da177e4SLinus Torvalds #define __ATTR_NULL { .attr = { .name = NULL } }
1411da177e4SLinus Torvalds
142356c05d5SAlan Stern #ifdef CONFIG_DEBUG_LOCK_ALLOC
143356c05d5SAlan Stern #define __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) { \
144356c05d5SAlan Stern .attr = {.name = __stringify(_name), .mode = _mode, \
145356c05d5SAlan Stern .ignore_lockdep = true }, \
146356c05d5SAlan Stern .show = _show, \
147356c05d5SAlan Stern .store = _store, \
148356c05d5SAlan Stern }
149356c05d5SAlan Stern #else
150356c05d5SAlan Stern #define __ATTR_IGNORE_LOCKDEP __ATTR
151356c05d5SAlan Stern #endif
152356c05d5SAlan Stern
1533493f69fSOliver Schinagl #define __ATTRIBUTE_GROUPS(_name) \
1543493f69fSOliver Schinagl static const struct attribute_group *_name##_groups[] = { \
1553493f69fSOliver Schinagl &_name##_group, \
156f2f37f58SGreg Kroah-Hartman NULL, \
157f2f37f58SGreg Kroah-Hartman }
158f2f37f58SGreg Kroah-Hartman
1593493f69fSOliver Schinagl #define ATTRIBUTE_GROUPS(_name) \
1603493f69fSOliver Schinagl static const struct attribute_group _name##_group = { \
1613493f69fSOliver Schinagl .attrs = _name##_attrs, \
1623493f69fSOliver Schinagl }; \
1633493f69fSOliver Schinagl __ATTRIBUTE_GROUPS(_name)
1643493f69fSOliver Schinagl
16546ad0572SHeiner Kallweit #define BIN_ATTRIBUTE_GROUPS(_name) \
16646ad0572SHeiner Kallweit static const struct attribute_group _name##_group = { \
16746ad0572SHeiner Kallweit .bin_attrs = _name##_attrs, \
16846ad0572SHeiner Kallweit }; \
16946ad0572SHeiner Kallweit __ATTRIBUTE_GROUPS(_name)
17046ad0572SHeiner Kallweit
1712c3c8beaSChris Wright struct file;
1721da177e4SLinus Torvalds struct vm_area_struct;
17374b30195SDaniel Vetter struct address_space;
1741da177e4SLinus Torvalds
1751da177e4SLinus Torvalds struct bin_attribute {
1761da177e4SLinus Torvalds struct attribute attr;
1771da177e4SLinus Torvalds size_t size;
1781da177e4SLinus Torvalds void *private;
179f06aff92SKrzysztof Wilczyński struct address_space *(*f_mapping)(void);
1802c3c8beaSChris Wright ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
18191a69029SZhang Rui char *, loff_t, size_t);
1822c3c8beaSChris Wright ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
18391a69029SZhang Rui char *, loff_t, size_t);
1842c3c8beaSChris Wright int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
1851da177e4SLinus Torvalds struct vm_area_struct *vma);
1861da177e4SLinus Torvalds };
1871da177e4SLinus Torvalds
18835960258SEric W. Biederman /**
18935960258SEric W. Biederman * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
19035960258SEric W. Biederman * @attr: struct bin_attribute to initialize
19135960258SEric W. Biederman *
19235960258SEric W. Biederman * Initialize a dynamically allocated struct bin_attribute so we
19335960258SEric W. Biederman * can make lockdep happy. This is a new requirement for
19435960258SEric W. Biederman * attributes and initially this is only needed when lockdep is
19535960258SEric W. Biederman * enabled. Lockdep gives a nice error when your attribute is
19635960258SEric W. Biederman * added to sysfs if you don't have this.
19735960258SEric W. Biederman */
19862e877b8SStephen Rothwell #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
1996992f533SEric W. Biederman
2003493f69fSOliver Schinagl /* macros to create static binary attributes easier */
2013493f69fSOliver Schinagl #define __BIN_ATTR(_name, _mode, _read, _write, _size) { \
202e4b63603SGreg Kroah-Hartman .attr = { .name = __stringify(_name), .mode = _mode }, \
203e4b63603SGreg Kroah-Hartman .read = _read, \
204e4b63603SGreg Kroah-Hartman .write = _write, \
205e4b63603SGreg Kroah-Hartman .size = _size, \
206e4b63603SGreg Kroah-Hartman }
207e4b63603SGreg Kroah-Hartman
2083493f69fSOliver Schinagl #define __BIN_ATTR_RO(_name, _size) { \
209353c6ddaSJoe Perches .attr = { .name = __stringify(_name), .mode = 0444 }, \
2103493f69fSOliver Schinagl .read = _name##_read, \
2113493f69fSOliver Schinagl .size = _size, \
2123493f69fSOliver Schinagl }
2133493f69fSOliver Schinagl
21482af5b66SNayna Jain #define __BIN_ATTR_WO(_name, _size) { \
2157f905761SGreg Kroah-Hartman .attr = { .name = __stringify(_name), .mode = 0200 }, \
21682af5b66SNayna Jain .write = _name##_write, \
2177f905761SGreg Kroah-Hartman .size = _size, \
2187f905761SGreg Kroah-Hartman }
2197f905761SGreg Kroah-Hartman
220353c6ddaSJoe Perches #define __BIN_ATTR_RW(_name, _size) \
221353c6ddaSJoe Perches __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size)
2223493f69fSOliver Schinagl
2233493f69fSOliver Schinagl #define __BIN_ATTR_NULL __ATTR_NULL
2243493f69fSOliver Schinagl
2253493f69fSOliver Schinagl #define BIN_ATTR(_name, _mode, _read, _write, _size) \
2263493f69fSOliver Schinagl struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \
2273493f69fSOliver Schinagl _write, _size)
2283493f69fSOliver Schinagl
2293493f69fSOliver Schinagl #define BIN_ATTR_RO(_name, _size) \
2303493f69fSOliver Schinagl struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
2313493f69fSOliver Schinagl
2327f905761SGreg Kroah-Hartman #define BIN_ATTR_WO(_name, _size) \
2337f905761SGreg Kroah-Hartman struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size)
2347f905761SGreg Kroah-Hartman
2353493f69fSOliver Schinagl #define BIN_ATTR_RW(_name, _size) \
2363493f69fSOliver Schinagl struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
2373493f69fSOliver Schinagl
238*9d6794feSIra Weiny
239*9d6794feSIra Weiny #define __BIN_ATTR_ADMIN_RO(_name, _size) { \
240*9d6794feSIra Weiny .attr = { .name = __stringify(_name), .mode = 0400 }, \
241*9d6794feSIra Weiny .read = _name##_read, \
242*9d6794feSIra Weiny .size = _size, \
243*9d6794feSIra Weiny }
244*9d6794feSIra Weiny
245*9d6794feSIra Weiny #define __BIN_ATTR_ADMIN_RW(_name, _size) \
246*9d6794feSIra Weiny __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size)
247*9d6794feSIra Weiny
248*9d6794feSIra Weiny #define BIN_ATTR_ADMIN_RO(_name, _size) \
249*9d6794feSIra Weiny struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size)
250*9d6794feSIra Weiny
251*9d6794feSIra Weiny #define BIN_ATTR_ADMIN_RW(_name, _size) \
252*9d6794feSIra Weiny struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size)
253*9d6794feSIra Weiny
2541da177e4SLinus Torvalds struct sysfs_ops {
2551da177e4SLinus Torvalds ssize_t (*show)(struct kobject *, struct attribute *, char *);
2561da177e4SLinus Torvalds ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
2571da177e4SLinus Torvalds };
2581da177e4SLinus Torvalds
2591da177e4SLinus Torvalds #ifdef CONFIG_SYSFS
2601da177e4SLinus Torvalds
261e34ff490STejun Heo int __must_check sysfs_create_dir_ns(struct kobject *kobj, const void *ns);
26259f69015STejun Heo void sysfs_remove_dir(struct kobject *kobj);
263e34ff490STejun Heo int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
264e34ff490STejun Heo const void *new_ns);
265e34ff490STejun Heo int __must_check sysfs_move_dir_ns(struct kobject *kobj,
266e34ff490STejun Heo struct kobject *new_parent_kobj,
267e34ff490STejun Heo const void *new_ns);
26887d2846fSEric W. Biederman int __must_check sysfs_create_mount_point(struct kobject *parent_kobj,
26987d2846fSEric W. Biederman const char *name);
27087d2846fSEric W. Biederman void sysfs_remove_mount_point(struct kobject *parent_kobj,
27187d2846fSEric W. Biederman const char *name);
2721da177e4SLinus Torvalds
27358292cbeSTejun Heo int __must_check sysfs_create_file_ns(struct kobject *kobj,
27458292cbeSTejun Heo const struct attribute *attr,
27558292cbeSTejun Heo const void *ns);
2761c205ae1SAndi Kleen int __must_check sysfs_create_files(struct kobject *kobj,
2779ee4685cSJani Nikula const struct attribute * const *attr);
27849c19400SJean Delvare int __must_check sysfs_chmod_file(struct kobject *kobj,
27948176a97SAl Viro const struct attribute *attr, umode_t mode);
2802afc9166SBart Van Assche struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj,
2812afc9166SBart Van Assche const struct attribute *attr);
2822afc9166SBart Van Assche void sysfs_unbreak_active_protection(struct kernfs_node *kn);
28358292cbeSTejun Heo void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
28458292cbeSTejun Heo const void *ns);
2856b0afc2aSTejun Heo bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
2869ee4685cSJani Nikula void sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attr);
2871da177e4SLinus Torvalds
2884a7fb636SAndrew Morton int __must_check sysfs_create_bin_file(struct kobject *kobj,
28966ecb92bSPhil Carmody const struct bin_attribute *attr);
29066ecb92bSPhil Carmody void sysfs_remove_bin_file(struct kobject *kobj,
29166ecb92bSPhil Carmody const struct bin_attribute *attr);
2921da177e4SLinus Torvalds
29359f69015STejun Heo int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
29459f69015STejun Heo const char *name);
29536ce6dadSCornelia Huck int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
29636ce6dadSCornelia Huck struct kobject *target,
29736ce6dadSCornelia Huck const char *name);
29859f69015STejun Heo void sysfs_remove_link(struct kobject *kobj, const char *name);
29959f69015STejun Heo
3004b30ee58STejun Heo int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target,
3014b30ee58STejun Heo const char *old_name, const char *new_name,
3024b30ee58STejun Heo const void *new_ns);
3037cb32942SEric W. Biederman
304746edb7aSEric W. Biederman void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
305746edb7aSEric W. Biederman const char *name);
306746edb7aSEric W. Biederman
30759f69015STejun Heo int __must_check sysfs_create_group(struct kobject *kobj,
30859f69015STejun Heo const struct attribute_group *grp);
3093e9b2baeSGreg Kroah-Hartman int __must_check sysfs_create_groups(struct kobject *kobj,
3103e9b2baeSGreg Kroah-Hartman const struct attribute_group **groups);
311aac1f7f9SJiri Olsa int __must_check sysfs_update_groups(struct kobject *kobj,
312aac1f7f9SJiri Olsa const struct attribute_group **groups);
3130f423895SJames Bottomley int sysfs_update_group(struct kobject *kobj,
3140f423895SJames Bottomley const struct attribute_group *grp);
31559f69015STejun Heo void sysfs_remove_group(struct kobject *kobj,
31659f69015STejun Heo const struct attribute_group *grp);
3173e9b2baeSGreg Kroah-Hartman void sysfs_remove_groups(struct kobject *kobj,
3183e9b2baeSGreg Kroah-Hartman const struct attribute_group **groups);
319dfa87c82SAlan Stern int sysfs_add_file_to_group(struct kobject *kobj,
320dfa87c82SAlan Stern const struct attribute *attr, const char *group);
321dfa87c82SAlan Stern void sysfs_remove_file_from_group(struct kobject *kobj,
322dfa87c82SAlan Stern const struct attribute *attr, const char *group);
32369d44ffbSAlan Stern int sysfs_merge_group(struct kobject *kobj,
32469d44ffbSAlan Stern const struct attribute_group *grp);
32569d44ffbSAlan Stern void sysfs_unmerge_group(struct kobject *kobj,
32669d44ffbSAlan Stern const struct attribute_group *grp);
3270bb8f3d6SRafael J. Wysocki int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
3280bb8f3d6SRafael J. Wysocki struct kobject *target, const char *link_name);
3290bb8f3d6SRafael J. Wysocki void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
3300bb8f3d6SRafael J. Wysocki const char *link_name);
3319255782fSSourabh Jain int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
3329255782fSSourabh Jain struct kobject *target_kobj,
3339255782fSSourabh Jain const char *target_name,
3349255782fSSourabh Jain const char *symlink_name);
335dfa87c82SAlan Stern
3368c0e3998STrent Piepho void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
3373ff195b0SEric W. Biederman
338f1282c84SNeil Brown int __must_check sysfs_init(void);
339f20a9eadSAndrew Morton
sysfs_enable_ns(struct kernfs_node * kn)340fa4cd451STejun Heo static inline void sysfs_enable_ns(struct kernfs_node *kn)
341fa4cd451STejun Heo {
342fa4cd451STejun Heo return kernfs_enable_ns(kn);
343fa4cd451STejun Heo }
344fa4cd451STejun Heo
345f70ce185SChristian Brauner int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid,
346f70ce185SChristian Brauner kgid_t kgid);
3472c4f9401SChristian Brauner int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid);
3480666a3aeSChristian Brauner int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ,
3490666a3aeSChristian Brauner const char *name, kuid_t kuid, kgid_t kgid);
350303a4276SChristian Brauner int sysfs_groups_change_owner(struct kobject *kobj,
351303a4276SChristian Brauner const struct attribute_group **groups,
352303a4276SChristian Brauner kuid_t kuid, kgid_t kgid);
353303a4276SChristian Brauner int sysfs_group_change_owner(struct kobject *kobj,
354303a4276SChristian Brauner const struct attribute_group *groups, kuid_t kuid,
355303a4276SChristian Brauner kgid_t kgid);
3562efc459dSJoe Perches __printf(2, 3)
3572efc459dSJoe Perches int sysfs_emit(char *buf, const char *fmt, ...);
3582efc459dSJoe Perches __printf(3, 4)
3592efc459dSJoe Perches int sysfs_emit_at(char *buf, int at, const char *fmt, ...);
360f70ce185SChristian Brauner
3611da177e4SLinus Torvalds #else /* CONFIG_SYSFS */
3621da177e4SLinus Torvalds
sysfs_create_dir_ns(struct kobject * kobj,const void * ns)363e34ff490STejun Heo static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
3641da177e4SLinus Torvalds {
3651da177e4SLinus Torvalds return 0;
3661da177e4SLinus Torvalds }
3671da177e4SLinus Torvalds
sysfs_remove_dir(struct kobject * kobj)36859f69015STejun Heo static inline void sysfs_remove_dir(struct kobject *kobj)
3691da177e4SLinus Torvalds {
3701da177e4SLinus Torvalds }
3711da177e4SLinus Torvalds
sysfs_rename_dir_ns(struct kobject * kobj,const char * new_name,const void * new_ns)372e34ff490STejun Heo static inline int sysfs_rename_dir_ns(struct kobject *kobj,
373e34ff490STejun Heo const char *new_name, const void *new_ns)
3741da177e4SLinus Torvalds {
3750b4a4feaSEric W. Biederman return 0;
3761da177e4SLinus Torvalds }
3771da177e4SLinus Torvalds
sysfs_move_dir_ns(struct kobject * kobj,struct kobject * new_parent_kobj,const void * new_ns)378e34ff490STejun Heo static inline int sysfs_move_dir_ns(struct kobject *kobj,
379e34ff490STejun Heo struct kobject *new_parent_kobj,
380e34ff490STejun Heo const void *new_ns)
3818a82472fSCornelia Huck {
3828a82472fSCornelia Huck return 0;
3838a82472fSCornelia Huck }
3848a82472fSCornelia Huck
sysfs_create_mount_point(struct kobject * parent_kobj,const char * name)38587d2846fSEric W. Biederman static inline int sysfs_create_mount_point(struct kobject *parent_kobj,
38687d2846fSEric W. Biederman const char *name)
38787d2846fSEric W. Biederman {
38887d2846fSEric W. Biederman return 0;
38987d2846fSEric W. Biederman }
39087d2846fSEric W. Biederman
sysfs_remove_mount_point(struct kobject * parent_kobj,const char * name)39187d2846fSEric W. Biederman static inline void sysfs_remove_mount_point(struct kobject *parent_kobj,
39287d2846fSEric W. Biederman const char *name)
39387d2846fSEric W. Biederman {
39487d2846fSEric W. Biederman }
39587d2846fSEric W. Biederman
sysfs_create_file_ns(struct kobject * kobj,const struct attribute * attr,const void * ns)39658292cbeSTejun Heo static inline int sysfs_create_file_ns(struct kobject *kobj,
39758292cbeSTejun Heo const struct attribute *attr,
39858292cbeSTejun Heo const void *ns)
3991da177e4SLinus Torvalds {
4001da177e4SLinus Torvalds return 0;
4011da177e4SLinus Torvalds }
4021da177e4SLinus Torvalds
sysfs_create_files(struct kobject * kobj,const struct attribute * const * attr)4031c205ae1SAndi Kleen static inline int sysfs_create_files(struct kobject *kobj,
4049ee4685cSJani Nikula const struct attribute * const *attr)
4051c205ae1SAndi Kleen {
4061c205ae1SAndi Kleen return 0;
4071c205ae1SAndi Kleen }
4081c205ae1SAndi Kleen
sysfs_chmod_file(struct kobject * kobj,const struct attribute * attr,umode_t mode)40959f69015STejun Heo static inline int sysfs_chmod_file(struct kobject *kobj,
41048176a97SAl Viro const struct attribute *attr, umode_t mode)
41131e5abe9SKay Sievers {
41231e5abe9SKay Sievers return 0;
41331e5abe9SKay Sievers }
4141da177e4SLinus Torvalds
4152afc9166SBart Van Assche static inline struct kernfs_node *
sysfs_break_active_protection(struct kobject * kobj,const struct attribute * attr)4162afc9166SBart Van Assche sysfs_break_active_protection(struct kobject *kobj,
4172afc9166SBart Van Assche const struct attribute *attr)
4182afc9166SBart Van Assche {
4192afc9166SBart Van Assche return NULL;
4202afc9166SBart Van Assche }
4212afc9166SBart Van Assche
sysfs_unbreak_active_protection(struct kernfs_node * kn)4222afc9166SBart Van Assche static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn)
4232afc9166SBart Van Assche {
4242afc9166SBart Van Assche }
4252afc9166SBart Van Assche
sysfs_remove_file_ns(struct kobject * kobj,const struct attribute * attr,const void * ns)42658292cbeSTejun Heo static inline void sysfs_remove_file_ns(struct kobject *kobj,
42758292cbeSTejun Heo const struct attribute *attr,
42858292cbeSTejun Heo const void *ns)
4291da177e4SLinus Torvalds {
4301da177e4SLinus Torvalds }
4311da177e4SLinus Torvalds
sysfs_remove_file_self(struct kobject * kobj,const struct attribute * attr)4326b0afc2aSTejun Heo static inline bool sysfs_remove_file_self(struct kobject *kobj,
4336b0afc2aSTejun Heo const struct attribute *attr)
4346b0afc2aSTejun Heo {
4356b0afc2aSTejun Heo return false;
4366b0afc2aSTejun Heo }
4376b0afc2aSTejun Heo
sysfs_remove_files(struct kobject * kobj,const struct attribute * const * attr)4381c205ae1SAndi Kleen static inline void sysfs_remove_files(struct kobject *kobj,
4399ee4685cSJani Nikula const struct attribute * const *attr)
4401c205ae1SAndi Kleen {
4411c205ae1SAndi Kleen }
4421c205ae1SAndi Kleen
sysfs_create_bin_file(struct kobject * kobj,const struct bin_attribute * attr)44359f69015STejun Heo static inline int sysfs_create_bin_file(struct kobject *kobj,
44466ecb92bSPhil Carmody const struct bin_attribute *attr)
4451da177e4SLinus Torvalds {
4461da177e4SLinus Torvalds return 0;
4471da177e4SLinus Torvalds }
4481da177e4SLinus Torvalds
sysfs_remove_bin_file(struct kobject * kobj,const struct bin_attribute * attr)4493612e06bSDavid Rientjes static inline void sysfs_remove_bin_file(struct kobject *kobj,
45066ecb92bSPhil Carmody const struct bin_attribute *attr)
45159f69015STejun Heo {
45259f69015STejun Heo }
45359f69015STejun Heo
sysfs_create_link(struct kobject * kobj,struct kobject * target,const char * name)45459f69015STejun Heo static inline int sysfs_create_link(struct kobject *kobj,
45559f69015STejun Heo struct kobject *target, const char *name)
45659f69015STejun Heo {
45759f69015STejun Heo return 0;
45859f69015STejun Heo }
45959f69015STejun Heo
sysfs_create_link_nowarn(struct kobject * kobj,struct kobject * target,const char * name)46036ce6dadSCornelia Huck static inline int sysfs_create_link_nowarn(struct kobject *kobj,
46136ce6dadSCornelia Huck struct kobject *target,
46236ce6dadSCornelia Huck const char *name)
46336ce6dadSCornelia Huck {
46436ce6dadSCornelia Huck return 0;
46536ce6dadSCornelia Huck }
46636ce6dadSCornelia Huck
sysfs_remove_link(struct kobject * kobj,const char * name)46759f69015STejun Heo static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
4681da177e4SLinus Torvalds {
4691da177e4SLinus Torvalds }
4701da177e4SLinus Torvalds
sysfs_rename_link_ns(struct kobject * k,struct kobject * t,const char * old_name,const char * new_name,const void * ns)4714b30ee58STejun Heo static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t,
4724b30ee58STejun Heo const char *old_name,
4734b30ee58STejun Heo const char *new_name, const void *ns)
4747cb32942SEric W. Biederman {
4757cb32942SEric W. Biederman return 0;
4767cb32942SEric W. Biederman }
4777cb32942SEric W. Biederman
sysfs_delete_link(struct kobject * k,struct kobject * t,const char * name)478746edb7aSEric W. Biederman static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
479746edb7aSEric W. Biederman const char *name)
480746edb7aSEric W. Biederman {
481746edb7aSEric W. Biederman }
482746edb7aSEric W. Biederman
sysfs_create_group(struct kobject * kobj,const struct attribute_group * grp)48359f69015STejun Heo static inline int sysfs_create_group(struct kobject *kobj,
48459f69015STejun Heo const struct attribute_group *grp)
4851da177e4SLinus Torvalds {
4861da177e4SLinus Torvalds return 0;
4871da177e4SLinus Torvalds }
4881da177e4SLinus Torvalds
sysfs_create_groups(struct kobject * kobj,const struct attribute_group ** groups)489f7998780SGreg Kroah-Hartman static inline int sysfs_create_groups(struct kobject *kobj,
490f7998780SGreg Kroah-Hartman const struct attribute_group **groups)
491f7998780SGreg Kroah-Hartman {
492574979c6SGreg Kroah-Hartman return 0;
493f7998780SGreg Kroah-Hartman }
494f7998780SGreg Kroah-Hartman
sysfs_update_groups(struct kobject * kobj,const struct attribute_group ** groups)495aac1f7f9SJiri Olsa static inline int sysfs_update_groups(struct kobject *kobj,
496aac1f7f9SJiri Olsa const struct attribute_group **groups)
497aac1f7f9SJiri Olsa {
498aac1f7f9SJiri Olsa return 0;
499aac1f7f9SJiri Olsa }
500aac1f7f9SJiri Olsa
sysfs_update_group(struct kobject * kobj,const struct attribute_group * grp)5011cbfb7a5SRandy Dunlap static inline int sysfs_update_group(struct kobject *kobj,
5021cbfb7a5SRandy Dunlap const struct attribute_group *grp)
5031cbfb7a5SRandy Dunlap {
5041cbfb7a5SRandy Dunlap return 0;
5051cbfb7a5SRandy Dunlap }
5061cbfb7a5SRandy Dunlap
sysfs_remove_group(struct kobject * kobj,const struct attribute_group * grp)50759f69015STejun Heo static inline void sysfs_remove_group(struct kobject *kobj,
50859f69015STejun Heo const struct attribute_group *grp)
5091da177e4SLinus Torvalds {
5101da177e4SLinus Torvalds }
5111da177e4SLinus Torvalds
sysfs_remove_groups(struct kobject * kobj,const struct attribute_group ** groups)512f7998780SGreg Kroah-Hartman static inline void sysfs_remove_groups(struct kobject *kobj,
513f7998780SGreg Kroah-Hartman const struct attribute_group **groups)
514f7998780SGreg Kroah-Hartman {
515f7998780SGreg Kroah-Hartman }
516f7998780SGreg Kroah-Hartman
sysfs_add_file_to_group(struct kobject * kobj,const struct attribute * attr,const char * group)517dfa87c82SAlan Stern static inline int sysfs_add_file_to_group(struct kobject *kobj,
518dfa87c82SAlan Stern const struct attribute *attr, const char *group)
519dfa87c82SAlan Stern {
520dfa87c82SAlan Stern return 0;
521dfa87c82SAlan Stern }
522dfa87c82SAlan Stern
sysfs_remove_file_from_group(struct kobject * kobj,const struct attribute * attr,const char * group)523dfa87c82SAlan Stern static inline void sysfs_remove_file_from_group(struct kobject *kobj,
524d701d8a3SRalf Baechle const struct attribute *attr, const char *group)
525dfa87c82SAlan Stern {
526dfa87c82SAlan Stern }
527dfa87c82SAlan Stern
sysfs_merge_group(struct kobject * kobj,const struct attribute_group * grp)52869d44ffbSAlan Stern static inline int sysfs_merge_group(struct kobject *kobj,
52969d44ffbSAlan Stern const struct attribute_group *grp)
53069d44ffbSAlan Stern {
53169d44ffbSAlan Stern return 0;
53269d44ffbSAlan Stern }
53369d44ffbSAlan Stern
sysfs_unmerge_group(struct kobject * kobj,const struct attribute_group * grp)53469d44ffbSAlan Stern static inline void sysfs_unmerge_group(struct kobject *kobj,
53569d44ffbSAlan Stern const struct attribute_group *grp)
53669d44ffbSAlan Stern {
53769d44ffbSAlan Stern }
53869d44ffbSAlan Stern
sysfs_add_link_to_group(struct kobject * kobj,const char * group_name,struct kobject * target,const char * link_name)5390bb8f3d6SRafael J. Wysocki static inline int sysfs_add_link_to_group(struct kobject *kobj,
5400bb8f3d6SRafael J. Wysocki const char *group_name, struct kobject *target,
5410bb8f3d6SRafael J. Wysocki const char *link_name)
5420bb8f3d6SRafael J. Wysocki {
5430bb8f3d6SRafael J. Wysocki return 0;
5440bb8f3d6SRafael J. Wysocki }
5450bb8f3d6SRafael J. Wysocki
sysfs_remove_link_from_group(struct kobject * kobj,const char * group_name,const char * link_name)5460bb8f3d6SRafael J. Wysocki static inline void sysfs_remove_link_from_group(struct kobject *kobj,
5470bb8f3d6SRafael J. Wysocki const char *group_name, const char *link_name)
5480bb8f3d6SRafael J. Wysocki {
5490bb8f3d6SRafael J. Wysocki }
5500bb8f3d6SRafael J. Wysocki
compat_only_sysfs_link_entry_to_kobj(struct kobject * kobj,struct kobject * target_kobj,const char * target_name,const char * symlink_name)5519255782fSSourabh Jain static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
5529255782fSSourabh Jain struct kobject *target_kobj,
5539255782fSSourabh Jain const char *target_name,
5549255782fSSourabh Jain const char *symlink_name)
5559255782fSSourabh Jain {
5569255782fSSourabh Jain return 0;
5579255782fSSourabh Jain }
5589255782fSSourabh Jain
sysfs_notify(struct kobject * kobj,const char * dir,const char * attr)5598c0e3998STrent Piepho static inline void sysfs_notify(struct kobject *kobj, const char *dir,
5608c0e3998STrent Piepho const char *attr)
5614508a7a7SNeilBrown {
5624508a7a7SNeilBrown }
5634508a7a7SNeilBrown
sysfs_init(void)564f20a9eadSAndrew Morton static inline int __must_check sysfs_init(void)
565f20a9eadSAndrew Morton {
566f20a9eadSAndrew Morton return 0;
567f20a9eadSAndrew Morton }
568f20a9eadSAndrew Morton
sysfs_enable_ns(struct kernfs_node * kn)569fa4cd451STejun Heo static inline void sysfs_enable_ns(struct kernfs_node *kn)
570fa4cd451STejun Heo {
571fa4cd451STejun Heo }
572fa4cd451STejun Heo
sysfs_file_change_owner(struct kobject * kobj,const char * name,kuid_t kuid,kgid_t kgid)573f70ce185SChristian Brauner static inline int sysfs_file_change_owner(struct kobject *kobj,
574f70ce185SChristian Brauner const char *name, kuid_t kuid,
575f70ce185SChristian Brauner kgid_t kgid)
576f70ce185SChristian Brauner {
577f70ce185SChristian Brauner return 0;
578f70ce185SChristian Brauner }
579f70ce185SChristian Brauner
sysfs_link_change_owner(struct kobject * kobj,struct kobject * targ,const char * name,kuid_t kuid,kgid_t kgid)5800666a3aeSChristian Brauner static inline int sysfs_link_change_owner(struct kobject *kobj,
5810666a3aeSChristian Brauner struct kobject *targ,
5820666a3aeSChristian Brauner const char *name, kuid_t kuid,
5830666a3aeSChristian Brauner kgid_t kgid)
5840666a3aeSChristian Brauner {
5850666a3aeSChristian Brauner return 0;
5860666a3aeSChristian Brauner }
5870666a3aeSChristian Brauner
sysfs_change_owner(struct kobject * kobj,kuid_t kuid,kgid_t kgid)5882c4f9401SChristian Brauner static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid)
5892c4f9401SChristian Brauner {
5902c4f9401SChristian Brauner return 0;
5912c4f9401SChristian Brauner }
5922c4f9401SChristian Brauner
sysfs_groups_change_owner(struct kobject * kobj,const struct attribute_group ** groups,kuid_t kuid,kgid_t kgid)593303a4276SChristian Brauner static inline int sysfs_groups_change_owner(struct kobject *kobj,
594303a4276SChristian Brauner const struct attribute_group **groups,
595303a4276SChristian Brauner kuid_t kuid, kgid_t kgid)
596303a4276SChristian Brauner {
597303a4276SChristian Brauner return 0;
598303a4276SChristian Brauner }
599303a4276SChristian Brauner
sysfs_group_change_owner(struct kobject * kobj,const struct attribute_group * groups,kuid_t kuid,kgid_t kgid)600303a4276SChristian Brauner static inline int sysfs_group_change_owner(struct kobject *kobj,
6018511d72fSChristian Brauner const struct attribute_group *groups,
602303a4276SChristian Brauner kuid_t kuid, kgid_t kgid)
603303a4276SChristian Brauner {
604303a4276SChristian Brauner return 0;
605303a4276SChristian Brauner }
606303a4276SChristian Brauner
6072efc459dSJoe Perches __printf(2, 3)
sysfs_emit(char * buf,const char * fmt,...)6082efc459dSJoe Perches static inline int sysfs_emit(char *buf, const char *fmt, ...)
6092efc459dSJoe Perches {
6102efc459dSJoe Perches return 0;
6112efc459dSJoe Perches }
6122efc459dSJoe Perches
6132efc459dSJoe Perches __printf(3, 4)
sysfs_emit_at(char * buf,int at,const char * fmt,...)6142efc459dSJoe Perches static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
6152efc459dSJoe Perches {
6162efc459dSJoe Perches return 0;
6172efc459dSJoe Perches }
6181da177e4SLinus Torvalds #endif /* CONFIG_SYSFS */
6191da177e4SLinus Torvalds
sysfs_create_file(struct kobject * kobj,const struct attribute * attr)62058292cbeSTejun Heo static inline int __must_check sysfs_create_file(struct kobject *kobj,
62158292cbeSTejun Heo const struct attribute *attr)
62258292cbeSTejun Heo {
62358292cbeSTejun Heo return sysfs_create_file_ns(kobj, attr, NULL);
62458292cbeSTejun Heo }
62558292cbeSTejun Heo
sysfs_remove_file(struct kobject * kobj,const struct attribute * attr)62658292cbeSTejun Heo static inline void sysfs_remove_file(struct kobject *kobj,
62758292cbeSTejun Heo const struct attribute *attr)
62858292cbeSTejun Heo {
62978e1da62SSimon Wunderlich sysfs_remove_file_ns(kobj, attr, NULL);
63058292cbeSTejun Heo }
63158292cbeSTejun Heo
sysfs_rename_link(struct kobject * kobj,struct kobject * target,const char * old_name,const char * new_name)6324b30ee58STejun Heo static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
6334b30ee58STejun Heo const char *old_name, const char *new_name)
6344b30ee58STejun Heo {
6354b30ee58STejun Heo return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
6364b30ee58STejun Heo }
6374b30ee58STejun Heo
sysfs_notify_dirent(struct kernfs_node * kn)638324a56e1STejun Heo static inline void sysfs_notify_dirent(struct kernfs_node *kn)
639024f6471STejun Heo {
640324a56e1STejun Heo kernfs_notify(kn);
641024f6471STejun Heo }
642024f6471STejun Heo
sysfs_get_dirent(struct kernfs_node * parent,const char * name)643324a56e1STejun Heo static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent,
64489cf2a20SNick Desaulniers const char *name)
645ccf73cf3STejun Heo {
646324a56e1STejun Heo return kernfs_find_and_get(parent, name);
647ccf73cf3STejun Heo }
648ccf73cf3STejun Heo
sysfs_get(struct kernfs_node * kn)649324a56e1STejun Heo static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn)
650ccf73cf3STejun Heo {
651324a56e1STejun Heo kernfs_get(kn);
652324a56e1STejun Heo return kn;
653ccf73cf3STejun Heo }
654ccf73cf3STejun Heo
sysfs_put(struct kernfs_node * kn)655324a56e1STejun Heo static inline void sysfs_put(struct kernfs_node *kn)
656ccf73cf3STejun Heo {
657324a56e1STejun Heo kernfs_put(kn);
658ccf73cf3STejun Heo }
659ccf73cf3STejun Heo
6601da177e4SLinus Torvalds #endif /* _SYSFS_H_ */
661