I have a embedded device running Linux Angstrom. I need to detect a USB drive. So when a USB drive is inserted, I need to automatically copy data from the USB to internal memory of the embedded device.
To detect the USB, I am using below code:
DIR* dir = opendir("/media/sda1/");
if (dir)
{
printf("USB detected\n");
//rest of the code
//to copy data from the USB
}
This works normally but sometimes after copying is done, I remove the USB but the name of the mount point (sda1) remains there. So after removing the USB, it again try to copy the data (because sda1 is there in media) and then shows error because physical no USB is connected. What is the best way to detect if USB is connected and if connected then after copying how to eject it properly. Here I cannot use udisks
because its not available for the linux angstrom I am using for this embedded device. So only generic linux commands will work.
Any help. Thanks
umount /media/sda1
but sometimes it still remains there. Thats why I am looking for another approach. – S Andrewudev
command is not available.! – S Andrewmount | grep sda
command. – Mathieu