Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking for USB drive from code
#1
Hello,
I have an application where we are logging data to a text file on a USB drive at /media/disk-0/

This is working, the file is generated correctly. However, I need to know if the USB drive is connected or not. If I try to write the file when there is no drive I get some watchdog issues in the background.

So, can anyone tell me how to detect this drive? I don't care if it is through PMAC script or C code, either will do. I don't need millisecond frequency checking either, I can schedule it every second or so.

I have tried stat() and it seems to always say the directory is present even when the drive is removed. so this doesn't work:

struct stat st;
if(stat("/media/disk-0/",&st) == 0)
{
bUSB_Ready = 1;
}
else
{
bUSB_Ready = 0;
}

I've also tried adding a directory in the root of the USB drive, I can tell the customer they need that for it to work (so it would be /media/disk-0/LOGS or whatever). When I try to detect that I never see the drive, even when it is plugged in.

Ideas welcome!

Thanks, Steve
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)