STRUCT DEVICE_ATTRIBUTE(9)
π struct device_attribute(9) β like, the Kernel API Manual's own page about exporting device attributes π
okay so listen bestie, this whole page lives in the Kernel API Manual, and it's about struct device_attribute β literally the interface for exporting device attributes. that's the whole vibe. it's giving "sysfs but make it a struct" β¨
πΈ NAME πΈ
struct device_attribute β Interface for exporting device attributes. periodt. that's it, that's the name π
β¨ SYNOPSIS β¨
here's the whole shape of it, bestie β read it slow, it's just two anonymous unions doing their thing π¦
struct device_attribute {
struct attribute attr;
union {
ssize_t (*show)(struct device *dev, struct device_attribute *attr,
char *buf);
ssize_t (*show_const)(struct device *dev, const struct
device_attribute *attr, char *buf);
};
union {
ssize_t (*store)(struct device *dev, struct device_attribute
*attr, const char *buf, size_t count);
ssize_t (*store_const)(struct device *dev, const struct
device_attribute *attr, const char *buf, size_t count);
};
};
like β two unions, each with a "normal" version and a const version. pick your fighter, you only get one per union π
π«Ά Members π«Ά
attrβ the sysfs attribute definition itself. the actual backbone, no cap.{unnamed_union}β anonymous. yes, it has no name. mysterious. main character energy honestly πshowβ the Show handler. it's the one doing the showing πshow_constβ the Show handler, but read-only. same energy, more boundaries.{unnamed_union}β anonymous again. two whole unnamed unions on one page, iconic.storeβ the Store handler. it stores things.store_constβ the Store handler, read-only flavor.
bestie please don't try to name those unions. they are unnamed by design and they're thriving π
π SEE ALSO π
the little black book, fr fr. this is maybe the longest SEE ALSO I've ever seen and I'm obsessed β all of these are from Kernel file ./include/linux/device.h:
struct subsys_interface(9), struct dev_ext_attribute(9), DEVICE_ATTR(9), DEVICE_ATTR_RW(9), DEVICE_ATTR_ADMIN_RW(9), DEVICE_ATTR_RW_NAMED(9), DEVICE_ATTR_RO(9), DEVICE_ATTR_ADMIN_RO(9), DEVICE_ATTR_RO_NAMED(9), DEVICE_ATTR_WO(9), DEVICE_ATTR_WO_NAMED(9), DEVICE_ULONG_ATTR(9), DEVICE_INT_ATTR(9), DEVICE_BOOL_ATTR(9), DEVICE_STRING_ATTR_RO(9), enum device_link_state(9), enum dl_dev_state(9), enum device_removable(9), struct dev_links_info(9), struct dev_msi_info(9), enum device_physical_location_panel(9), enum device_physical_location_vertical_position(9), enum device_physical_location_horizontal_position(9), struct device_physical_location(9), enum struct_device_flags(9), struct device(9), struct device_link(9), device_set_driver_override(9), device_has_driver_override(9), device_match_driver_override(9), device_iommu_mapped(9), dev_name(9), dev_bus_name(9), device_find_child_by_name(9), device_find_any_child(9), device_lock_set_class(9), device_lock_reset_class(9)
like, go read all of them. i'll wait. iykyk π
aaand that's the page, bestie π§ this cutie came out of ./include/linux and it's stamped October 2026 β so like, read it again next year and it'll still be here πβ slay π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms