Identify kernel module which created a sysfs entry
Asked Answered
T

2

11

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?

Taimi answered 25/10, 2012 at 5:20 Comment(0)
S
2

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.

Straub answered 25/10, 2012 at 9:35 Comment(2)
Thanks sanrio for the reply. I knew about the thing you have mentioned. My question is, given a sysfs entry, is it possible to tell to which driver module(if listed by lsmod) it belongs to on a running Linux system.Taimi
i doubt there is a direct way to do that.. If you do come across one then please share it here :)Straub
T
0

This is not a universal way, but in many cases sysfs files are symlinks. Looking at symlink path, you probably can realize which module it belongs to.

root@host:~# ls -l /sys/class/hwmon/hwmon5                                                                                                                                                                                                                                               
lrwxrwxrwx  1 root root  0  Feb 27 2021  /sys/class/hwmon/hwmon5 -> ../../devices/platform/iio-hwmon/hwmon/hwmon5
Tranche answered 16/4 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.