Dynamic Sysfs Attribute Files

Matt Davis mattdavis9 at gmail.com
Wed Apr 24 06:02:50 EDT 2013


Hello,
I want my kernel module to dynamically add sysfs files for its
corresponding device.  Without going into detail, the attribute file
will be named something like: /sys/class/myclass/mydev0/fileX where
'X' is an integer ranging from 1-256.  I did not see anything in the
api to allow this.  I suppose I could just dynamically allocate an
attribute, give it the unique name by tacking on my own integer, and
pass that off to device_create_file().  However, I have not seen
anywhere in the codebase where another module does this; I assume it
is not allowed (or there is a better solution).

The other solution (instead of sysfs) would be to add an ioctl, but
this means the userland application must know the specific 'file' id
to query.  In the sysfs version above, the userland application can
just grab the directory listing of /sys/class/myclaass/mydev0/ and see
how many 'file' instances exist.

-Matt



More information about the Kernelnewbies mailing list