Delta Tau Forums

Full Version: Checking for USB drive from code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Steve,

Try this, it's working on my CK3E.

Code:
char bUSB_Ready = 0;
FILE *f = popen("mount | grep /media/disk-0", "r");
if (NULL != f)
{
       /* test if something has been outputed by
       the command */
       if (EOF == fgetc(f)) {}
       else
       {
             bUSB_Ready = 1;
       }        
       /* close the command file */
       pclose(f);        
}
Hi Eric

Where can I get some documents or examples related to the logging on USB in C-app?
We have an example in this App note.
http://forums.deltatau.com/filedepot/dow...0Media.pdf

Look at the "Saving Files on External Flash Devices" section starting on page 3.

At one point the app note instructs you to connect over telnet by typing a command windows command. I would suggest connecting with SSH through putty instead. Telnet may be disabled on newer form factors with the expectation that SSH will be used instead.