Linux:我怎么知道导出设备节点的模块? [英] Linux: how do i know the module that exports a device node?
问题描述
如果有一个/dev设备节点及其主要/次要数字,我怎么知道导出该节点的内核模块名称?
If a have a /dev device node and its major/minor numbers how do i know the kernel module name that exported this node?
推荐答案
简短答案:
cd /sys/dev/char/major:minor/device/driver/
ls -al | grep module
每个设备通常与一个驱动程序关联,而这就是设备模型"的全部含义. sysfs
文件系统包含此设备及其关联的驱动程序的表示.不幸的是,似乎不是所有的sysfs都有设备节点的表示形式,因此仅当/sys目录包含/dev目录时才适用.
让我们举一个例子,用/dev/video0
Each device is generally associated with a driver, and this is all what the "device model" is about. The sysfs
filesystem contains a representation of this devices and their associated driver. Unfortuantely, it seems not all sysfs have a representation of the device nodes, so this applyd only if your /sys directory contains a /dev directory.
Let's take an example, with /dev/video0
在我的板上,ls -al /dev/video0
输出是
crw------- 1 root root 81, 0 Jan 1 00:00 video0
所以主号码是81,次号码是0. 让我们深入了解sysfs:
So major number is 81 and minor number is 0. Let's dive into sysfs :
# cd /sys
# ls
block class devices fs module
bus dev firmware kernel
sys/dev
目录包含系统的char和block设备的条目:
The sys/dev
directory contains entry for the char and block devices of the system :
# cd dev
# cd char
# ls
10:61 13:64 1:3 1:8 249:0 252:0 29:0 4:65 81:0 89:1
10:62 1:1 1:5 1:9 250:0 253:0 29:1 5:0 81:2
10:63 1:11 1:7 248:0 251:0 254:0 4:64 5:1 81:3
这跟陌生名字的链接到底是什么? 还记得主要数字和次要数字81和0吗? 让我们点击此链接:
What the hell are this links with strange names ? Remember the major and minor number, 81 and 0 ? Let's follow this link :
#cd major:minor (ie 81:0)
#ls -al
drwxr-xr-x 2 root root 0 Jan 1 01:56 .
drwxr-xr-x 3 root root 0 Jan 1 01:56 ..
-r--r--r-- 1 root root 4096 Jan 1 01:56 dev
lrwxrwxrwx 1 root root 0 Jan 1 01:56 device -> ../../../vpfe-capture
-r--r--r-- 1 root root 4096 Jan 1 01:56 index
-r--r--r-- 1 root root 4096 Jan 1 01:56 name
lrwxrwxrwx 1 root root 0 Jan 1 01:56 subsystem -> ../../../../../class/video4linux
-rw-r--r-- 1 root root 4096 Jan 1 01:56 uevent
现在,我们可以看到该设备nod与内核设备相关联,这是将设备呈现给用户空间的方式.该关联是通过链接建立的.如果遵循此链接,则最终会到达带有驱动程序链接的目录中.驱动程序的名称通常是模块的名称:
Now we can see that this device nod, which is how the device is presented to userspace, is associated with a kernel device. This association is made through a link. If we follow this link, we end up in a directory, with a driver link. The name of the driver is usually the name of the module :
# ls -al
drwxr-xr-x 3 root root 0 Jan 1 01:56 .
drwxr-xr-x 25 root root 0 Jan 1 00:00 ..
lrwxrwxrwx 1 root root 0 Jan 1 01:56 driver -> ../../../bus/platform/drivers/vpfe-capture
-r--r--r-- 1 root root 4096 Jan 1 01:56 modalias
lrwxrwxrwx 1 root root 0 Jan 1 01:56 subsystem -> ../../../bus/platform
-rw-r--r-- 1 root root 4096 Jan 1 01:56 uevent
drwxr-xr-x 3 root root 0 Jan 1 01:56 video4linux
所以这里的模块名称是vpfe_capture
So here the name of the module is vpfe_capture
这篇关于Linux:我怎么知道导出设备节点的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!