4

As far as I know:

  • One driver can be related to one or more "devices".

  • Files under /dev files represent these devices. Driver has major number and each device also has a minor number so (major, minor) identifies one device.

  • /proc/devices also lists the devices.

If what I know is true then:

Why /dev and /proc/devices have totally different outputs? In dev there is device name, major number and minor number. And in /proc/devices there is major number and device name but not minor number. Why these two lists show totally different outputs even for the same major number?

For example, look at this line in ls -l /dev

crw------- 1 root root     10, 235 Sep 19 21:40 autofs

It's character device with major number 10 and minor number 235. Device name is autofs.

Now I check the entry with the same major number in /proc/devices:

10 misc

As you see device name is totally different and there is no minor number (how this identifies device only by major number?).

Seems like some terminology is mixed but I couldn't solve this.

2
  • I’m not particularly familiar with /proc/devices, but it looks like it’s just poorly named — it should be called /proc/drivers, because, as you seem to have figured out, it seems to have just one line per major device number (with some exceptions).  I don’t know why autofs is categorized as misc, but I suspect that you’re exaggerating when you say “/dev and /proc/devices have totally different outputs”.  Don’t you see correspondences for things like tty and sd?  And, hint:  there once was a Unix device called /dev/mem, which no longer exists, but /dev/null is related to it. Sep 23, 2017 at 18:17
  • If they are really module names, why the output is different from lsmod then? Sep 23, 2017 at 20:03

1 Answer 1

2

Kernel modules ("drivers", if you like) can register block or character devices (in the traditional unix sense, "device" is a word with many meanings) in the kernel, using a routine like register_blkdev together with a string that is supposed to identify the device. It's possible to use any string for that purpose, and these strings show up in the /proc/devices file (which is just a textual representation of this kernel table).

On the other hand, in modern Linux systems, files in /dev are created by udev following a number of complicated rules. These files are supposed to represent ways for the userspace to interact with the kernel, via reads, writes and ioctls, which works because they are "special" files with a major and minor device number, so accesses to these files get translated into kernel calls (roughly speaking).

Those two and their structure are totally unrelated. The only connection is that the major device number of such a special file is looked up whenever such a file is accessed, and used to find the module that registered it. The string under which it was registered is totally irrelevant. The name under which a file appears is also totally irrelevant, as long as the user knows the name. Nothing prevents you from calling your disks /dev/this-disk and /dev/that-disk instead of /dev/sda and /dev/sdb if you feel the urge to do so, and change the udev rules.

But of course people like to make things simple, which is why the strings that are used to register devices are often the same or at least similar to the default names under which they show up in /dev. But that's the only connection.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .