PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Strange case: file system access denided after power off,on

Hello,

I'm getting strange error when loading my resources. I do power off when loading my resources then power on. After that I have GetLastError==5 (Access Denided) error when trying to read from opened file or open a new one (I use fopen, fread). After some seconds error no longer presents. This error occures only when loading files from my storage card.

I think that WinCE doing some storage card initializations when power on, so I can't read my files on storage card for some time while it is intializing.
I saw this problem 3 or 4 years ago with an NEC MobilePro handheld PC. It is dependent on how the OEM implemented their drivers. When the device is powered on any removable storage is not yet mounted. Depending on the driver, there is a delay before the card is recognized and exposed to the OS. On the NEC MobilePro it was around a full 10 seconds. I also see this on a Casio BE-300, although it only takes 2 seconds or so to remount the CF card. The better drivers (the majority of devices) are smart enough to show the card immediately.

The only way to handle it is to add a retry into your file access routine. Instead of calling fopen call your own version of fopen that will try multiple times (Sleeping between each try) for up to 15 seconds or so. It is important to Sleep between tries because that frees up CPU time for the OS, which could actually allow it to remount the card faster. That is especially true if you have increased the process priority of your process above normal (which could be the reason the delay is happening at all). A smarter version of your custom fopen would be able to recognize when the device is powered on, and only apply the retry mechanism if it is within 30 seconds or so of a power on.

To possibly save you some digging, the technique I use to determine if the device has been powered off and on is to watch the game timer. If more than 30 seconds or so has elapsed since the last frame then I assume the device has been powered off and on. AFAIK the OS provides no simple method for an app to determine that the device has been powered on, without having to implement a serial port driver or some similar overly complex solution.

Dan East