In the function scan_files(), couple of structures have been declared. FRESULT stores the result of an action. FILINFO is a structure that contains the information related to the file. And DIR contain information about a directory.
The _USE_LFN option switches to the LNF support.
#if _USE_LFN
char c_lfn[_MAX_LFN + 1];
fno.lfname = c_lfn;
fno.lfsize = sizeof(c_lfn);
#endif
To open the directory of a given path
res = f_opendir(&dir, path);
If it is a valid directory, we read the contents in it. res stores FR_OK if directory is empty.
res = f_readdir(&dir, &fno);
In the above res stores FR_OK when all the contents of the directory have been read or when the directory is empty. The content read is stored in fno.
if(fno.fattrib & AM_DIR)
checks whether the content is a directory or not.
In the run_fatfs_test() function, we use
#if _FS_TINY == 0
When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system object instead of the sector buffer in the individual file object for file data transfer. This reduces memory consumption 512 bytes each file object.
Two static objects have been used - FATFS and FIL.
The root_directory and file_name have been initialized by '0' + disk_dev_num where disk_dev_num is the logical unit number.
res = f_mount(disk_dev_num, &fs);
is used to mount the logical unit.
res = FR_NO_FILESYSTEM;
The result means that there is no valid FAT volume.
res = f_open(&file_object, (char const *)file_name,
FA_CREATE_ALWAYS | FA_WRITE);
is used to open a file. If file does not exist, a new one is created.
res = f_write(&file_object, data_buffer, DATA_SIZE,
&byte_written);
is used to write into the file. The number of bytes written into the file is stored in byte_written.
res = f_read(&file_object, data_buffer, DATA_SIZE, &byte_read);
is used to read from the file. The number of bytes to be read is specified in byte_read.
res = f_close(&file_object);
is used to close the file.