This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FATFS and long file name

Other Parts Discussed in Thread: SYSBIOS

Does the version of FATFS that SYS/BIOS has in it support long file name? i tried to define "_USE_LFN" but i think i would have to rebuild sys bios for that....is that correct?

also, when i try to do an fopen("file.bla", "r") it seems it requires me to add the "fat:1:" prefix to the file. otherwise it wont let me open it. is there a reason for this when i am trying to open a file in the root directory?

  • Hi cobsonchael,

    cobsonchael said:
    Does the version of FATFS that SYS/BIOS has in it support long file name? i tried to define "_USE_LFN" but i think i would have to rebuild sys bios for that....is that correct?

    Long filename support is included with the 3rd party module but we do not test for its functionality with our regression tests.

    cobsonchael said:
    also, when i try to do an fopen("file.bla", "r") it seems it requires me to add the "fat:1:" prefix to the file. otherwise it wont let me open it. is there a reason for this when i am trying to open a file in the root directory?

    Yes, there is a reason for it. fopen is part of the C standard I/O routine which calls a FatFs API. The C standard I/O library is registered at runtime to the FatFs APIs which is done for you in the FatFS module (FatFS.xdt). The way the C I/O library extracts the "fat:" prefix in the fopen("fat:1:filename", ...) call to determine which hook functions are to be called (ffcio.c). This prefix can also changed but not removed in the FatFS module.

    FatFS.fatfsPrefix = "yourOwnPrefix";

    The remaining string is then passed on to the FatFs API to parse (e.g. f_open("1:filename,)). The FatFs API also parses this prefix to determine which drive it is supposed to access. Here you would include a digit [0-9] followed by a ":". If the string isn't formatted properly, it will assume drive number 0.

    See this User's Guide at section 8.2.

  • so how do i enable long file name?

  • Hi Cobsonchael,

    ffconf.h in 'ti/sysbios/fatfs' has a few options to enable long file name support.

    The easiest option is to define _USE_LFN to 2. This will place the long file name buffer on your (task) stack keeping it re-entrant. If you don't want to keep this buffer in your stack, you can set _USE_LFN to 3, which gets the buffer from the heap by calling ff_memalloc and ff_memfree (which are both included in memsysbios.c)

    After you change ffconf.h you need to rebuild SYS/BIOS (more specifically, the FatFS module). I'm not sure which version of SYS/BIOS you are using and whether or not your using it with another product (e.g. BIOS PSP) However, in any case there should be a SYS/BIOS User's Guide that explains how to rebuild SYS/BIOS (The latest version can be found here: spruex3k.pdf).

    If you have SYS/BIOS v6.32 or newer you can use LibType_Custom which will create the libraries for you.

    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    BIOS.libType = BIOS.LibType_Custom;

  • so what i am understanding is that long file name is not supported by default and that for EVERY SINGLE SYSBIOS version i update to i have to make this change for this to work?

    i tried changing the file and making my .cfg file to use "custom" but that didn't do anything. it is still defined as 0 as far as the system is concerned. i am using SYSBIOS 6.33.07.53. so it looks like i have to manually compile the library.

    why is this not an option in the SYSBIOS FATFS portion? 

    i would suggest defining the _USE_LFN = 2 by default because, seriously, who is using this thing and limiting the file names to only 8 chars? this isn't 1989.

  • ok so i was able to rebuild SYSBIOS with the LFN define set to 2

    there are 3 issues i see after that

    1) after i did that i had to come up with 2 functions that controlled the conversion from one file name to another or something to that effect.  ff_convert and ff_wtoupper.  i figured out how to make those (there is no support for this by the way) by downloading the collection of FATFS examples from the website http://elm-chan.org/fsw/ff/00index_e.html i have no idea if those are right. i attached what i have i would like some kind of indication that this is what those functions should be (for american only)

    i can now open files with long file names and read them, though. which is nice

    2) in the FILINFO structure that gets filled in when you do a f_readdir still doesn't recognize the lfn variables.  there are errors that get posted when i compile.  the compile still happens and i get an .out file (which i didn't think you could do. why don't those fields show up when i build the library with _USE_LFN?). i can't use that data apparently....

    THIS LEADS ME #3

    3) i can no longer seem to use the f_readdir to sort through my file system. the long file names do not come out when i try to sort through the files and the whole thing is useless.  this is very important to our project that this functionality works. how do i use f_readdir when using lfn and be able to read the file names? i guess i can try long file name define of 3 or 1 tomorrow....

  • Cobsonchael,

    cobsonchael said:

    so what i am understanding is that long file name is not supported by default and that for EVERY SINGLE SYSBIOS version i update to i have to make this change for this to work?

    i tried changing the file and making my .cfg file to use "custom" but that didn't do anything. it is still defined as 0 as far as the system is concerned. i am using SYSBIOS 6.33.07.53. so it looks like i have to manually compile the library.

    I just looked into this a bit further. The FatFs API is a 3rd party application which wasn't designed as a RTSC module. So the short story is that we can't build the FatFS module with LibType_Custom without some internal hacks to the build flow. So, you are correct, the only option is to rebuild SYS/BIOS (gmake -f bios.mak)

    I opened a bug to track this feature enhancement (SDOCM00095699) so we can simply use LibType_Custom. When this feature has been implemented, it would make more sense to create some sort of configuration parameter to change items in ffconf.h as they would have to be rebuilt every time something is modified.

    cobsonchael said:
    i would suggest defining the _USE_LFN = 2 by default because, seriously, who is using this thing and limiting the file names to only 8 chars? this isn't 1989.

    There are 2 reasons to keep LFN disabled by default:

    1. SYS/BIOS is also used with micro controllers will very limited resources (MSP430 and Stellaris M3/M4F's and etc..) and to avoid extra code and ram usage LFN support is kept off by default.

    2. Patent infringement is still an issue today. Before jumping to conclusions, take a look at the FatFs developer's Application Note. He states that you might be required to get a license from Microsoft if you want to use LFN in a commercial product. LFN is kept disabled to avoid this licensing requirement.

  • Cobsonchael,

    This looks like FatFs specific issue for which I'm not familiar with. Have you checked with the FatFs forum?

  • thanks for creating a bug report for this. that will make it at least a little easier to handle

    is it possible, within the cfg file, to make a section in the FATFS to change these settings, but then require a custom library type? like when custom library type was enabled all these FATFS features with then become available. that would solve some headaches i think.

    apparently the issue i was having with the f_readdir went away after i rebooted CCS. apparently the program didn't update a symbol inside itself and was prevent things from being compiled without errors. also, i changed my ff_convert to apply to the default settings in FATFS which is the japanese, not english which seems to make things better as well. i am attaching the file for future individuals who might be looking for this thing as well.

  • hello

    long file name should not be enabled, short the file name

    using _long..path_tool.