fatfs 学习笔记--f_open用法(转载)

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.

FlagsMeaning
FA_READSpecifies read access to the object. Data can be read from the file.
FA_WRITESpecifies write access to the object. Data can be written to the file. Combine with FA_READfor read-write access.
FA_OPEN_EXISTINGOpens the file. The function fails if the file is not existing. (Default)
FA_CREATE_NEWCreates a new file. The function fails with FR_EXIST if the file is existing.
FA_CREATE_ALWAYSCreates a new file. If the file is existing, it will be truncated and overwritten.
FA_OPEN_ALWAYSOpens the file if it is existing. If not, a new file will be created.
FA_OPEN_APPENDSame 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:

POSIXFatFs
"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"*1FA_CREATE_NEW | FA_WRITE
"x+"*1FA_CREATE_NEW | FA_WRITE | FA_READ

*1: glibc extension

Return Values

FR_OKFR_DISK_ERRFR_INT_ERRFR_NOT_READYFR_NO_FILEFR_NO_PATHFR_INVALID_NAMEFR_DENIEDFR_EXISTFR_INVALID_OBJECT,FR_WRITE_PROTECTEDFR_INVALID_DRIVEFR_NOT_ENABLEDFR_NO_FILESYSTEMFR_TIMEOUTFR_LOCKEDFR_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.

转载 https://blog.csdn.net/lbaihao/article/details/75143971

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值