CopyFile() equivalent in QNX


I want to copy multiple files (ELF executables) from one location to another from a C/C++ Code.

In QNX, I could use "system( "cp " ). But there is a problem with this approach.

I copy files from USB device to a Flash Disk. Now sometimes, when the USB Device is not available, the thread executing the “cp” command becomes REPLY-blocked on the devb-umass driver.

I used “timer_timeout” API to set a timeout on the REPLY-blocked state but it didn’t worked, system call still waits indefinitely. I think that there must be many kernel calls getting executed in system() API.

Suggest some good alternatives.


Why don’t you just test to make sure the USB drive is inserted before you do the system(cp) command?

You obviously must know the mount point for the USB drive to issue the cp command. So just test to see if it exists. If not, then don’t attempt the cp command.


opendir, readdir for scanning directory. For files open, read, write , lseek. and a litte big of recursivity will do the job. Timeout on these should work ok.


Checking that the USB drive is inserted before executing the system(cp) command, will certainly help.
However, there will be a chance that after checking that the USB drive is inserted and starting the copy operation, the USB drive is removed accidentally before the copy operation is complete (I don;t know thats a valid scenario to test but the application should be prepared for that), it would still be stuck.

What say?


Thanks mario. Yeah that is a good alternative. I’ll try coding that. But, in the meantime if you have a sample code for this or a link where I could get this…it would be a great help…

Recently I was surprised at how easy it is to passively monitor insertion and removal of a USB device.
You could have a thread monitoring and if you are unfortunate enough to have the device removed while you are blocked, you could handle the situation gracefully.