STRUCT ATTRIBUTE_GROUP(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 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_visible and is_bin_visible are allowed to return SYSFS_GROUP_INVISIBLE to 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 and SYSFS_PREALLOC are accepted here β€” that's the whole menu, don't get creative πŸ”₯. it must return 0 if an attribute is not visible. whatever value it returns replaces the static permissions defined in struct attribute. and when you're assigning this callback, use SYSFS_GROUP_VISIBLE to specify separate _group_visible and _attr_visible handlers. 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 plus SYSFS_PREALLOC (and the visibility flags for named groups β€” yes, those get in too). must return 0 if a binary attribute is not visible. the returned value replaces the static permissions defined in struct bin_attribute. and heads up: 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: a function returning the size of a binary attribute of the group. called repeatedly for each binary attribute in the group. it overwrites the size field embedded inside the attribute itself. so it fully takes over, no cap πŸ’€
  • {unnamed_union} β€” anonymous again, we love a recurring bit ✨
  • attrs β€” pointer to a NULL-terminated list of attributes.
  • bin_attrs β€” pointer to a NULL-terminated list of binary attributes.
⚠️ real talk: either attrs or bin_attrs or both must be provided. you can't just show up with neither, that's not a vibe check you pass πŸ™ˆ

🌈 SEE ALSO 🌈


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