LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2008, 12:49 PM   #1
Sharon Olshanksy
LQ Newbie
 
Registered: Nov 2008
Posts: 1

Rep: Reputation: 0
How to know where a flash disk that was discovered, is mounted(from C++ application)?


Hello, I have a question:

How to know where a flash disk that was discovered, is mounted(from C++ application)?

I write a project in C++/Linux (Debian), in which I have to identify when USB flash disk is insterted/removed, and when the flash disk is inserted,I have to read the files in the flash drive and copy them.

I found many ways to identify that the flash disk is insterted (I'm going to use usblib for that), but I haven't found a way to link between the data I get on the drive, to it's mapping in the file-system.

thanks,
Sharon
 
Old 11-02-2008, 01:06 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Sharon Olshanksy View Post
Hello, I have a question:

How to know where a flash disk that was discovered, is mounted(from C++ application)?

I write a project in C++/Linux (Debian), in which I have to identify when USB flash disk is insterted/removed, and when the flash disk is inserted,I have to read the files in the flash drive and copy them.

I found many ways to identify that the flash disk is insterted (I'm going to use usblib for that), but I haven't found a way to link between the data I get on the drive, to it's mapping in the file-system.

thanks,
Sharon
What about parsing stdout of 'mount' command ?
 
Old 11-02-2008, 01:34 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Actually, it's even simpler; from "man mount":

/etc/mtab table of mounted file systems
.
 
Old 11-02-2008, 04:16 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Neither of those are really reliable since neither will tell you if 1) something was mounted from chroot, 2) something was mounted when / was read-only, 3) something was mounted with -n. Really the only reliable way to check for mounts is /proc/mounts, but some of the /proc files won't give you a size, so you just have to read linearly until they're empty.
ta0kira

PS That's the Linux-only solution; Sergei's is more portable.

Last edited by ta0kira; 11-02-2008 at 04:18 PM.
 
Old 11-02-2008, 11:45 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ta0kira View Post
Neither of those are really reliable since neither will tell you if 1) something was mounted from chroot, 2) something was mounted when / was read-only, 3) something was mounted with -n. Really the only reliable way to check for mounts is /proc/mounts, but some of the /proc files won't give you a size, so you just have to read linearly until they're empty.
ta0kira

PS That's the Linux-only solution; Sergei's is more portable.
/etc/mtab and/or 'mount' can be good starting points; the next logical step would be to look into 'mount' source and see which library functions are used to report mounted media.

To make it portable, if possible, one would have to look into various 'mount' flavors (Linux, *BSD) - maybe the both use just POSIX-compliant functions.

OTOH, if /etc/mtab is present on all UNIXes and has the same format, maybe it's not worth bothering with 'mount' source code and library functions.

I hope the OP has enough inputs for now :-).
 
  


Reply

Tags
c++, debian, driver, usb



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB Flash is not mounted mesh2005 Linux - Hardware 1 11-29-2006 11:08 AM
copy a file to the flash disk and extract it from the flash disk indu.a Linux - Kernel 2 11-15-2006 03:22 AM
how come usb flash drive doesn't get auto mounted? darkhatter Fedora 5 02-26-2006 08:04 PM
Format a Compact Flash Drive While Mounted sadarax Linux - General 2 12-15-2005 03:26 AM
specific USB Flash Disk not being mounted on Red hat 9 on kernel 2.4.20 irfanhab Linux - Hardware 3 01-30-2004 04:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration