Linux – Information about the device files: /dev

filesystemslinux

ls /dev 

command lists the device files.

How to know the associated drivers/major_numbers/minor_numbers with those device files?

Best Answer

ls -l /dev will give you the major and minor numbers, e.g.

crw-rw---- 1 root dialout 4, 64 Apr  4 07:54 /dev/ttyS0

has major number 4 and minor number 64.

Then you can look at /proc/devices to look up the major number. In this example we have a character device (c at the start of the line) with major number 4, and in /proc/modules we find

Character devices:
...
  4 tty
  4 ttyS

Allocation of minor numbers is device-dependent.

Some devices are driven from core kernel code (e.g. tty), whereas others are managed by loadable modules (e.g. rfcomm). You could try looking in /proc/modules for a matching module; alternatively look in /proc/kallsyms for the module name. You'll get lots of results, but the key thing to look for is the presence or absence of a string in square brackets. For example, grep tty /proc/kallsyms gives

0000000000000000 t tty_drivers_open
0000000000000000 t show_tty_range
0000000000000000 t show_tty_driver
...

whereas grep rfcomm /proc/kallsyms gievs

0000000000000000 t rfcomm_apply_pn  [rfcomm]
0000000000000000 t rfcomm_dlc_debugfs_open  [rfcomm]
0000000000000000 t rfcomm_dlc_debugfs_show  [rfcomm]

[rfcomm] indicates that the code is in the rfcomm module, whereas tty is in the kernel itself and not in a module, so nothing appears in square brackets.

This method is not definitive but should give you some idea as to where the controlling code lives.

Related Question