Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


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

Posted by sonycman on June 5, 2017


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

Posted by heinbali01 on June 6, 2017

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

Posted by sonycman on June 6, 2017

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

Posted by heinbali01 on June 6, 2017

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. */
    /* 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. */ int32t FFGetFileSize( FFFILE *pFile, uint32t *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

Posted by sonycman on June 7, 2017

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

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists