* Dynamic Sysfs Attribute Files
@ 2013-04-24 10:02 Matt Davis
2013-04-24 13:32 ` Rami Rosen
2013-04-24 13:39 ` Tobias Boege
0 siblings, 2 replies; 4+ messages in thread
From: Matt Davis @ 2013-04-24 10:02 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Dynamic Sysfs Attribute Files
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
1 sibling, 0 replies; 4+ messages in thread
From: Rami Rosen @ 2013-04-24 13:32 UTC (permalink / raw)
To: kernelnewbies
Hi,
Take a look in:
http://lxr.free-electrons.com/source/Documentation/filesystems/sysfs.txt
You should consider the sysfs API like
sysfs_create_dir(), sysfs_create_group(), sysfs_create_file()
Best Regards,
Rami Rosen
http://ramirose.wix.com/ramirosen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Dynamic Sysfs Attribute Files
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
1 sibling, 0 replies; 4+ messages in thread
From: Tobias Boege @ 2013-04-24 13:39 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Dynamic Sysfs Attribute Files
@ 2013-04-24 22:24 Matt Davis
0 siblings, 0 replies; 4+ messages in thread
From: Matt Davis @ 2013-04-24 22:24 UTC (permalink / raw)
To: kernelnewbies
> Date: Wed, 24 Apr 2013 15:39:42 +0200
> From: Tobias Boege <tobias@gambas-buch.de>
>
> 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.
Tobi,
That is exactly what I am looking for; that and the fact no one
explicitly flamed me for my idea.
-Matt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-24 22:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
-- strict thread matches above, loose matches on Subject: below --
2013-04-24 22:24 Matt Davis
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).