# FILE

## Defines
#define | DEBUG_VERBOSE_LEVEL 1
#define | SECTOR_SIZE _MAX_SS
#define | TMP_BUFFER_SIZE _MAX_SS
## Functions
s32 | FILE_Init (u32 mode)
s32 | FILE_CheckSDCard (void)
s32 | FILE_UpdateFreeBytes (void)
u32 | FILE_VolumeSectorsPerCluster (void)
u32 | FILE_VolumeCluster2Sector (u32 cluster)
s32 | FILE_SDCardAvailable (void)
s32 | FILE_VolumeAvailable (void)
u32 | FILE_VolumeBytesFree (void)
u32 | FILE_VolumeBytesTotal (void)
char * | FILE_VolumeLabel (void)
s32 | FILE_ReadOpen (file_t *file, char *filepath)
s32 | FILE_ReadReOpen (file_t *file)
s32 | FILE_ReadClose (file_t *file)
s32 | FILE_ReadSeek (u32 offset)
u32 | FILE_ReadGetCurrentSize (void)
u32 | FILE_ReadGetCurrentPosition (void)
s32 | FILE_ReadBuffer (u8 *buffer, u32 len)
s32 | FILE_ReadBufferUnknownLen (u8 *buffer, u32 len)
s32 | FILE_ReadLine (u8 *buffer, u32 max_len)
s32 | FILE_ReadByte (u8 *byte)
s32 | FILE_ReadHWord (u16 *hword)
s32 | FILE_ReadWord (u32 *word)
s32 | FILE_WriteOpen (char *filepath, u8 create)
s32 | FILE_WriteClose (void)
s32 | FILE_WriteSeek (u32 offset)
u32 | FILE_WriteGetCurrentSize (void)
u32 | FILE_WriteGetCurrentPosition (void)
s32 | FILE_WriteBuffer (u8 *buffer, u32 len)
s32 | FILE_WriteByte (u8 byte)
s32 | FILE_WriteHWord (u16 hword)
s32 | FILE_WriteWord (u32 word)
s32 | FILE_Copy (char *src_file, char *dst_file)
s32 | FILE_MakeDir (char *path)
s32 | FILE_Remove (char *path)
s32 | FILE_FileExists (char *filepath)
s32 | FILE_DirExists (char *path)
s32 | FILE_GetDirs (char *path, char *dir_list, u8 num_of_items, u8 dir_offset)
s32 | FILE_GetFiles (char *path, char *ext_filter, char *file_list, u8 num_of_items, u8 file_offset)
s32 | FILE_FindNextFile (char *path, char *filename, char *ext_filter, char *next_filename)
s32 | FILE_FindPreviousFile (char *path, char *filename, char *ext_filter, char *prev_filename)
s32 | FILE_SendSyxDump (char *path, mios32_midi_port_t port, u32 ms_delay_between_dumps)
s32 | FILE_PrintSDCardInfos (void)
s32 | FILE_SendErrorMessage (s32 error_status)
s32 | FILE_BrowserHandler (mios32_midi_port_t port, char *command)
s32 | FILE_BrowserUploadCallback_Init (s32(*callback_upload)(char *filename))
## Variables
u32 | file_dfs_errno
u8 | file_copy_percentage

## Detailed Description

File access layer for FatFS

Frontend functions to read/write files.
Optimized for Memory Size and Speed!

For the whole application only single file handlers for read and write operations are available. They are shared globally to save memory (because each FatFs handler allocates more than 512 bytes to store the last read sector)

For read operations it is possible to re-open a file via a file_t reference so that no directory access is required to find the first sector of the file (again).

NOTE: before accessing the SD Card, the upper level function should synchronize with a SD Card semaphore! E.g. (defined in tasks.h in various projects): MUTEX_SDCARD_TAKE; // to take the semaphore MUTEX_SDCARD_GIVE; // to release the semaphore

## Define Documentation

#define DEBUG_VERBOSE_LEVEL 1

#define SECTOR_SIZE _MAX_SS

#define TMP_BUFFER_SIZE _MAX_SS

## Function Documentation

s32 FILE_BrowserHandler | ( | mios32_midi_port_t | port,
|  | char * | command |
| ) |  |  |

Handler for MIOS Studio Filebrowser accesses.
See $MIOS32_PATH/apps/controllers/midio128/src/terminal.c for usage example.

Here is the call graph for this function:

s32 FILE_BrowserUploadCallback_Init | ( | s32(*)(char *filename) | callback_upload | ) |

Installs the Browser Upload callback function which is executed whenever a file upload starts, and when it has been successfully finished.

Parameters:

  `[in]` | filename | if != NULL, upload has been started for the given file, if NULL the upload has been finished. This means: if the application should do anything with the uploaded file (e.g. auto-load), then it has to store the filename in a temporary variable!

s32 FILE_CheckSDCard | ( | void |  | ) |

This function should be called periodically to check the availability of the SD Card

Returns:
  < 0 on errors (error codes are documented in file.h)
  1 if SD card has been connected
  2 if SD card has been disconnected
  3 if new files should be loaded, e.g. after startup or SD Card change

Here is the call graph for this function:

s32 FILE_Copy | ( | char * | src_file,
|  | char * | dst_file |
| ) |  |  |

This function copies a file

Parameters:

  `[in]` | src_file | the source file which should be copied
  `[in]` | dst_file | the destination file

Here is the call graph for this function:

s32 FILE_DirExists | ( | char * | path | ) |

Returns 1 if directory exists, 0 if it doesn't exist, < 0 on errors

Here is the call graph for this function:

s32 FILE_FileExists | ( | char * | filepath | ) |

Returns 1 if file exists, 0 if it doesn't exist, < 0 on errors

Here is the call graph for this function:

s32 FILE_FindNextFile | ( | char * | path,
|  | char * | filename,
|  | char * | ext_filter,
|  | char * | next_filename |
| ) |  |  |

Returns a file next to the given filename with the given extension if filename == NULL, the first file will be returned in next_filename

Parameters:

  `[in]` | path | directory in which we want to search
  `[in]` | filename | current file (if NULL, the first file will be returned)
  `[in]` | ext_filter | optional extension filter (if NULL: no extension)
  `[out]` | next_filename | the next file if return status is 1

Returns:
  < 0 on errors (error codes are documented in file.h)
  1 if next file has been found
  0 if no additional file

Here is the call graph for this function:

s32 FILE_FindPreviousFile | ( | char * | path,
|  | char * | filename,
|  | char * | ext_filter,
|  | char * | prev_filename |
| ) |  |  |

Returns a previous file of the given filename with the given extension if filename == NULL, no first file will be returned in prev_filename

Parameters:

  `[in]` | path | directory in which we want to search
  `[in]` | filename | current file (if NULL, the last file will be returned)
  `[in]` | ext_filter | optional extension filter (if NULL: no extension)
  `[out]` | prev_filename | the previous file if return status is 1

Returns:
  < 0 on errors (error codes are documented in file.h)
  1 if previous file has been found
  0 if no additional file

Here is the call graph for this function:

s32 FILE_GetDirs | ( | char * | path,
|  | char * | dir_list,
|  | u8 | num_of_items,
|  | u8 | dir_offset |
| ) |  |  |

Here is the call graph for this function:

s32 FILE_GetFiles | ( | char * | path,
|  | char * | ext_filter,
|  | char * | file_list,
|  | u8 | num_of_items,
|  | u8 | file_offset |
| ) |  |  |

Here is the call graph for this function:

s32 FILE_Init | ( | u32 | mode | ) |

Initialisation

Here is the call graph for this function:

s32 FILE_MakeDir | ( | char * | path | ) |

Creates a directory

Here is the call graph for this function:

s32 FILE_PrintSDCardInfos | ( | void |  | ) |

This function prints some useful SD card informations on the MIOS terminal

Here is the call graph for this function:

s32 FILE_ReadBuffer | ( | u8 * | buffer,
|  | u32 | len |
| ) |  |  |

Read from file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_ReadBufferUnknownLen | ( | u8 * | buffer,
|  | u32 | len |
| ) |  |  |

Read from file with unknown size

Returns:
  < 0 on errors (error codes are documented in file.h)
  >= 0: value contains the actual read bytes

Here is the call graph for this function:

s32 FILE_ReadByte | ( | u8 * | byte | ) |

Read a 8bit value from file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_ReadClose | ( | file_t * | file | ) |

Closes a file which has been read File can be re-opened if required thereafter w/o performance issues

Returns:
  < 0 on errors (error codes are documented in file.h)

u32 FILE_ReadGetCurrentPosition | ( | void |  | ) |

Returns current file pointer of the write file

u32 FILE_ReadGetCurrentSize | ( | void |  | ) |

Returns current size of write file

s32 FILE_ReadHWord | ( | u16 * | hword | ) |

Read a 16bit value from file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_ReadLine | ( | u8 * | buffer,
|  | u32 | max_len |
| ) |  |  |

Read a string (terminated with CR) from file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_ReadOpen | ( | file_t * | file,
|  | char * | filepath |
| ) |  |  |

opens a file for reading Note: to save memory, one a single file is allowed to be opened per time - always use FILE_ReadClose() before opening a new file! Use FILE_ReadReOpen() to continue reading

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_ReadReOpen | ( | file_t * | file | ) |

reopens a file for reading

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_ReadSeek | ( | u32 | offset | ) |

Changes to a new file position

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_ReadWord | ( | u32 * | word | ) |

Read a 32bit value from file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_Remove | ( | char * | path | ) |

Removes a file or directory

Here is the call graph for this function:

s32 FILE_SDCardAvailable | ( | void |  | ) |

Returns:
  1 if SD card available

s32 FILE_SendErrorMessage | ( | s32 | error_status | ) |

Send a verbose error message to MIOS terminal

s32 FILE_SendSyxDump | ( | char * | path,
|  | mios32_midi_port_t | port,
|  | u32 | ms_delay_between_dumps |
| ) |  |  |

This function sends a .syx file to given MIDI out port

Here is the call graph for this function:

s32 FILE_UpdateFreeBytes | ( | void |  | ) |

This function updates the number of free bytes by scanning the FAT for unused clusters.
should be called before FILE_Volume* bytes are read

Here is the call graph for this function:

s32 FILE_VolumeAvailable | ( | void |  | ) |

Returns:
  1 if volume available

u32 FILE_VolumeBytesFree | ( | void |  | ) |

Returns:
  number of available bytes

u32 FILE_VolumeBytesTotal | ( | void |  | ) |

Returns:
  total number of available bytes

u32 FILE_VolumeCluster2Sector | ( | u32 | cluster | ) |

Returns:
  the physical sector of the given cluster

char* FILE_VolumeLabel | ( | void |  | ) |

Returns:
  volume label

u32 FILE_VolumeSectorsPerCluster | ( | void |  | ) |

Returns:
  number of sectors per cluster

s32 FILE_WriteBuffer | ( | u8 * | buffer,
|  | u32 | len |
| ) |  |  |

Writes into a file with caching mechanism (actual write at end of sector) File has to be closed via FILE_WriteClose() after the last byte has been written

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_WriteByte | ( | u8 | byte | ) |

Writes a 8bit value into file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_WriteClose | ( | void |  | ) |

Closes a file by writing the last bytes

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

u32 FILE_WriteGetCurrentPosition | ( | void |  | ) |

Returns current file pointer of the write file

u32 FILE_WriteGetCurrentSize | ( | void |  | ) |

Returns current size of write file

s32 FILE_WriteHWord | ( | u16 | hword | ) |

Writes a 16bit value into file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_WriteOpen | ( | char * | filepath,
|  | u8 | create |
| ) |  |  |

Opens a file for writing

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_WriteSeek | ( | u32 | offset | ) |

Changes to a new file position

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

s32 FILE_WriteWord | ( | u32 | word | ) |

Writes a 32bit value into file

Returns:
  < 0 on errors (error codes are documented in file.h)

Here is the call graph for this function:

## Variable Documentation

u8 file_copy_percentage

u32 file_dfs_errno