1

I am trying to read the resource file for my device and mmap it to read the device registers but when i try open the file location error prompts : NO such file or directory. I have changed the permissions of the file using chmod 666. The code I am using to open the file :

sprintf(filePath , "sys/bus/pci/devices/%04x:%02x:%02x.%d/resource0",segment,bus,device,function)

fileHandle = open(filePath , O_RDONLY);

if (fileHandle < 0)
{
    perror("ERRRO : ");
}

The file exists and I am able to read it using the cat utility.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
lokesharo
  • 305
  • 2
  • 11

1 Answers1

3

You are trying to open a relative path (which does not exist):

sys/bus/pci/devices/%04x:%02x:%02x.%d/resource0

instead of an absolute one:

/sys/bus/pci/devices/%04x:%02x:%02x.%d/resource0
MByD
  • 135,866
  • 28
  • 264
  • 277