无法打开/sys/bus/pci/devices/0000:00:01.0/resource
我试图用C代码打开PCI设备的绝对路径无法打开/sys/bus/pci/devices/0000:00:01.0/resource,c,linux,linux-device-driver,pci,C,Linux,Linux Device Driver,Pci,我试图用C代码打开PCI设备的绝对路径 fd = open("/sys/bus/pci/devices/0000:00:01.0/resource", O_RDWR); if (fd < 0) { printf("Not found %s\n", path); return -1; } fd=open(“/sys/bus/pci/devices/0000:00:01.0/resource”,O_RDWR); 如果(fd
fd = open("/sys/bus/pci/devices/0000:00:01.0/resource", O_RDWR);
if (fd < 0) {
printf("Not found %s\n", path);
return -1;
}
fd=open(“/sys/bus/pci/devices/0000:00:01.0/resource”,O_RDWR);
如果(fd<0){
printf(“未找到%s\n”,路径);
返回-1;
}
但是它给了我一个错误,说找不到/sys/bus/pci/devices/0000:00:01.0/resource
有人能告诉我我在这里做什么吗?您试图打开读/写路径,但它只是可读的(这就是
ls-l
输出中的-r--r--
的意思)。您需要将O_RDWR
更改为O_RDONLY
那么,您的系统上是否存在该路径?你认为它是什么设备?是的,我检查过了,它就在我的系统上。你能给我们看一下ls-l/sys/bus/pci/devices/0000:00:01.0/resource
的输出吗?另外,也可以使用perror
而不是printf
来打印errno文本,因为它会为您提供更详细的失败原因。-r--r--r--1根根根4096 Jan 1 00:03/sys/bus/pci/devices/0000:00:01.0/resourceAh,我明白了,但我可以将其设置为chmod 777/sys/bus/pci/devices/0000:00.0/resource吗?欢迎您尝试。我不知道这个设备是什么,也不知道它将如何工作。