kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: tobias@gambas-buch.de (Tobias Boege)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Dynamic Sysfs Attribute Files
Date: Wed, 24 Apr 2013 15:39:42 +0200	[thread overview]
Message-ID: <20130424133942.GD510@aurora> (raw)
In-Reply-To: <CACqRspD4zV6GrbFOOzvdCWHhK=CY0rx5EnGPt1YUUU67qL_LyA@mail.gmail.com>

On Wed, 24 Apr 2013, Matt Davis wrote:
> 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

Hmm, the following led some places on my system:

$ shopt -s extglob
$ find /sys/!(module|kernel) -name "*[0-9]"
...
/sys/firmware/acpi/interrupts/gpe00
/sys/firmware/acpi/interrupts/gpe01
/sys/firmware/acpi/interrupts/gpe02
/sys/firmware/acpi/interrupts/gpe03
/sys/firmware/acpi/interrupts/gpe04
/sys/firmware/acpi/interrupts/gpe05
...

>From a quick grep, the source _may_ be somewhere around

drivers/acpi/sysfs.c:
658                         sprintf(buffer, "gpe%02X", i);

Hope this helps you further.

Regards,
Tobi

  parent reply	other threads:[~2013-04-24 13:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-24 10:02 Dynamic Sysfs Attribute Files Matt Davis
2013-04-24 13:32 ` Rami Rosen
2013-04-24 13:39 ` Tobias Boege [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-04-24 22:24 Matt Davis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130424133942.GD510@aurora \
    --to=tobias@gambas-buch.de \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).