open()返回"没有这样的设备"错误,但是有这样的设备(linux)

Pau*_*nov 5 c linux kernel-module linux-device-driver linux-kernel

我正在尝试使用一个有点旧的DAQ,并且不得不跳过一些箍来获得一个旧的(大约2004年)设备驱动程序来编译它(DTI-DT340 Linux-DAQ-PCI).

我已经达到了编译的程度,我可以加载内核模块,找到卡片,然后我可以使用mknod创建角色设备.

但我似乎无法打开这些设备并继续获得errno 19(ENODEV)'没有这样的设备'当我尝试

open("/dev/dt340/0",O_RDWR);
Run Code Online (Sandbox Code Playgroud)

但是mknod没有关于制作它的抱怨,它就在那里:

# ls -l /dev/dt340/
total 0
crw-rw-r-- 1 root staff 250, 0 2009-04-23 11:02 0
crw-rw-r-- 1 root staff 250, 1 2009-04-23 11:02 1
crw-rw-r-- 1 root staff 250, 2 2009-04-23 11:02 2
crw-rw-r-- 1 root staff 250, 3 2009-04-23 11:02 3
Run Code Online (Sandbox Code Playgroud)

有什么我忽略的事情吗?什么可能是开放失败的原因?

这是我用来加载驱动程序和制作设备的脚本.

#!/bin/bash
module="dt340"
device="dt340"
mode="664"

# invoke modprobe with all arguments we were passed
#/sbin/modprobe -t misc -lroot -f -s $module.o $* || exit 1
insmod $module.ko

# remove stale nodes
rm -f /dev/${device}/[0-3]

major=`awk "\\$2==\"$module\" {print \\$1}" /proc/devices`
mkdir -p /dev/${device}
mknod /dev/${device}/0 c $major 0
mknod /dev/${device}/1 c $major 1
mknod /dev/${device}/2 c $major 2
mknod /dev/${device}/3 c $major 3

# give appropriate group/permissions, and change the group
# not all distributions have staff; some have "users" instead
group="staff"
grep '^staff:' /etc/group > /dev/null || group="users"

chgrp $group /dev/${device}/[0-3]
chmod $mode  /dev/${device}/[0-3]
Run Code Online (Sandbox Code Playgroud)

一些额外的信息:

#grep dt340 /proc/devices 
250 dt340
# lsmod | grep dt340
dt340                  21516  0 
# tail /var/log/messages
Apr 23 11:59:26 ve kernel: [  412.862139] dt340 0000:03:01.0: PCI INT A -> GSI 22 (level, low) -> IRQ 22
Apr 23 11:59:26 ve kernel: [  412.862362] dt340: In function dt340_init_one:
Apr 23 11:59:26 ve kernel: [  412.862363] Device DT340 Rev 0x0 detected at address 0xfebf0000
#lspci | grep 340
03:01.0 Multimedia controller: Data Translation DT340
Run Code Online (Sandbox Code Playgroud)

答案:printk确认-ENODEV是从open()内部抛出的.继老式之后

while ((pdev = pci_find_device(PCI_VENDOR_ID_DTI, PCI_ANY_ID, pdev)))
Run Code Online (Sandbox Code Playgroud)

(已弃用),if(!pdev)结束为true,并返回-ENODEV.

我正在靠近 - 我想我必须通过并更新pci代码以使用更现代的机制......

Mar*_*rkR 8

如果设备显示在/ proc/devices中,并且您确定在mknod中有正确的数字,则驱动程序本身拒绝打开.驱动程序可以从open()返回任何错误代码 - 包括"没有这样的设备",如果它发现初始化硬件时可能会出错.