识别创建 sysfs 条目的内核模块

问题描述 投票:0回答:2

在正在运行的 Linux 系统上,我想知道哪个设备驱动程序模块创建了特定的 sysfs 条目。有可能知道吗?我知道我可以在内核源代码中 grep 查找相关字符串并尝试识别。但是,有没有办法不这样做呢?

linux-kernel linux-device-driver
2个回答
2
投票

您可以通过查看其源代码来找到哪个驱动程序创建了 sysfs 条目。如果驱动程序在其 init/exit 序列中分别使用 device_create_file()/device_remove_file(),那么您可以确定驱动程序已创建 sysfs 属性文件。 您还可以在源代码中找到 DEVICE_ATTR(_name, _mode, _show, _store) 宏来了解 sysfs 文件提供了哪些功能。 通常,您可以对文件进行分类或向其回显字符串。 cat /sys/.../file 将对应于 _show 函数,echo /sys/.../file 将对应于宏中提到的 _store 函数。


0
投票

这不是通用方法,但在许多情况下 sysfs 文件是符号链接。查看符号链接路径,您可能可以知道它属于哪个模块。

root@host:~# ls -l /sys/class/hwmon/hwmon5
lrwxrwxrwx 1 root root 0 2021 年 2 月 27 日 /sys/class/hwmon/hwmon5 -> ../../devices/platform/iio-hwmon/hwmon/hwmon5

© www.soinside.com 2019 - 2024. All rights reserved.