I am using the FreeRTOS+FAT driver for my data logger project. I would like to know if it is possible to get the filename if I have a handle to the file object
FF_FILE*. I have tried digging deep into the +FAT source code but couldn’t quite find a straightforward way to do this.
Not sure it is possible. Can you keep a mapping between the FF_FILE variable and the name of the file opened when that value was returned within your application code?
Ah damn, feels like something so simple but I’m sure there are complications that will come with doing that.
My backup option was to create a struct that wraps together a
FF_FILE item and the associated filename. I think I will just do this for now.
For anyone wondering why I need this, it is because I want to use the
ff_remove function which only takes a file name as an argument and not a handle to the file. So like Richard said, I am going to keep a mapping between the name and the handle so that I can delete the file when needed.
It would be possible to derive the original filename by reading the directory in which the file appears.
FF_FILE struct maintains two fields fir this:
ulDirCluster which is the cluster in which the directory can be found
usDirEntry the entry number within the directory
If I am not mistaken, the following code should do:
xError = FF_GetEntry( pxFile->pxIOManager, pxFile->usDirEntry, pxFile->ulDirCluster, &xDirEntry );
if( FF_isERR( xError ) == pdFALSE )
printf( "The name is stored in: %s\n", xDirEntry.pcFileName );
But as Richard noted, an easier ( and more compatible ) is to just remember the filename that belongs to the file handle. Up to you!