FATFS函数之——f_open & f_read
FATFS函数之——f_open & f_read FATFS函数之——f_open & f_read
刚开始使用f_read和f_write时发现read/write老是出错,仔细查看源码发现,原来f_open文件时需要指定open 方式,
这些个方式影响了后面的文件操作。 刚开始使用f_read和f_write时发现read/write老是出错,仔细查看源码发现,原来f_open文件时需要指定open 方式, 这些个方式影响了后面的文件操作。
f_open函数声明如下: f_open函数声明如下:
FRESULT f_open ( FIL* fp, /* [OUT] Pointer to the file object structure */ const TCHAR* path, /* [IN] File name */ BYTE mode /* [IN] Mode flags */ );参数详细说明如下: FRESULT f_open ( FIL* fp, /* [OUT] Pointer to the file object structure */ const TCHAR* path, /* [IN] File name */ BYTE mode /* [IN] Mode flags */ ); 参数详细说明如下:
fp:Pointer to the blank file object structure to be created.
path: Pointer to a 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 bya combination of following flags. fp:Pointer to the blank file object structure to be created. path: Pointer to a 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 bya combination of following flags.
path: Pointer to a 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 bya combination of following flags. fp:Pointer to the blank file object structure to be created. path: Pointer to a 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 bya combination of following flags.
flags如下: flags如下:
刚开始用的组合为FA_READ | FA_WRITE | FA_CREATE_ALWAYS,这样的话就读不出来数据,而换成FA_OPEN_ALWAYS就可以正常的读写了,且看FA_CREATE_ALWAYS最后一句: 刚开始用的组合为FA_READ | FA_WRITE | FA_CREATE_ALWAYS,这样的话就读不出来数据,而换成FA_OPEN_ALWAYS就可以正常的读写了,且看FA_CREATE_ALWAYS最后一句:
it will be truncated and overwritten,意思是如果文件存在,则覆盖,所以会读不出数据。 it will be truncated and overwritten,意思是如果文件存在,则覆盖,所以会读不出数据。
f_read函数声明如下: f_read函数声明如下:
FRESULT f_read ( FIL* fp, /* [IN] File object */ void* buff, /* [OUT] Buffer to store read data */ UINT btr, /* [IN] Number of bytes to read */ UINT* br /* [OUT] Number of bytes read */ );btr是用户要读的数据量,br是实际读取的数据量,这样当判断到br==0时,文件读完。
FRESULT f_read ( FIL* fp, /* [IN] File object */ void* buff, /* [OUT] Buffer to store read data */ UINT btr, /* [IN] Number of bytes to read */ UINT* br /* [OUT] Number of bytes read */ ); btr是用户要读的数据量,br是实际读取的数据量,这样当判断到br==0时,文件读完。
