STRUCT ATTRIBUTE_GROUP(9)
πΈ struct attribute_group(9) πΈ
okay bestie, so we're deep in the Kernel API Manual today β this is struct attribute_group(9), and honestly? it's giving foundational. it's the data structure you use to declare an attribute group, and if you're doing sysfs stuff you're gonna meet it. let's go π
β¨ NAME β¨
struct attribute_group β the data structure used to declare an attribute group. that's it, that's the whole vibe. π
π¦ SYNOPSIS π¦
struct attribute_group {
const char *name;
union {
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;
const struct attribute *const *attrs_const;
};
const struct bin_attribute *const *bin_attrs;
};
π Members π
π the fields, one by one
nameβ optional! it's the attribute group's name. if you set it, the attribute group gets created in a new subdirectory with this name. and bonus: when a group is named,is_visibleandis_bin_visibleare allowed to returnSYSFS_GROUP_INVISIBLEto control the visibility of the directory itself. so yes, the folder can hide from you. iconic behaviour honestly π«Ά{unnamed_union}β anonymous. no name, no problem. πis_visibleβ optional: a function that returns the permissions tied to an attribute of the group. it gets called repeatedly for each non-binary attribute in the group. only read/write permissions andSYSFS_PREALLOCare accepted here β that's the whole menu, don't get creative π₯. it must return0if an attribute is not visible. whatever value it returns replaces the static permissions defined instruct attribute. and when you're assigning this callback, useSYSFS_GROUP_VISIBLEto specify separate_group_visibleand_attr_visiblehandlers. lowkey important, ngl.is_bin_visibleβ optional: same deal but for a binary attribute of the group. called repeatedly for each binary attribute in the group. accepted permissions are read/write plusSYSFS_PREALLOC(and the visibility flags for named groups β yes, those get in too). must return0if a binary attribute is not visible. the returned value replaces the static permissions defined instruct bin_attribute. and heads up: ifis_visibleis not set, useSYSFS_GROUP_VISIBLEwhen assigning this callback to specify separate_group_visibleand_attr_visiblehandlers.bin_sizeβ optional: a function returning the size of a binary attribute of the group. called repeatedly for each binary attribute in the group. it overwrites thesizefield embedded inside the attribute itself. so it fully takes over, no cap π{unnamed_union}β anonymous again, we love a recurring bit β¨attrsβ pointer to aNULL-terminated list of attributes.bin_attrsβ pointer to aNULL-terminated list of binary attributes.
β οΈ real talk: eitherattrsorbin_attrsor both must be provided. you can't just show up with neither, that's not a vibe check you pass π
π SEE ALSO π
- Kernel file
./include/linux/sysfs.h sysfs_attr_init(9)sysfs_bin_attr_init(9)
and that's the whole page, bestie β go forth and group your attributes responsibly π
this one lives at ./include/linux, dated October 2026, and it's straight from the Kernel API Manual. mwah, see u in the next one πβ¨
π¦ 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