cregit-Linux how code gets into the kernel

Release 4.12 include/linux/sysfs.h

Directory: include/linux
/*
 * sysfs.h - definitions for the device driver filesystem
 *
 * Copyright (c) 2001,2002 Patrick Mochel
 * Copyright (c) 2004 Silicon Graphics, Inc.
 * Copyright (c) 2007 SUSE Linux Products GmbH
 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
 *
 * Please see Documentation/filesystems/sysfs.txt for more information.
 */

#ifndef _SYSFS_H_

#define _SYSFS_H_

#include <linux/kernfs.h>
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/lockdep.h>
#include <linux/kobject_ns.h>
#include <linux/stat.h>
#include <linux/atomic.h>

struct kobject;
struct module;
struct bin_attribute;
enum kobj_ns_type;


struct attribute {
	
const char		*name;
	
umode_t			mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
	
bool			ignore_lockdep:1;
	
struct lock_class_key	*key;
	
struct lock_class_key	skey;
#endif
};

/**
 *      sysfs_attr_init - initialize a dynamically allocated sysfs attribute
 *      @attr: struct attribute to initialize
 *
 *      Initialize a dynamically allocated struct attribute so we can
 *      make lockdep happy.  This is a new requirement for attributes
 *      and initially this is only needed when lockdep is enabled.
 *      Lockdep gives a nice error when your attribute is added to
 *      sysfs if you don't have this.
 */
#ifdef CONFIG_DEBUG_LOCK_ALLOC

#define sysfs_attr_init(attr)				\
do {                                                    \
        static struct lock_class_key __key;             \
                                                        \
        (attr)->key = &__key;                           \
} while (0)
#else

#define sysfs_attr_init(attr) do {} while (0)
#endif

/**
 * struct attribute_group - data structure used to declare an attribute group.
 * @name:       Optional: Attribute group name
 *              If specified, the attribute group will be created in
 *              a new subdirectory with this name.
 * @is_visible: Optional: Function to return permissions associated with an
 *              attribute of the group. Will be called repeatedly for each
 *              non-binary attribute in the group. Only read/write
 *              permissions as well as SYSFS_PREALLOC are accepted. Must
 *              return 0 if an attribute is not visible. The returned value
 *              will replace static permissions defined in struct attribute.
 * @is_bin_visible:
 *              Optional: Function to return permissions associated with a
 *              binary attribute of the group. Will be called repeatedly
 *              for each binary attribute in the group. Only read/write
 *              permissions as well as SYSFS_PREALLOC are accepted. Must
 *              return 0 if a binary attribute is not visible. The returned
 *              value will replace static permissions defined in
 *              struct bin_attribute.
 * @attrs:      Pointer to NULL terminated list of attributes.
 * @bin_attrs:  Pointer to NULL terminated list of binary attributes.
 *              Either attrs or bin_attrs or both must be provided.
 */

struct attribute_group {
	
const char		*name;
	
umode_t			(*is_visible)(struct kobject *,
					      struct attribute *, int);
	
umode_t			(*is_bin_visible)(struct kobject *,
						  struct bin_attribute *, int);
	
struct attribute	**attrs;
	
struct bin_attribute	**bin_attrs;
};

/**
 * Use these macros to make defining attributes easier. See include/linux/device.h
 * for examples..
 */


#define SYSFS_PREALLOC 010000


#define __ATTR(_name, _mode, _show, _store) {                               \
        .attr = {.name = __stringify(_name),                            \
                 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) },             \
        .show   = _show,                                                \
        .store  = _store,                                               \
}


#define __ATTR_PREALLOC(_name, _mode, _show, _store) {                       \
        .attr = {.name = __stringify(_name),                            \
                 .mode = SYSFS_PREALLOC | VERIFY_OCTAL_PERMISSIONS(_mode) },\
        .show   = _show,                                                \
        .store  = _store,                                               \
}


#define __ATTR_RO(_name) {                                               \
        .attr   = { .name = __stringify(_name), .mode = S_IRUGO },      \
        .show   = _name##_show,                                         \
}


#define __ATTR_WO(_name) {                                               \
        .attr   = { .name = __stringify(_name), .mode = S_IWUSR },      \
        .store  = _name##_store,                                        \
}


#define __ATTR_RW(_name) __ATTR(_name, (S_IWUSR | S_IRUGO),              \
                         _name##_show, _name##_store)


#define __ATTR_NULL { .attr = { .name = NULL } }

#ifdef CONFIG_DEBUG_LOCK_ALLOC

#define __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) {       \
        .attr = {.name = __stringify(_name), .mode = _mode,     \
                        .ignore_lockdep = true },               \
        .show           = _show,                                \
        .store          = _store,                               \
}
#else

#define __ATTR_IGNORE_LOCKDEP	__ATTR
#endif


#define __ATTRIBUTE_GROUPS(_name)				\
static const struct attribute_group *_name##_groups[] = {       \
        &_name##_group,                                         \
        NULL,                                                   \
}


#define ATTRIBUTE_GROUPS(_name)					\
static const struct attribute_group _name##_group = {           \
        .attrs = _name##_attrs,                                 \
};                                                              \
__ATTRIBUTE_GROUPS(_name)

struct file;
struct vm_area_struct;


struct bin_attribute {
	
struct attribute	attr;
	
size_t			size;
	
void			*private;
	
ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
			char *, loff_t, size_t);
	
ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
			 char *, loff_t, size_t);
	
int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
		    struct vm_area_struct *vma);
};

/**
 *      sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
 *      @attr: struct bin_attribute to initialize
 *
 *      Initialize a dynamically allocated struct bin_attribute so we
 *      can make lockdep happy.  This is a new requirement for
 *      attributes and initially this is only needed when lockdep is
 *      enabled.  Lockdep gives a nice error when your attribute is
 *      added to sysfs if you don't have this.
 */

#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)

/* macros to create static binary attributes easier */

#define __BIN_ATTR(_name, _mode, _read, _write, _size) {               \
        .attr = { .name = __stringify(_name), .mode = _mode },          \
        .read   = _read,                                                \
        .write  = _write,                                               \
        .size   = _size,                                                \
}


#define __BIN_ATTR_RO(_name, _size) {                                       \
        .attr   = { .name = __stringify(_name), .mode = S_IRUGO },      \
        .read   = _name##_read,                                         \
        .size   = _size,                                                \
}


#define __BIN_ATTR_RW(_name, _size) __BIN_ATTR(_name,                       \
                                   (S_IWUSR | S_IRUGO), _name##_read,   \
                                   _name##_write, _size)


#define __BIN_ATTR_NULL __ATTR_NULL


#define BIN_ATTR(_name, _mode, _read, _write, _size)			\
struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \
                                        _write, _size)


#define BIN_ATTR_RO(_name, _size)					\
struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)


#define BIN_ATTR_RW(_name, _size)					\
struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)


struct sysfs_ops {
	
ssize_t	(*show)(struct kobject *, struct attribute *, char *);
	
ssize_t	(*store)(struct kobject *, struct attribute *, const char *, size_t);
};

#ifdef CONFIG_SYSFS

int __must_check sysfs_create_dir_ns(struct kobject *kobj, const void *ns);
void sysfs_remove_dir(struct kobject *kobj);
int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
				     const void *new_ns);
int __must_check sysfs_move_dir_ns(struct kobject *kobj,
				   struct kobject *new_parent_kobj,
				   const void *new_ns);
int __must_check sysfs_create_mount_point(struct kobject *parent_kobj,
					  const char *name);
void sysfs_remove_mount_point(struct kobject *parent_kobj,
			      const char *name);

int __must_check sysfs_create_file_ns(struct kobject *kobj,
				      const struct attribute *attr,
				      const void *ns);
int __must_check sysfs_create_files(struct kobject *kobj,
				   const struct attribute **attr);
int __must_check sysfs_chmod_file(struct kobject *kobj,
				  const struct attribute *attr, umode_t mode);
void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
			  const void *ns);
bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr);
void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);

int __must_check sysfs_create_bin_file(struct kobject *kobj,
				       const struct bin_attribute *attr);
void sysfs_remove_bin_file(struct kobject *kobj,
			   const struct bin_attribute *attr);

int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
				   const char *name);
int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
					  struct kobject *target,
					  const char *name);
void sysfs_remove_link(struct kobject *kobj, const char *name);

int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target,
			 const char *old_name, const char *new_name,
			 const void *new_ns);

void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
			const char *name);

int __must_check sysfs_create_group(struct kobject *kobj,
				    const struct attribute_group *grp);
int __must_check sysfs_create_groups(struct kobject *kobj,
				     const struct attribute_group **groups);
int sysfs_update_group(struct kobject *kobj,
		       const struct attribute_group *grp);
void sysfs_remove_group(struct kobject *kobj,
			const struct attribute_group *grp);
void sysfs_remove_groups(struct kobject *kobj,
			 const struct attribute_group **groups);
int sysfs_add_file_to_group(struct kobject *kobj,
			const struct attribute *attr, const char *group);
void sysfs_remove_file_from_group(struct kobject *kobj,
			const struct attribute *attr, const char *group);
int sysfs_merge_group(struct kobject *kobj,
		       const struct attribute_group *grp);
void sysfs_unmerge_group(struct kobject *kobj,
		       const struct attribute_group *grp);
int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
			    struct kobject *target, const char *link_name);
void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
				  const char *link_name);
int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj,
				      struct kobject *target_kobj,
				      const char *target_name);

void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);

int __must_check sysfs_init(void);


static inline void sysfs_enable_ns(struct kernfs_node *kn) { return kernfs_enable_ns(kn); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo18100.00%1100.00%
Total18100.00%1100.00%

#else /* CONFIG_SYSFS */
static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1365.00%133.33%
Tejun Heo735.00%266.67%
Total20100.00%3100.00%


static inline void sysfs_remove_dir(struct kobject *kobj) { }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton981.82%133.33%
David Rientjes19.09%133.33%
Tejun Heo19.09%133.33%
Total11100.00%3100.00%


static inline int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, const void *new_ns) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1560.00%233.33%
Tejun Heo728.00%233.33%
Cornelia Huck28.00%116.67%
Eric W. Biedermann14.00%116.67%
Total25100.00%6100.00%


static inline int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, const void *new_ns) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Cornelia Huck1456.00%120.00%
Tejun Heo832.00%240.00%
Andrew Morton312.00%240.00%
Total25100.00%5100.00%


static inline int sysfs_create_mount_point(struct kobject *parent_kobj, const char *name) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann20100.00%1100.00%
Total20100.00%1100.00%


static inline void sysfs_remove_mount_point(struct kobject *parent_kobj, const char *name) { }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann16100.00%1100.00%
Total16100.00%1100.00%


static inline int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr, const void *ns) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1869.23%133.33%
Tejun Heo830.77%266.67%
Total26100.00%3100.00%


static inline int sysfs_create_files(struct kobject *kobj, const struct attribute **attr) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andi Kleen22100.00%1100.00%
Total22100.00%1100.00%


static inline int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr, umode_t mode) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Kay Sievers2291.67%133.33%
Al Viro14.17%133.33%
Jean Delvare14.17%133.33%
Total24100.00%3100.00%


static inline void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, const void *ns) { }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1359.09%125.00%
Tejun Heo836.36%250.00%
David Rientjes14.55%125.00%
Total22100.00%4100.00%


static inline bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr) { return false; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo21100.00%1100.00%
Total21100.00%1100.00%


static inline void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr) { }

Contributors

PersonTokensPropCommitsCommitProp
Andi Kleen18100.00%1100.00%
Total18100.00%1100.00%


static inline int sysfs_create_bin_file(struct kobject *kobj, const struct bin_attribute *attr) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1676.19%133.33%
Tejun Heo419.05%133.33%
Phil Carmody14.76%133.33%
Total21100.00%3100.00%


static inline void sysfs_remove_bin_file(struct kobject *kobj, const struct bin_attribute *attr) { }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton952.94%125.00%
Tejun Heo529.41%125.00%
David Rientjes211.76%125.00%
Phil Carmody15.88%125.00%
Total17100.00%4100.00%


static inline int sysfs_create_link(struct kobject *kobj, struct kobject *target, const char *name) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Cornelia Huck2080.00%133.33%
Andrew Morton416.00%133.33%
Tejun Heo14.00%133.33%
Total25100.00%3100.00%


static inline int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target, const char *name) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1248.00%133.33%
Tejun Heo832.00%133.33%
Cornelia Huck520.00%133.33%
Total25100.00%3100.00%


static inline void sysfs_remove_link(struct kobject *kobj, const char *name) { }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton956.25%133.33%
Tejun Heo637.50%133.33%
David Rientjes16.25%133.33%
Total16100.00%3100.00%


static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t, const char *old_name, const char *new_name, const void *ns) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann2982.86%150.00%
Tejun Heo617.14%150.00%
Total35100.00%2100.00%


static inline void sysfs_delete_link(struct kobject *k, struct kobject *t, const char *name) { }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann21100.00%1100.00%
Total21100.00%1100.00%


static inline int sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Randy Dunlap1571.43%150.00%
Andrew Morton628.57%150.00%
Total21100.00%2100.00%


static inline int sysfs_create_groups(struct kobject *kobj, const struct attribute_group **groups) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Greg Kroah-Hartman22100.00%2100.00%
Total22100.00%2100.00%


static inline int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1361.90%133.33%
Randy Dunlap628.57%133.33%
Tejun Heo29.52%133.33%
Total21100.00%3100.00%


static inline void sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp) { }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton1482.35%133.33%
Tejun Heo211.76%133.33%
David Rientjes15.88%133.33%
Total17100.00%3100.00%


static inline void sysfs_remove_groups(struct kobject *kobj, const struct attribute_group **groups) { }

Contributors

PersonTokensPropCommitsCommitProp
Greg Kroah-Hartman18100.00%1100.00%
Total18100.00%1100.00%


static inline int sysfs_add_file_to_group(struct kobject *kobj, const struct attribute *attr, const char *group) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern26100.00%1100.00%
Total26100.00%1100.00%


static inline void sysfs_remove_file_from_group(struct kobject *kobj, const struct attribute *attr, const char *group) { }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern2195.45%150.00%
Ralf Bächle14.55%150.00%
Total22100.00%2100.00%


static inline int sysfs_merge_group(struct kobject *kobj, const struct attribute_group *grp) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern21100.00%1100.00%
Total21100.00%1100.00%


static inline void sysfs_unmerge_group(struct kobject *kobj, const struct attribute_group *grp) { }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern17100.00%1100.00%
Total17100.00%1100.00%


static inline int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, struct kobject *target, const char *link_name) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki30100.00%1100.00%
Total30100.00%1100.00%


static inline void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, const char *link_name) { }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki21100.00%1100.00%
Total21100.00%1100.00%


static inline int __compat_only_sysfs_link_entry_to_kobj( struct kobject *kobj, struct kobject *target_kobj, const char *target_name) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Jarkko Sakkinen25100.00%1100.00%
Total25100.00%1100.00%


static inline void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr) { }

Contributors

PersonTokensPropCommitsCommitProp
Neil Brown1885.71%133.33%
Trent Piepho29.52%133.33%
Tejun Heo14.76%133.33%
Total21100.00%3100.00%


static inline int __must_check sysfs_init(void) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Andrew Morton13100.00%1100.00%
Total13100.00%1100.00%


static inline void sysfs_enable_ns(struct kernfs_node *kn) { }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo11100.00%1100.00%
Total11100.00%1100.00%

#endif /* CONFIG_SYSFS */
static inline int __must_check sysfs_create_file(struct kobject *kobj, const struct attribute *attr) { return sysfs_create_file_ns(kobj, attr, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo29100.00%1100.00%
Total29100.00%1100.00%


static inline void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr) { sysfs_remove_file_ns(kobj, attr, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo2696.30%150.00%
Simon Wunderlich13.70%150.00%
Total27100.00%2100.00%


static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target, const char *old_name, const char *new_name) { return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo41100.00%1100.00%
Total41100.00%1100.00%


static inline void sysfs_notify_dirent(struct kernfs_node *kn) { kernfs_notify(kn); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo17100.00%2100.00%
Total17100.00%2100.00%


static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent, const unsigned char *name) { return kernfs_find_and_get(parent, name); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo28100.00%3100.00%
Total28100.00%3100.00%


static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn) { kernfs_get(kn); return kn; }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo22100.00%2100.00%
Total22100.00%2100.00%


static inline void sysfs_put(struct kernfs_node *kn) { kernfs_put(kn); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo17100.00%3100.00%
Total17100.00%3100.00%

#endif /* _SYSFS_H_ */

Overall Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo39319.91%1314.44%
Patrick Mochel22811.55%1415.56%
Andrew Morton22611.45%55.56%
Eric W. Biedermann20710.49%88.89%
Alan Stern1849.32%33.33%
Greg Kroah-Hartman1326.69%1213.33%
Rafael J. Wysocki944.76%11.11%
Cornelia Huck733.70%22.22%
Andi Kleen733.70%11.11%
Oliver Schinagl733.70%22.22%
Neil Brown512.58%22.22%
Jarkko Sakkinen442.23%11.11%
Kay Sievers371.87%11.11%
James Bottomley311.57%22.22%
Jesse Barnes281.42%11.11%
Randy Dunlap221.11%22.22%
Emilio López180.91%11.11%
Chris Wright150.76%11.11%
Rui Zhang80.41%11.11%
David Rientjes60.30%11.11%
Al Viro40.20%33.33%
Trent Piepho40.20%11.11%
Phil Carmody40.20%11.11%
Ralf Bächle40.20%22.22%
Frank Haverkamp30.15%11.11%
David Howells30.15%11.11%
Jean Delvare20.10%11.11%
Dmitry Torokhov20.10%11.11%
Rusty Russell10.05%11.11%
Arun Sharma10.05%11.11%
Simon Wunderlich10.05%11.11%
Maneesh Soni10.05%11.11%
Stephen Rothwell10.05%11.11%
Total1974100.00%90100.00%
Directory: include/linux
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.