The pf_open function opens an existing file.
FRESULT pf_open ( const char* FileName /* Pointer to the file neme */ );
The file must be opend prior to use pf_read and pf_lseek function. The open file is valid until next open.
void 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 .... // Unregister the work area before discard it f_mount(NULL); }
Always available.