How to programmatically detect a mounted device

Apr 09, 2007 3 Replies

Hi,



I have a gumstix running linux version below.



# uname -r



2.6.11gum

It has a MMC slot which I use for collecting log files. My requirements is that if the MMC card is mounted, my application would archive log files to the MMC card. If the card is not mounted (user not inserted), the my application would not archive log files, so as to not write to the internal flash.



My question is: how can I programmatically detect whether or not a MMC card is mounted?



Thanks for any help.



P

| I have a gumstix running linux version below. | | # uname -r | 2.6.11gum | | It has a MMC slot which I use for collecting log files. My | requirements is that if the MMC card is mounted, my application would | archive log files to the MMC card. If the card is not mounted (user | not inserted), the my application would not archive log files, so as | to not write to the internal flash. | | My question is: how can I programmatically detect whether or not a MMC | card is mounted?

By scanning the contents of /proc/mounts (if you have /proc enabled and mounted).

|---------------------------------------/----------------------------------| | Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below | | first name lower case at ipal.net / spamtrap-2007-04-09-1445@ipal.net | |------------------------------------/-------------------------------------|

Yes, thank you. I do see the entry in the file after mounting the card.

Best, P

Here is a little /bin/sh routine that you probably might find useful, or can modify to suit...

is_reader() { test=$( cat /proc/scsi/usb-storage*/* 2> /dev/null | grep "Card Reader"; cat /proc/bus/usb/devices 2> /dev/null | grep Cnt=0[1-9] ) if [ "$test" = "" ]; then return 0 else return 1 fi }

TonyB

There are 10 types of people in this world, those that read binary and those who don't!

-- __ __ _ I N C.

formatting link
/ __|\\// __|| \ __ __ / snipped-for-privacy@sysdev.org \__ \ \/\__ \||)|/ O_)\/ / \/ System Tools / Utilities |___/ || ___/|_ /\___|\_/ WIntel / Linux Device Drivers

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required