ReadFile returns "ACCESS_DENIED" error message during resume (811693)



The information in this article applies to:

  • Microsoft Pocket PC 2002

SYMPTOMS

Applications that are reading file allocation table (FAT) based storage devices at the time of a resume may receive the following error message from the file system:
ERROR_ACCESS_DENIED (0x00000005)
This occurs although the file has appropriate sharing and access permission.

Examples of storage media that frequently use the FAT file system on Pocket PC 2002 are the PCMCIA PC Card ATA, the Compact Flash (CF) Storage Card, and the Secure Digital (SD) Memory Card.

This behavior is observed when using Pocket PC 2002 Adaptation Kit Update 4 (AKU4) and later.

CAUSE

The error code is an indication that the device is not ready to access. Typically, this problem occurs because drivers for FAT-based removable storage devices are unloaded and reloaded on resume, which requires a short period of time to be completed. If a read access occurs during this period, the error code is returned by the file system. A fix was introduced in AKU4 to prevent the device from hanging when the device is accessed immediately after resume, and the new expected behavior is to return this error code.

RESOLUTION

Applications can handle this situation by detecting the specific error code while reading a storage card file, and then retrying for a short period until the device is ready. The following is an example C code fragment that demonstrates this concept:
while ( !WriteFile( hFile, achBuffer, dwBytesRequested, &dwBytesReturned, 0 ) && 
        ( ERROR_ACCESS_DENIED == GetLastError() ) )
{
    // Access Denied: Maybe the file system is not ready yet.
    tries++;
    if ( tries > 4 )
        break;
    Sleep(500);
}
// It has been a few seconds.  The file cannot be accessed.

You can use the same approach for other programming languages. For applications that access the storage card through middleware libraries that do not provide direct access to the file system, you may have to implement transactional or block verification methods to get reliable data transfer across a suspend resume.

STATUS

This behavior is by design.

MORE INFORMATION

Some Microsoft applications do not retry when the file system is not ready, and will return an error message that indicates that the read has failed. File Explorer is one such application. When this problem occurs in File Explorer, you receive the following error message:
Cannot copy 'FileName': Access is Denied. Make sure the disk is not full or write-protected and the file is not currently in use.

Modification Type:MajorLast Reviewed:7/15/2005
Keywords:kberrmsg kbprb KB811693