The fopen function opens the file specified by filename. Any valid string is allowed for filename. The string size is limited to 32 characters including terminating null-character. However, choosing very long filenames decreases the overall Flash File System performance. The filename may contain a drive prefix which specifies the medium where the file should be opened. If the drive prefix is omitted the default drive specified in the FILE_CONFIG.C configuration file is used. The following drive prefixes are allowed: | Drive Prefix | Description |
|---|
| "F:" | Embedded Flash drive. | | "S:" | SPI Flash drive. | | "R:" | Ram drive. | | "M:" | Memory Card drive. |
The mode defines the type of access permitted for the file. It may have one of the following values. | Mode | Description |
|---|
| "r" | Opens a file for reading. If the file does not exist fopen fails. | | "w" | Opens an empty file for writing. If the file already exists, its contents are destroyed. If the file does not exist, an empty file is opened for writing. | | "a" | Opens a file for writing. If the file already exists, data is appended at the end of file. If the file does not exist, an empty file is opened for writing. |
For the M: drive, a filename must contain a path, othervise a file from the root folder will be referenced or created. To create a subfolder parameter filename must containg also a path. If the specified subfolder does not exist, the system will create one and then create a file in this subfolder. The fopen function is in the RL-FlashFS library. The prototype is defined in stdio.h. Note - The fopen function must be called to create a file handle before any other file functions are invoked.
- Use the "w" mode with care as it can destroy existing files.
- Read/write modes are currently not supported.
- You cannot open more than one file stream for writing to the same filename. If filename is open for writing, subsequent calls to fopen for writing to filename fail until you close filename using the fclose function.
|