1

I want to know how a device node is created when a hardware is connected to the system.

Information that I know:

When a piece of hardware is connected to the system, the device name is compared with the driver name, if it matches, then probe is called.

Info I wish to know:

At which point is the device node created and who is creating it? (In other words, I want to know where mknod is happening?)

This one thing is bugging my mind from so many months. Please tell me programatically where is this happening.

Community
  • 1
  • 1
Sandeep
  • 18,356
  • 16
  • 68
  • 108

1 Answers1

2

On most (but not all!) Linux systems this is handled by Udev.

It is notified of the new hardware through a netlink socket. It then creates the device node, based on its configuration.

Kristof Provost
  • 26,018
  • 2
  • 26
  • 28
  • Where is this particular code present inside the kernel code? Please direct me to the respective files. I will look it up myself – Sandeep Apr 20 '12 at 13:55
  • Have you read the link? The Udev code runs entirely in userspace. The netlink messages are of course triggered from the kernel, deeply tied to the kobject system. See lib/kobject_uevent.c for much of the relevant code. – Kristof Provost Apr 20 '12 at 13:58
  • Yes. I read it now. The linux file name is not written inside it. Thank you for the wonderful answer. I am going through the code. Once i understand it completely i will accept the answer. Thanks once again – Sandeep Apr 20 '12 at 14:11
  • One question. All this happens before calling probe or after calling probe? – Sandeep Apr 20 '12 at 14:19
  • It fits in with kobject so I'd guess when the kobject is created. – Kristof Provost Apr 20 '12 at 16:45
  • On modern kernels device nodes at `/dev` being managed by the kernel via `devtmpfs`. Kill all instances of `udevd`, insert/remove flash drive and take a look on `/dev` nodes list. – Ilya Matveychikov Apr 20 '12 at 18:06