Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

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

Posted by sonycman on June 5, 2017

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

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. */
}
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. */ 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

Attachments


+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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner