LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Distributions (https://www.linuxquestions.org/questions/linux-distributions-5/)
-   -   Creation of device node after USB insertion (https://www.linuxquestions.org/questions/linux-distributions-5/creation-of-device-node-after-usb-insertion-748738/)

paldebojyoti 08-19-2009 09:46 AM

Creation of device node after USB insertion
 
Hi,

When a USB device is inserted into a linux system a device node is created in /deb. I need to know the following information:
1) Who creates this node, is it USBcore?
2) Why it takes 4-5 seconds to be created?
3) Is there any other location apart from /dev where the device node corresponding to the same USB device is created?
Thanks in advance.

Regards,
Debojyoti

ilikejam 08-19-2009 11:14 AM

Hi.

1) All the /dev entries in recent-ish Linux systems are handled by 'udev'. This is a userland daemon that the kernel notifies every time there's a hardware change. It creates the appropriate node in /dev according to some built in rules, and the rules in /etc/udev/rules.d
2) Some (all?) USB devices take a few seconds to 'settle' before they are probed. Some devices also require firmware which has to be uploaded to the device before it'll work, which may take a couple of seconds.
3) Nope, not as far as I can see. There's nothing stopping you creating your own device node wherever you like, with the right major and minor numbers, though. 'mknod' is the command.

Dave

paldebojyoti 08-19-2009 11:54 PM

Hi Dave,

Thanks a lot for your information. It really helpful. I do have some queries:
1) If UDEV creates the device node, then if I change the udev rule then I hope this device node will not be created.
2) In Windows, file system has been created instantly after USB device insertion, but in Linux it takes bit longer time, is there any other mechanism to create the device node faster?
3) Can I stop UDEV from creating the device node, instead my application will create the device node as I have seen that SYSFS contains all the information regarding a USB device?

Regards,
Deb

ilikejam 08-20-2009 05:14 AM

Hi.

2 questions:
Is there a particular reason you need devices to be available very quickly after attachment?
How are you measuring the time it takes between insertion and the device being available?

If you /really/ want to you can abandon udev and use the old static /dev directory. You'd have to create all the device nodes in /dev manually, and stop the udev daemon from starting. There might be some kernel reconfiguration required too.

Dave

jschiwal 08-20-2009 05:28 AM

For the third question of your original post, there are other device nodes created. Look in /dev/disk/by-path and /dev/disk/by-id. These are also created by udev. You can have entries in /etc/fstab files that allow you to mount filesystems by UUID or LABEL. This allows you to use particular options like uid,gid,fmask & dmask based on the filesystem and not the mode. Using the same computer, this could allow one user to have exclusive access to a pen drive. The permissions and ownership are determined (for vfat & ntfs) in the mount command. Another user may be able to mount it but can be denied read or write access, depending on the option values given.

Also look at PolicyKit. You can have rules that allow mounting of removable media, restrict it to the user of an active session, or deny mounting removable media all together.

paldebojyoti 08-20-2009 05:34 AM

Hi Dave,

Yes I need to get the device node should come up very fast. If UDEV will take long then my application will create separate device node, as my application will get the major & minor number form the sysfs.
When a device is inserted, an entry in usbfs has immediately created, also all the USB related information is updated in SYSFS immediately, but the device node is not created that fast, it takes almost 4-5 seconds.
If my application can create the device node apart from the device node created by UDEV, then I don't need to remove the UDEV.

Regards,
Deb

paldebojyoti 08-20-2009 06:01 AM

Hi jschiwal,

Yes the entries are created in /dev/disk/by-id and /dev/disk/by-path, but these two are not the separate device nodes, these are the soft links to the device node created in /dev (i.e. sdb, sdc) by UDEV.

Regards,
Deb


All times are GMT -5. The time now is 08:10 AM.