无法打开/sys/bus/pci/devices/0000:00:01.0/resource

时间:2015-12-02 13:31:50

标签: 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;
    }

但是它给我一个错误,说找不到/sys/bus/pci/devices/0000:00:01.0/resource

有人可以指出我在这里做什么吗?

1 个答案:

答案 0 :(得分:2)

您正在尝试打开读/写路径,但它只是可读的(-r--r--r--输出中的ls -l意味着什么)。您需要将O_RDWR更改为O_RDONLY