+FAT ff_filelength() returns Error when file length is >2GB

Hello. The fffilelength() function incorrectly interprets big files (>2GB) length as error and returns zero. This is because it uses MSB of the length value returned by FFFileSize() as an error flag, which in case of the big files leads to misinterpretation of correct value as an erratic. Regards Vladimir.

+FAT ff_filelength() returns Error when file length is >2GB

Vladimir, this is indeed something to be finished: files longer than 2 GB. Throughout the library, signed 32-bit values are used to indicate the length, and negative values are interpreted as an error. lseek also has an intrinsic problem: ~~~ long lseek(int fd, long offset, int whence); ~~~ FreeRTOS+TCP is using the same syntax for ff_fseek(). The Posix varian is ok, if off_t is a 64-bit signed integer: ~~~ offt lseek(int fd, offt offset, int whence); ~~~ The +FAT library will not force people to include 64-bit arithmetic. Right now I have a 2 GB file ( -2,147,483,648 bytes 🙂 ) on an SD-card and I will test it. To be continued.

+FAT ff_filelength() returns Error when file length is >2GB

Hello, Hein Thanks for an explanation. I understand, that big files support is not so important for the embedded systems. Its not needed in my case too. But glad to hear such a support might be available one day in the future 🙂

+FAT ff_filelength() returns Error when file length is >2GB

All right, I made some minor changes: ff_filelength() will return correct values for files between 0 bytes and 4 GB. A return value of 0 can mean two things: the size is either 0, or the handle is invalid. ~~~ size_t uxLength;
/* Clear errno. */
stdioSET_ERRNO( 0 );
uxLength = ff_filelength( pxFile );

if( ( uxLength != 0 ) || ( stdioGET_ERRNO() == 0 ) )
{
    /* Length equals to uxLength. */
}
else
{
    /* Invalid handle. */
}
~~~ Also I introduced a new low-level function that splits up the result and the file length: ~~~ /* Use the following function in case files may get larger than 2 GB. */ int32_t FF_GetFileSize( FF_FILE *pFile, uint32_t *pulSize ); ~~~ And more importantly: FF_Seek() now works correctly with sizes and offsets larger than 2GB. Here below I attach 3 files, which are a copy of the ‘160919’ release along with mentioned changes. ~~~ fffile.c ffstdio.c include/ff_file.h ~~~ Hein Tibosch

+FAT ff_filelength() returns Error when file length is >2GB

Thanks a lot, Hein! This is the best support I have ever seen! My respects!