Hi, I've changed some of MFS code and now things are working well.
I'm not sure if any of these changes may affect other functionalities, but I've already tested the rest of my application and things look fine.
I'm posting the changes here to help others and luckily for someone on NXP to check.
The problem is on the mfs_search.c file, more specifically in the MFS_Find_directory_entry function. I've found two bugs:
1. Even the filename being "invalid" for the 8.3 standard, the first search for-loop step considers the function passed attributes instead of looking for LFN entries. This is probably NOT the cause of my problem, but (correct me if I'm wrong) can cause a LFN entry to be missed. In order to fix it, I've the replaced the following lines in the beginning of the function:
/* We also need special treatement for a directory name */
if (attribute == (ATTR_EXCLUSIVE | MFS_ATTR_DIR_NAME))
{
attribute = MFS_ATTR_LFN;
dirname = 1;
}
by:
attribute = MFS_ATTR_LFN; /* added by LFS - 2016-07-20 */
Why? If the file or directory being searched has an invalid 8.3 name - we MUST find a LFN entry in order to find it - so that condition makes no sense.
The dirname var is originally used later to restore the dir search attributes, however the second problem (the root cause of the problem reported in this topic) solution makes it useless.
2. In the first search loop the attribute parm being searched is changed to the LFN pattern if the file being searched has invalid 8.3 name - but the original attribute being searched is NOT saved anywhere! As the attribute being passed to the function should be used in order to check the 8.3 entry pointed by the LFN entries, the function can't just discard it! Explaining it better - when looking for a dirname which qualifies as LFN, the following steps were being executed:
1. The attribute passed by the function call is being replaced by the LFN pattern in the firstentry that didn't match what we are looking for - after that only LFN entries are being checked - according to the following lines
if (MFS_Attribute_match(mqx_dtohc(dir_entry_ptr->ATTRIBUTE),
attribute) == true)
{
... /*checking code here */
} else
{
if (lfn_flag)
{
attribute = MFS_ATTR_LFN;
lfn_ptr = file_ptr + lfn_len; /* reset ptr */
maybe = true;
found_lfn = false;
}
}
2. The function finds the LFN entry matching the name being searched (fine) and marks the flag to check the next entry for 8.3 matching in the next loop (found_lfn). Notice that the attribute value is not being reverted to the attributes being searched - it keeps the LFN bits marked - except when the attribute was being restored to a dir search - and this happens if, and only if, the function call was looking ONLY for dirs (dirname set to 1 on function beginning only if attribute == (ATTR_EXCLUSIVE | MFS_ATTR_DIR_NAME)). This is not the case when looking for dirs or files (usual search).
if (lfn_ptr == file_ptr)
{
found_lfn = true;
if (dirname)
{
attribute = ATTR_EXCLUSIVE | MFS_ATTR_DIR_NAME;
}
}
3. After that the next entry is the 8.3 entry corresponding to the search (not LFN) - but as it is searching for LFN attribute entries only, the file entry was never being found! The following condition never holds in the loop beginning:
if (MFS_Attribute_match(mqx_dtohc(dir_entry_ptr->ATTRIBUTE),
attribute) == true)
So, for error 2, what have I changed (the changed file is attached):
1. On function beginning I save the attribute parameter to a var (original_attribute):
unsigned char original_attribute = attribute;
2. If we are looking for a LFN entry, the attribute being searched is set to MFS_ATTR_LFN (as described in the fix for problem 1)
3. When the LFN name is found (in one or more entries), I revert the attribute back to the original function call:
if (lfn_ptr == file_ptr)
{
found_lfn = true;
// if (dirname)
// {
// attribute = ATTR_EXCLUSIVE | MFS_ATTR_DIR_NAME;
// }
attribute = original_attribute;
}
4. I've also removed the dirname var (as it is useless now).
If in the next loop step the file attributes don't match the ones being searched - it is reverted back to MFS_ATTR_LFN and the search continues.
The corrected mfs_search.c file is attached - I'll be grateful if any of you with knowledge about FAT32 can have a look. I've spotted some other coding bad practices, but didn't change them in order to avoid inserting any bug.
After these changes my FTPSRV is working like a charm.
Thanks
Luiz Fernando
p.s.: I'm still waiting for answers about the MQX 4.2.0.2 patch posted in the original topic