How many letters is filesystem's filename allowed?

Hi
I am developing Texas Instruments AM6442 with TI SDK using FreeRTOS.
Now, I’m testing create file in uSD using FreeRTOS filesystem API.
I’m glad if you let me answer this question.
Question1. I’m using ff_fopen(). when created file format is FAT16, FAT32, or else?

Question2. In ff_open(), I want to set filename over 9 letters. Is this allowed?
In my debugging, Created fileneme was broking.
image

Thanks,
GR

Hi GR, thank you for contacting us.

Do you have a FreeRTOS+FAT driver for your AM6442? Where did you find it?

When the driver mounts a disk partition, it will detect the type of FAT: 12, 16, or 32.

Note that ffconfigFAT12_SUPPORT is defined as 0 by default, thus FAT12 will not be supported unless you define ffconfigFAT12_SUPPORT as 1 in your FreeRTOSFATConfig.h.

By default, ffconfigLFN_SUPPORT is defined as 0, meaning that Long File Names will not be supported, only 8.3 names.

I normally have the following settings in my FreeRTOSFATConfig.h:

#define ffconfigLFN_SUPPORT       1
#define ffconfigMAX_FILENAME    129
#define ffconfigFAT12_SUPPORT     0

This means that I can use long file- and directory names, which are up to 128 bytes long ( make sure the task has enough stack space ).

I also recommend to use the functions declared in ff_stdio.h because they are compatible with the functions used in stdio.h. That makes it easy to test your programs on a PC before running it in an MCU.

Here is an example of how to read the first sector of a file:

FF_FILE * pxHandle = ff_fopen( "/files/my_long_filename.txt", "r" );

if( pxHandle != NULL )
{
    char pcBuffer[ 512 ];
    size_t xResult = ff_fread( pcBuffer,
                               1U,  /* size */
                               sizeof( pcBuffer ), /* count */
                               pxHandle );
    if( xResult > 0 )
    {
        printf("Read %u bytes\n", xResult );
    }
    else
    {
        int iNumber = stdioGET_ERRNO();
        printf( "ff_fread failed with errno %d\n", iNumber );
    }
    ff_fclose( pxHandle );
}

I haven’t tested the above code.

stdioGET_ERRNO() returns a value which can be looked up in projdefs.h. They are more or less the same as errno on other systems.

Note that errno is simulated using local storage pointers. Therefor, the value of “errno” and the cwd (current working directory) are local for every task.

Please define the following in your copy of FreeRTOSConfig.h:

 /* FreeRTOS+FAT requires 4 pointers if a CWD is supported. */
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS	4

Hi htibosch,
Thank you to your information!

TI is providing in MCU PLUS SDK.
but now, using only FreeRTOS filesystem API.
Using with FreeRTOS is in my customer’s original software.

sdk user’s guid
sdk link

I was tested in your setting,

#define ffconfigFAT12_SUPPORT                (0U)
#define ffconfigLFN_SUPPORT                  (1U)
#define ffconfigMAX_FILENAME    129

and SD card was formated by my windows PC to FAT32.
However, as a result, filename was broken.

I think the probrem is related stack size.
So I will test change linker setting.

Best regards,
GR

The maximum filename length varies depending on the file system. For older Windows systems using the FAT file system, it is 11 characters. In modern Windows systems using NTFS or Unix-based systems like Linux, it is 255 characters.

zeinthpaul wrote:

In modern Windows systems using NTFS or Unix-based systems like Linux, it is 255 characters.

Sure, FAT with LFN also supports filenames with a length up to 255 characters.

But we added a configurable limit to the actual maximum length, in order to live with a small memory footprint.

In some places, a filename is declared on stack as:

char pcFileName[ ffconfigMAX_FILENAME ];

So if you have plenty of stack space, you can define ffconfigMAX_FILENAME as 256.

GR, good to hear that TI has included a driver for FreeRTOS+FAT in their SDK.

Do you have any logging from your system?

I use the following lines in my FreeFRTOFATConfig.h:

extern int lUDPLoggingPrintf( const char *apFmt, ... );

#define FF_PRINTF lUDPLoggingPrintf

so I get all sorts of logging about mounting the disk.

Also, if you want, can you show code that does the +FAT calls? Initialisation, mounting, etc?