Manuals
General operations
Block device operations
File system operations
File operations
Directory operations
Direct Block access
Block driver (mandatory)
Block driver (optional)
ECF_ReadFile
ECF_ReadFile reads data from an open file.
ECF_ErrorCode ECF_ReadFile(
struct ECF_FileHandle *pFileHandle,
uint8_t *pData,
uint32_t bytesToRead,
uint32_t *pBytesRead
);
struct ECF_FileHandle *pFileHandle,
uint8_t *pData,
uint32_t bytesToRead,
uint32_t *pBytesRead
);
Parameters
pFileHandle
A pointer to an open file handle.
pData
A pointer to a buffer big enough to hold the read data.
bytesToRead
The number of bytes to read.
pBytesRead
If not NULL, the uint32_t will be set to the number of bytes actually read. Also see the Remarks section.
Return value
Returns one of the EcFAT error codes (ECFERR_SUCCESS on success)
Remarks
If pBytesRead is NULL, ECF_ReadFile will attempt to read exactly the number of bytes specified and return ECFERR_ENDOFFILE if there is not enough data available in the file. This is the behaviour of EcFAT 2.2 and previous.
If pBytesRead is not NULL, ECF_ReadFile will attempt to read the number of bytes specified by bytesToRead. If there aren't enough data available ECFERR_SUCCESS will still be returned. pBytesRead will be set to the actual number of bytes read. If there are no bytes available to read ECFERR_ENDOFFILE will be returned.
Example Code
#include <EcFAT/EcFAT.h>
#define COPYFILE_BUFFERSIZE 4096
void CopyFile(const char *sourceFileName, const char *destinationFileName)
{
struct ECF_FileHandle sourceFileHandle;
struct ECF_FileHandle destinationFileHandle;
uint32_t bytesRead;
uint8_t abCopyBuffer[COPYFILE_BUFFERSIZE];
// Error checking omitted
ECF_OpenFile(&sourceFileHandle, sourceFileName, ECF_MODE_READ);
ECF_OpenFile(&destinationFileHandle, destinationFileName, ECF_MODE_READ_WRITE);
while(ECFERR_SUCCESS ==
ECF_ReadFile(&sourceFileHandle, abCopyBuffer, COPYFILE_BUFFERSIZE, &bytesRead))
{
ECF_WriteFile(&destinationFileHandle, abCopyBuffer, bytesRead);
}
ECF_CloseFile(&destinationFileHandle);
ECF_CloseFile(&sourceFileHandle);
}
#define COPYFILE_BUFFERSIZE 4096
void CopyFile(const char *sourceFileName, const char *destinationFileName)
{
struct ECF_FileHandle sourceFileHandle;
struct ECF_FileHandle destinationFileHandle;
uint32_t bytesRead;
uint8_t abCopyBuffer[COPYFILE_BUFFERSIZE];
// Error checking omitted
ECF_OpenFile(&sourceFileHandle, sourceFileName, ECF_MODE_READ);
ECF_OpenFile(&destinationFileHandle, destinationFileName, ECF_MODE_READ_WRITE);
while(ECFERR_SUCCESS ==
ECF_ReadFile(&sourceFileHandle, abCopyBuffer, COPYFILE_BUFFERSIZE, &bytesRead))
{
ECF_WriteFile(&destinationFileHandle, abCopyBuffer, bytesRead);
}
ECF_CloseFile(&destinationFileHandle);
ECF_CloseFile(&sourceFileHandle);
}
See also