f_open
The f_open function opens a file.
FRESULT f_open ( FIL* fp, /* [OUT] Pointer to the file object structure */ const TCHAR* path, /* [IN] File name */ BYTE mode /* [IN] Mode flags */ );
Parameters
fp
Pointer to the blank file object structure.
path
Pointer to the null-terminated string that specifies the file name to open or create.
mode
Mode flags that specifies the type of access and open method for the file. It is specified by a combination of following flags.
| Flags | Meaning |
|---|---|
| FA_READ | Specifies read access to the object. Data can be read from the file. |
| FA_WRITE | Specifies write access to the object. Data can be written to the file. Combine with FA_READfor read-write access. |
| FA_OPEN_EXISTING | Opens the file. The function fails if the file is not existing. (Default) |
| FA_CREATE_NEW | Creates a new file. The function fails with FR_EXIST if the file is existing. |
| FA_CREATE_ALWAYS | Creates a new file. If the file is existing, it will be truncated and overwritten. |
| FA_OPEN_ALWAYS | Opens the file if it is existing. If not, a new file will be created. |
| FA_OPEN_APPEND | Same as FA_OPEN_ALWAYS except the read/write pointer is set end of the file. |
Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:
| POSIX | FatFs |
|---|---|
| "r" | FA_READ |
| "r+" | FA_READ | FA_WRITE |
| "w" | FA_CREATE_ALWAYS | FA_WRITE |
| "w+" | FA_CREATE_ALWAYS | FA_WRITE | FA_READ |
| "a" | FA_OPEN_APPEND | FA_WRITE |
| "a+" | FA_OPEN_APPEND | FA_WRITE | FA_READ |
| "x"*1 | FA_CREATE_NEW | FA_WRITE |
| "x+"*1 | FA_CREATE_NEW | FA_WRITE | FA_READ |
*1: glibc extension
Return Values
FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_NOT_READY, FR_NO_FILE, FR_NO_PATH, FR_INVALID_NAME, FR_DENIED, FR_EXIST, FR_INVALID_OBJECT,FR_WRITE_PROTECTED, FR_INVALID_DRIVE, FR_NOT_ENABLED, FR_NO_FILESYSTEM, FR_TIMEOUT, FR_LOCKED, FR_NOT_ENOUGH_CORE,FR_TOO_MANY_OPEN_FILES
Description
The f_open function opens a file and creates a file object. The file object is used for subsequent read/write operations to the file to identify the file. Open file should be closed with f_close function after the session of the file access. If any change to the file is made and not closed prior to power down, media removal or re-mount, or the file can be collapsed.
If duplicated file open is needed, read here carefully. However duplicated open of a file with any write mode flag is always prohibited.
QuickInfo
Always available. Only FA_READ and FA_OPEN_EXISTING are supported when FF_FS_READONLY == 1.
本文详细介绍了f_open函数的使用方法,包括参数说明、返回值解释及如何通过不同标志位组合实现文件的不同打开方式,如读取、写入、创建等。
&spm=1001.2101.3001.5002&articleId=81451107&d=1&t=3&u=7de0b4e8902a499aa18b759cc24ffc4c)
1万+

被折叠的 条评论
为什么被折叠?



