Share via


MyFSD_ReadFile (Windows Embedded CE 6.0)

1/6/2010

This function reads data from a file, starting at the position indicated by the file pointer. After the read operation has completed, the file pointer is adjusted by the number of bytes read. The application does not call this function directly. Instead, it uses the corresponding standard Win32 ReadFile function. File System Disk Manager (FSDMGR) determines the file system type and calls the MyFSD_ReadFile implementation of the function.

Syntax

BOOL MyFSD_ReadFile( 
  PFILE pFile, 
  PVOID pBuffer, 
  DWORD cbRead, 
  PDWORD pcbRead, 
  OVERLAPPED* pOverlapped
); 

Parameters

  • pFile
    [in] Pointer to the value that a file system driver (FSD) passes to the FSDMGR_CreateFileHandle function when creating the file handle.
  • pBuffer
    [out] Pointer to the buffer that receives the data read from the file.
  • cbRead
    [in] Number of bytes to be read from the file.
  • pcbRead
    [out] Pointer to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking. This parameter cannot be set to NULL.
  • pOverlapped
    [in] Unsupported. Set to NULL.

Return Value

ReadFile returns when the specified number of bytes has been read or an error occurs.

Nonzero indicates success. If the return value is nonzero and the number of bytes read is zero, the file pointer was beyond the current end of the file at the time of the read operation.

Zero indicates failure. To get extended error information, call GetLastError.

Remarks

Asynchronous read operations on files are not supported.

An FSD exports this function if it supports ReadFile. All FSD functions can be called on re-entry. Therefore, take this into account when developing an FSD.

FSDMGR is a DLL that manages all OS interaction with installable files systems. Each installable file system requires an FSD, which is a DLL that supports an installable file system. The name of the DLL and the names of its functions start with the name of the associated installable file system. For example, if the name of file system is MyFSD, its DLL is MyFSD.dll, and its exported functions are prefaced with MyFSD_*.

FSDMGR provides services to FSDs. The FSDMGR_RegisterVolume, the FSDMGR_CreateFileHandle, and the FSDMGR_CreateSearchHandle functions record a DWORD of volume-specific data that an FSD associates with a volume. This volume-specific data is passed as the first parameter of these three functions.

Applications that access an installable file system use standard Win32 functions. For example, when an application creates a folder on a device that contains an installable file system, it calls the CreateDirectory function. FSDMGR recognizes that the path is to a device containing an installable file system and calls the appropriate function, which for a FAT file system is FATFSD_CreateDirectoryW. That is, the application calls CreateDirectory, causing FSDMGR to call FATFSD_CreateDirectoryW.

If part of the file is locked by another process and the read operation overlaps the locked portion, this function fails.

You must meet the following requirements when working with files opened with FILE_FLAG_NO_BUFFERING:

  • File access must begin at byte offsets within the file that are integer multiples of the volume's sector size. To determine a volume's sector size, call the GetDiskFreeSpaceEx function.
  • File access must be for numbers of bytes that are integer multiples of the volume's sector size. For example, if the sector size is 512 bytes, an application can request reads and writes of 512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes.
  • Buffer addresses for read and write operations must be sector-aligned on addresses in memory that are integer multiples of the volume's sector size. One way to sector align buffers is to use the VirtualAlloc function to allocate the buffers. This function allocates memory that is aligned on addresses that are integer multiples of the system's page size. Because both page and volume sector sizes are powers of 2, memory aligned by multiples of the system's page size is also aligned by multiples of the volume's sector size.

Accessing the input buffer while a read operation is using the buffer can lead to data corruption in the buffer. Applications must not read from, write to, reallocate, or free the input buffer that a read operation is using until the read operation completes.

When reading from a communications device, the behavior of ReadFile is governed by the current communication time-outs set with the SetCommTimeouts function and retrieved with the GetCommTimeouts function. Unpredictable results can occur if you fail to set the time-out values. For more information about communication time-outs, see COMMTIMEOUTS.

When a synchronous read operation reaches the end of a file, ReadFile returns TRUE and sets *lpNumberOfBytesRead to zero. The following code example tests for the end of the file for a synchronous read operation.

// Attempt a synchronous read operation.
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL);
// Check for end of file.
if (bResult &&  nBytesRead == 0, )
{
   // The end of the file.
}

An asynchronous read operation can encounter the end of a file during the initiating call to ReadFile.

Requirements

Header fsdmgr.h
Library Fsdmgr.lib
Windows Embedded CE Windows CE 2.10 and later

See Also

Reference

MyFSD Functions
CreateDirectory
FSDMGR_CreateFileHandle
FSDMGR_CreateSearchHandle
FSDMGR_RegisterVolume
GetDiskFreeSpaceEx
MyFSD_CreateFileW
MyFSD_WriteFile
ReadFile

Other Resources

GetCommTimeouts
SetCommTimeouts
VirtualAlloc
COMMTIMEOUTS