Pages

Wednesday 1 August 2012

What happens when a device is plugged in?


What happens when a device is plugged in?

Many times device Plug-in related questions comes in our mind . These questions specially arises when we face challenges to block certain device on the server , or block certain devices for certain users . Let me explain my understanding on this topic.

For newly Plugged-in device , given below steps take place


1. Kernel detect the Plug-in device and export device status to sysfs. You can view exported state via mounted /sys virtual filesystem.


2. Kernel then notify udev about this event via netlink socket.


3. udev process the user-configurable rules (present in /etc/udev/rules.d) and creates device file in /dev.


4. After creating device node , udev notify hald about the event via the socket.


5. HAL probes the device for information.


6. The device object structure populates with the probed information.


7. HAL broadcast Plug-in event.


8. A user-space application then process the information.


In this complete process , We can add our custom hook in udev rules . For example suppose you want to notify administrator via mail about any usb storage device insertion on the system, we can do that by udev rules. In coming posts ,I will explain about writing udev rules.

No comments:

Post a Comment

Twitter Bird Gadget