On a running Linux system, I want to know which device driver module created a particular sysfs entry. Is it possible to know? I know I can grep for relevant strings in the kernel source and try to identify. But, is there a way without doing that?
sysfs is a pseudo file system provided by the Linux kernel that exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel's device model to user space through virtual files.
Sysfs is always mounted on /sys . The directories in Sysfs contain the hierarchy of devices, as they are attached to the computer. Sysfs is the commonly used method to export system information from the kernel space to the user space for specific devices. The sysfs is tied to the device driver model of the kernel.
The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data structures. ( More precisely, the files and directories in sysfs provide a view of the kobject structures defined internally within the kernel.)
You can find which driver has created a sysfs entry by going through its source. If the driver uses device_create_file()/device_remove_file() in its init/exit sequences respectively then you can be sure a sysfs attribute file has been created by the driver. You can also find DEVICE_ATTR(_name, _mode, _show, _store) macro in the source to find out what functionality is provided by the sysfs file. Usually you can either cat the file or echo a string to it. A cat /sys/.../file, will correspond to the _show function and an echo /sys/.../file will correspond to the _store function mentioned in the macro.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With