简体   繁体   English

Linux:我怎么知道导出设备节点的模块?

[英]Linux: how do i know the module that exports a device node?

如果有一个/ dev设备节点及其主要/次要编号,我如何知道导出该节点的内核模块名称?

Short answer : 简短回答:

cd /sys/dev/char/major:minor/device/driver/
ls -al | grep module

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. sysfs文件系统包含此设备及其相关驱动程序的表示。 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. 不幸的是,似乎并非所有sysfs都具有设备节点的表示,因此仅当/ sys目录包含/ dev目录时才应用此选项。 Let's take an example, with /dev/video0 让我们以/dev/video0

On my board, ls -al /dev/video0 output is 在我的主板上, ls -al /dev/video0输出是

crw-------    1 root     root      81,   0 Jan  1 00:00 video0

So major number is 81 and minor number is 0. Let's dive into sysfs : 所以主要数字是81而次要数字是0.让我们深入了解sysfs:

# cd /sys
# ls
block     class     devices   fs        module
bus       dev       firmware  kernel

The sys/dev directory contains entry for the char and block devices of the system : sys/dev目录包含sys/dev的char和块设备的条目:

# 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

What the hell are this links with strange names ? 这到底与陌生的名字有什么联系? Remember the major and minor number, 81 and 0 ? 记住主要和次要数字,81和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

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

So here the name of the module is vpfe_capture 所以这里模块的名称是vpfe_capture

The answer to this question is most likely different based on a number of factors. 基于许多因素,这个问题的答案很可能是不同的。 For example, if you're running udev, devfs, pre-devfs, etc. 例如,如果您正在运行udev,devfs,pre-devfs等。

If you're using Ubuntu (or another equally modern distro) the udevadm command might be what you want. 如果你正在使用Ubuntu(或其他同样现代的发行版), udevadm命令可能就是你想要的。

% udevadm info -q path -n /dev/cdrom
/devices/pci0000:00/0000:00:1f.1/host3/target3:0:0/3:0:0:0/block/sr0

So, my /dev/cdrom is provided by the sr driver, which resides in the sr_mod kernel module. 所以,我的/ dev / cdrom是由sr驱动程序提供的,它位于sr_mod内核模块中。 I don't know of a command that takes /dev/cdrom as an argument and prints sr_mod as output. 我不知道将/dev/cdrom作为参数的命令,并将sr_mod作为输出打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何知道Linux中的下一个设备映射器? - How do I know the next device mapper in Linux? 我如何知道设备驱动程序是否在Linux中工作? - How do I know whether a device driver works in Linux? 如何知道是否有一个(嵌入式/内核模块)设备驱动程序来控制运行中的Linux上的设备? - How to know if there is a (compiled in/kernel module) device driver controlling a device on a running linux? 如何从Linux内核模块的init_module代码创建设备节点? - How to create a device node from the init_module code of a Linux kernel module? 我如何知道Linux内核中的地址是否可读? - How do I know if an address in Linux kernel is readable or not? 我如何知道我的进程在Linux上的调度策略? - How do I know my process's scheduling policy on Linux? Linux中的套接字-我如何知道客户端已完成? - Sockets in Linux - how do I know the client has finished? 我如何知道在Linux上使用哪个串口? - How do I know which serial port to use on Linux? 在Linux中,我如何知道某个TCP数据包是否收到了ACK? - In Linux, how do I know if an ACK is received to a certain TCP packet? 我如何知道在Linux上编写的C程序是否可以在其他地方使用 - How do I know if a C program will written on Linux will work elsewhere
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM