LinuxQuestions.org
Review your favorite Linux distribution.
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 12-14-2020, 10:15 PM   #1
Nishanth1829
LQ Newbie
 
Registered: Dec 2020
Posts: 3

Rep: Reputation: Disabled
Unhappy How to know the existence of pendrive or memory card in embedded Linux?


Hi all,
I am using an Embedded SOM and application is running on GTK+. In my app, I need to show pendrive and memory card icons based on their existence. That is if sd card is inserted, the logo should be shown in my app and vice versa if removed in between.I have did this by using statfs() for every 5 seconds in C as I found that the pendrive is always mounted as /media/sda1 and memory card is always mounted as /media/mmcblk1p1. But this logic does not work perfectly some times and shows the icons wrongly. Is my way correct ? If not kindly guide me how to detect pendrive and memory card existence programmatically in polling method.

Thanks and regards,
Nishanth Kumar
 
Old 12-15-2020, 07:27 AM   #2
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
You could look at libudev. Here's and example: https://gavv.github.io/articles/libudev-usb/
 
Old 12-22-2020, 11:11 PM   #3
Nishanth1829
LQ Newbie
 
Registered: Dec 2020
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi SoftSprocket,
Thank you very much for you reply. Now I can list the pendrives and memory card properly. But when I insert a pendrive first time, It is mounting as /dev/sda1 and after some read and write into the directory /dev/sda1, then when removed and mount again, the pendrive is mounted as /dev/sdb1. As the directory changes, I am not able code the directory in my C Code. How to mount the pendrive always under /dev/sda1?

Thank you very much for your time.

Regards,
Nishanth
 
Old 12-23-2020, 08:02 AM   #4
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
Have a look at this: https://www.linuxquestions.org/quest...-point-511917/
 
Old 12-23-2020, 12:29 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
I know that some file managers use UDisks for this.
 
  


Reply



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
LXer: Copyright Industry Rhetoric Ignores the Existence of Linux and Wikipedia LXer Syndicated Linux News 1 01-10-2016 06:52 PM
How to install and configure grub on pendrive while os' are on the same pendrive? CeremCem DamnSmallLinux 0 11-07-2006 11:10 AM
check for existence of file j-me Linux - Newbie 5 07-29-2003 07:58 AM

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

All times are GMT -5. The time now is 04:26 AM.

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