Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify kernel module which created a sysfs entry

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?

like image 395
Santhosh N Avatar asked Oct 25 '12 05:10

Santhosh N


People also ask

What is sysfs entry?

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.

Where is sysfs in Linux?

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.

What is sysfs interface?

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.)


1 Answers

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.

like image 125
spitfire88 Avatar answered Jan 03 '23 19:01

spitfire88