How to know where a flash disk that was discovered, is mounted(from C++ application)?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.