include/linux/sysfs.h
Source file repositories/reference/linux-study-clean/include/linux/sysfs.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/sysfs.h- Extension
.h- Size
- 25345 bytes
- Lines
- 825
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernfs.hlinux/compiler.hlinux/errno.hlinux/list.hlinux/lockdep.hlinux/kobject_ns.hlinux/stat.hlinux/atomic.h
Detected Declarations
struct kobjectstruct modulestruct bin_attributestruct attributestruct attribute_groupstruct filestruct vm_area_structstruct address_spacestruct bin_attributestruct sysfs_opsenum kobj_ns_typefunction sysfs_enable_nsfunction sysfs_create_dir_nsfunction sysfs_remove_dirfunction sysfs_move_dir_nsfunction sysfs_create_mount_pointfunction sysfs_remove_mount_pointfunction sysfs_create_filesfunction sysfs_chmod_filefunction sysfs_break_active_protectionfunction sysfs_unbreak_active_protectionfunction sysfs_remove_filesfunction sysfs_remove_bin_filefunction sysfs_create_link_nowarnfunction sysfs_remove_linkfunction sysfs_delete_linkfunction sysfs_create_groupsfunction sysfs_update_groupsfunction sysfs_update_groupfunction sysfs_remove_groupfunction sysfs_remove_file_from_groupfunction sysfs_unmerge_groupfunction sysfs_remove_link_from_groupfunction sysfs_notifyfunction sysfs_enable_nsfunction sysfs_link_change_ownerfunction sysfs_change_ownerfunction sysfs_groups_change_ownerfunction sysfs_group_change_ownerfunction sysfs_emitfunction sysfs_emit_atfunction sysfs_bin_attr_simple_readfunction sysfs_create_filefunction sysfs_remove_filefunction sysfs_rename_linkfunction sysfs_notify_direntfunction sysfs_put
Annotated Snippet
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
#ifdef CONFIG_CFI
#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) struct { MEMBERS }
#else
#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) union { MEMBERS }
#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. Additionally when a
* group is named, @is_visible and @is_bin_visible may
* return SYSFS_GROUP_INVISIBLE to control visibility of
* the directory itself.
* @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. Use SYSFS_GROUP_VISIBLE() when assigning this
* callback to specify separate _group_visible() and
* _attr_visible() handlers.
* @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 (and the
* visibility flags for named groups) are accepted. Must
* return 0 if a binary attribute is not visible. The
* returned value will replace static permissions defined
* in struct bin_attribute. If @is_visible is not set, Use
* SYSFS_GROUP_VISIBLE() when assigning this callback to
* specify separate _group_visible() and _attr_visible()
* handlers.
* @bin_size:
* Optional: Function to return the size of a binary attribute
* of the group. Will be called repeatedly for each binary
* attribute in the group. Overwrites the size field embedded
* inside the attribute itself.
* @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;
__SYSFS_FUNCTION_ALTERNATIVE(
umode_t (*is_visible)(struct kobject *,
struct attribute *, int);
umode_t (*is_visible_const)(struct kobject *,
const struct attribute *, int);
);
umode_t (*is_bin_visible)(struct kobject *,
const struct bin_attribute *, int);
size_t (*bin_size)(struct kobject *,
const struct bin_attribute *,
int);
union {
struct attribute **attrs;
Annotation
- Immediate include surface: `linux/kernfs.h`, `linux/compiler.h`, `linux/errno.h`, `linux/list.h`, `linux/lockdep.h`, `linux/kobject_ns.h`, `linux/stat.h`, `linux/atomic.h`.
- Detected declarations: `struct kobject`, `struct module`, `struct bin_attribute`, `struct attribute`, `struct attribute_group`, `struct file`, `struct vm_area_struct`, `struct address_space`, `struct bin_attribute`, `struct sysfs_ops`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.