2020-06-05 07:11 AM
Dear all,
I'm using the FatFS generated by STM32CubeMX and I have one question about file size:
I'm using f_stat functionand read the file size from fsize field of FILINFO structure; when I open a file I can read the file size from obj.objsize field of FIL structure.
I have seen that the value is calculate differently but the value it's the same.
Is it possible to use the FIL structure field or is it recommended to use the FILEINFO field because in some cases the value may not be correct?
Thanks in advance.
Luca G.
Solved! Go to Solution.
2020-06-05 08:02 AM
> the value is calculate differently
Both of them contains the value of the file size field in the directory entry. There is no ther way to calculate it (I'm not sure about exFat).
> Is it possible to use the FIL structure field or is it recommended to use the FILEINFO field
fp->obj is an internal structure which might change in a future version.
Use f_size() if you open the file anyway, it is the most efficient and documented way as long as the file is open. It is the same as fp->obj.objsize, but it is documented, so you can expect that this interface remains stable in the future.
Use f_stat() if you need the information before opening the file.
2020-06-05 08:02 AM
> the value is calculate differently
Both of them contains the value of the file size field in the directory entry. There is no ther way to calculate it (I'm not sure about exFat).
> Is it possible to use the FIL structure field or is it recommended to use the FILEINFO field
fp->obj is an internal structure which might change in a future version.
Use f_size() if you open the file anyway, it is the most efficient and documented way as long as the file is open. It is the same as fp->obj.objsize, but it is documented, so you can expect that this interface remains stable in the future.
Use f_stat() if you need the information before opening the file.
2020-06-05 08:42 AM
Always used f_size() on an open file since the function/macro was available.
Secondarily used bytes read from f_read() to determine if end of file occurred prematurely.
2020-06-05 09:27 AM
Many thanks for the clarifications.
Regards.