1) What handles /sys/class/gpio ? A kernel module ? a driver ?
It's a kernel interface similar to the /proc
directory.
2) is it possible to have more complicated module parameters in a kernel module, with some directory structure ? Like a 'delays' directory containing the params for delays
Yes; some things in /proc
and /sys
do use directory hierarchies. If you want to modify or expand them, though, you have to modify the kernel.
#3 has a similar answer -- to make changes you need to change the relevant kernel code.
4) How does the gpio thing creates new/deletes files in /sys/class/gpio when you write to [un]export ?
These are not files on disk, they're just system interfaces.1 When you go to read data from a procfs or sysfs file, what you are really doing is making a request for information from the kernel. The data is then formatted and returned. It probably isn't stored anywhere in the form you see it, although parts of it may be stored in the kernel.
When you write to such a file -- not all of them allow this -- you're sending a request to the kernel to do something specific. This can include, e.g., activating or expanding the GPIO interface.
1. read
and write
calls are always system calls anyway, since normal files are normally on disk, and the kernel is needed to access hardware. Hence using a filesystem style API here is natural; even if they are not "real files", accessing whatever resource they represent must involve system calls.
Best Answer
Each loaded module has an entry in
/sys/module
. But there are also kernel components with an entry in/sys/module
that are not loaded as modules. Each kernel component¹ that can be built as a module has an entry in/sys/module
, whether it is compiled and loaded as a module or compiled as part of the main kernel image.lsmod
gets the list of loaded modules from/proc/modules
.I think that only loaded modules have an
initstate
file in their/sys/module
directory, so you can use that too.¹ That's each component of the loaded kernel. The kernel doesn't know or care what modules you may have in files on your hard disk. The kernel doesn't care what modules were built at the same time of the kernel image, either; it may show that via
/proc/config
but it doesn't use that information for anything.