1

I was asked this question in an interview. You are writing a PCI driver and you want to export the hardware-related information to the /proc filesystem. The interesting thing is that I searched the driver code and I couldn't find any call related to /proc filesystem though actually the information is exported. Is it done automatically? What is the mechanism? Can anyone please explain?

Shog9
  • 156,901
  • 35
  • 231
  • 235
liv2hak
  • 14,472
  • 53
  • 157
  • 270
  • What info is exported to /proc? Is it driver specific (e.g. something like author name) or device specific (e.g. something like bus, slot etc.)? – Rumple Stiltskin Apr 22 '11 at 10:48

2 Answers2

4

Creating entries in the /proc pseudo-filesystem is explained in Linux Device Drivers [3rd ed], chapter 4.

Nowadays you probably want to consider using sysfs instead; it's covered in LDD3 chapter 14.

Eric Seppanen
  • 5,923
  • 30
  • 24
3

One way to do it is for your driver to

  • implement a function that will get called whenever a process reads the corresponding /proc entry with the following signature:

    int (*read_proc)(char *page, char **start, off_t offset, int count, int *eof, void *data);

  • register your function by passing its pointer to create_proc_read_entry(), which accepts the name of the /proc entry as a string among other things:

    create_proc_read_entry("foobar", 0, NULL, your_read_func_ptr, NULL);

When your driver unloads, it should remove the entry with remove_proc_entry()

dmitrii
  • 188
  • 6