Hi, I would like to put the contents of an array in sysfs files. I found no simple way to do this, so here are my thoughts in hope someone can hand me a light. -simple array (array of simple type like int, char* and so on) needs: .name, .read, .write, .num, .writenum When exported a directory "name" is created, containing num()+1 entries. There is one entry for each array entry plus the special entry "n". "cat n" gives you the result of num, writing to num calls writenum to change the number of array members. If writenum is NULL the array has fixed size. read is read(struct whatever *, int, char *). The second argument gives the array number, the last one the buffer to print to (as usual). write looks similar, just as in existing sysfs interface (e.g. device_create_file()). -complex array (array of struct) This is even more tricky. You can't do this now if you don't know the number of entries. If you do you can create a struct device_attribute (or similar) for every entry and have different access functions that "know" their index. This is horribly inefficient and ugly. Sort of access struct could be: .name is fmt-string containing %i (or %lli or something like this) .members is an array of structs looking similar to what I described above for the simple array. Now the index gives the index of the struct. .num, .writenum as above Nesting them is probably not worth it at all as it would look horrible. :) Thoughts?
Attachment:
pgpfGiRrvCYsE.pgp
Description: PGP signature
- Follow-Ups:
- Re: Exporting array data in sysfs
- From: Greg KH <[email protected]>
- Re: Exporting array data in sysfs
- Prev by Date: Re: [PATCH 3/4] security: capabilities patch (version 0.4.4), part 3/4: introduce new capabilities
- Next by Date: Re: [PATCH 3/4] security: capabilities patch (version 0.4.4), part 3/4: introduce new capabilities
- Previous by thread: "set_rtc_mmss: can't update from m to n" cluttering my logs
- Next by thread: Re: Exporting array data in sysfs
- Index(es):