2

I need to create a whole bunch of attributes for a driver, which makes it impractical to allocate them statically (64 directories with 5 attributes each).

It looks like there are multiple ways to create directories in sysfs. One seems to be sysfs_create_dir_ns() and the other seems to be creating struct kobjects, add them to the sysfs and then add attributes to them.

Is there a recommended (or "best") way to do this?

Jan
  • 485
  • 3
  • 9
  • It seems to me that doing this is not really recommended or supported at all. If you need something like this, you should probably create sub-devices. – Jan Sep 22 '15 at 09:48

1 Answers1

2

One possible way, which at least works if you only have to create one level of subdirectories, is using a struct attribute_group. This structure has a member name which - if not NULL - will be used as a directory in which the attributes listed in the attribute group will be inserted.

This does not, however, allow multiple layers of directories, because you don't have matching kobjects for the first level created by sysfs_create_group().

Jan
  • 485
  • 3
  • 9
  • Thx. This is exactly what I needed to organize my attributes in directories with device_create_with_groups. Split up the attributes into groups and assign the name member of the struct attribute_group to the subdirectory name. – oscar1919 Jun 04 '21 at 07:54