pf_open

The pf_open function opens an existing file.

FRESULT pf_open (
  const char* path  /* [IN] Pointer to the file neme */
);

Parameters

path
Pointer to a null-terminated string that specifies the file name to open.

Return Values

FR_OK (0)
The function succeeded.
FR_NO_FILE
Could not find the file or path.
FR_DISK_ERR
The function failed due to a hard error in the disk function, a wrong FAT structure or an internal error.
FR_NOT_ENABLED
The volume has not been mounted.

Description

The file must be opend prior to use pf_read() and pf_lseek() function. The open file is valid until next open.

Example

int main (void)
{
    FATFS fs;          /* Work area (file system object) for the volume */
    BYTE buff[16];     /* File read buffer */
    UINT br;           /* File read count */
    FRESULT res;       /* Petit FatFs function common result code */


    /* Mount the volume */
    pf_mount(&fs);
    if (res) die(res);

    /* Open a file */
    res = pf_open("srcfile.dat");
    if (res) die(res);

    /* Read data to the memory */
    res = pf_read(buff, 16, &br);    /* Read data to the buff[] */
    if (res) die(res);               /* Check error */
    if (br != 16) die(255);          /* Check EOF */

    ....

    /* Forward data to the outgoing stream */
    do
        res = pf_read(0, 512, &br);  /* Send data to the stream */
    while (res || br != 512);        /* Break on error or eof */

    ....

}

QuickInfo

Always available.

References

pf_read, FATFS

Return