Thread: Udev & Interacting With Devices

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    24

    Udev & Interacting With Devices

    Hi,

    I'm trying to work out how to work with udev in my programs. I understand that this works in conjunction with sysfs mounting devices in the tree dynamically.

    More specifically, I want my program to find a USB Memory stick and then read/write data to it but I cannot find out any goo tutorials on how to do it except this brief intro here :

    Tutorial: How to use libudev and Sysfs in Linux

    And the udev API pages are not particularly helpful for a beginner.

    1) What particularly puzzles me is how do I know what class a particular device is? e.g. what class is a memory stick? And where can I find out how other devices are classed?

    2) Can I used the output from dmesg to determine what class my device is and how can I do that?

    3) Are there any good tutorials or books on this particular subject?

    Codebugs

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    What are you attempting to do?

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    24
    Quote Originally Posted by Kennedy View Post
    What are you attempting to do?
    Specifically, what I am intending to do is have my program search for a USB memory stick. I want my program to search for the memory stick and then query linux for its mount point or where it is in the /dev/ tree.

    This led me to how I can query Linux for any device attached and where it is mounted in /dev

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Bare bones Linux does not auto-mount the device. What support util are you using to create the mount point and mount the stick? If you are using a bare bones kernel, you can watch the hotplug subsystem (though, hotplug is no longer used, the subsystem is still useful to you). Otherwise, you can watch sysfs to determine what is mounted. /etc/mtab is also helpful for you (this is a symlink to /proc/mtab).

    I've done this before for an embedded system, but to help you, I need more information.

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    24
    Quote Originally Posted by Kennedy View Post
    Bare bones Linux does not auto-mount the device. What support util are you using to create the mount point and mount the stick? If you are using a bare bones kernel, you can watch the hotplug subsystem (though, hotplug is no longer used, the subsystem is still useful to you). Otherwise, you can watch sysfs to determine what is mounted. /etc/mtab is also helpful for you (this is a symlink to /proc/mtab).

    I've done this before for an embedded system, but to help you, I need more information.
    I won't be working with a bare-bones Linux but one(s) with udev installed which I understand automatically creates nodes in the /dev directory. Unfortunately the link I gave in my original post while useful, only explains briefly how to use the udev API and the Udev API itself at kernel.org gives only the briefest of details.

    So really my question is how do I use Udev in my programs?

    Although I have a specific case where I want my program to be notified/discover a USB memory stick attached, I'd also like to know how to use udev for ANY kind of device.

    Say, for example, I have another type of device (not a memory stick). From my understanding of Udev so far I can ask for what kind of class of device is attached and where it is mounted. But how do I know what class of device Udev assigns it? Where are the classes documented?

    As it happens I am using a single-board-computer but this doesn't really affect the information I would like.

    Udev looks as though it would make life a lot easier .... if I could only find some decent documentation for it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Flash on Apple Devices Discussion
    By DavidP in forum General Discussions
    Replies: 58
    Last Post: 05-05-2010, 09:20 AM
  2. Design suggestions: interacting with game items
    By anon in forum C++ Programming
    Replies: 3
    Last Post: 09-19-2008, 08:03 AM
  3. Lost devices in Direct3D
    By VirtualAce in forum Game Programming
    Replies: 10
    Last Post: 12-09-2006, 07:41 AM
  4. Interacting with other programs with readline
    By Provost in forum C Programming
    Replies: 1
    Last Post: 08-13-2004, 06:24 AM
  5. Add user without interacting.
    By zahid in forum Linux Programming
    Replies: 3
    Last Post: 12-21-2002, 11:36 PM