Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, I am developing a sample application to detect a memory card when it is being inserted. Presently I am able to detect a device when it is inserted. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    4

    Detecting memory card


    Hi all,
    I am developing a sample application to detect a memory card when it is being inserted. Presently I am able to detect a device when it is inserted. But I am not able to find a way to filter out whether the connected device is memory card or not. I am using kubuntu 8.04 . Can any one help me in this matter? Is it possible to do this using libhal APIs ? If it is not possible is there any other way to do this? Any help in this will be really great. If any one can provide a sample code it will be really helpfull .

    Thanks in advance..

  2. #2
    Just Joined!
    Join Date
    Apr 2009
    Posts
    33
    Quote Originally Posted by pratheeshp View Post
    Hi all,
    I am developing a sample application to detect a memory card when it is being inserted. Presently I am able to detect a device when it is inserted. But I am not able to find a way to filter out whether the connected device is memory card or not. I am using kubuntu 8.04 . Can any one help me in this matter? Is it possible to do this using libhal APIs ? If it is not possible is there any other way to do this? Any help in this will be really great. If any one can provide a sample code it will be really helpfull .

    Thanks in advance..
    I suppose you refer to that kind of cards you have on digital cameras for instance

    those used to be seen the same way as usb sticks (e.g., /dev/sda, /dev/sdb, ...) but
    I noticed this has changed recently
    For instance on my slackware12.2 my inserted (sd) memory card could be accessed
    via /dev/mmcblk0p1
    What I usually do, for instance when I'm on someone else machine and I'm not sure
    of their device names (does it have an ide hd or sata or scsi, etc.) I type in
    # cat /proc/partitions

    for instance on my machine, this displays

    major minor #blocks name
    8 0 .......... sda
    .......
    8 9 ......... sda9

    /dev/sda is my internal hard drive
    whenever I insert a usb external drive (hard disk, flash disk)
    entries like
    ...................................... sdb
    ...................................... sdb1
    .............
    appear

    So I suppose I could do this to view new devices (after I inserted them)
    cat /proc/partitions | grep -v 'sda' | grep -v '^major' | sed 's?^[ \t0-9]*??'

    so perhaps you could write a script that does something similar to the command above
    and execute it after waiting a few seconds after you inserted your device

  3. #3
    Just Joined!
    Join Date
    Jun 2009
    Posts
    4
    Hi vonbiber,
    Thanx for the replay. But I am looking for something else. What I need is a programmatic way (a small C applocation) to detect when a memory card (say SD mmc) is getting inserted and to get the mount path also.I need to run the process as daemon which will help me to do this.
    Can any one help in this. Any sample code or proper API list will be really helpful.
    Thanx

  4. #4
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,126
    What you are talking about is usually handled by udev. You can either write something that will talk to udev or you can have a look at the code of udev itself for ideas.

    udev

  5. #5
    Just Joined!
    Join Date
    Jun 2009
    Posts
    4
    Hi Thax for the tip
    but what I really want to know is how an application can communicate with udev. libhal API's will help me in doing that through hald??? What is a proper way to do it?
    If you can help me it will be really nice and I can wind up the small app which I am digging around for a number of days.............

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •