eclipse-threadx/filex

Turn on fault tolerance, error reading folder information

Closed this issue · 9 comments

Hello there:
I enabled the fault-tolerant function. Reading and writing files is normal, but there is a problem when searching for folders. Only files are created and there is no problem with searching; but when creating folders, garbled data will be read out, using fx_directory_next_entry_find and fx_directory_next_full_entry_find

Hi, could you provide the steps or sample code to reproduce the issue?

uint8_t get_directory_file_and_folder_total_num(sDIRECTORY_INFO_DATA *info)
{
uint8_t status;
uint8_t tmp_count = 0;
uint8_t tmp_num = 0;
char entry[FX_MAX_LONG_NAME_LEN];

printf("set path = %s\r\n", info->name);
status = fx_directory_default_set(&nand_disk, (char *)info->name);
if (status != FX_SUCCESS)
{
printf("fx directory default set error, status = %02x\r\n", status);
}

while (1)
{
tmp_count++;
if (tmp_count >= 20)
{
break;
}

status = fx_directory_next_entry_find(&nand_disk, entry);
if (status == FX_SUCCESS)
{
tmp_num++;
printf("%d - %s\r\n", tmp_num, entry);
}
else
{
printf("entry_find error = %02x\r\n", status);
break;
}

}

info->files_and_folder_num = tmp_num;
return tmp_num;
}

Thanks! Do you have the directory tree of the file system?

status = fx_file_create(nand_disk, "demo.txt");
if (status != FX_SUCCESS)
{
	filex_printf("file create fail, status = %d\r\n", status);
}

filex_printf("create demo.txt ok, status = %d\r\n", status);

status = fx_file_create(nand_disk, "abc.txt");
if (status != FX_SUCCESS)
{
	filex_printf("file create fail, status = %d\r\n", status);
}
filex_printf("create abc.txt ok, status = %d\r\n", status);

status = fx_directory_create(nand_disk, "hhh");
if (status != FX_SUCCESS)
{
	filex_printf("directory create fail, status = %d\r\n", status);
}
filex_printf("create hhh ok, status = %d\r\n", status);

status = fx_directory_create(nand_disk, "test");
if (status != FX_SUCCESS)
{
	filex_printf("directory create fail, status = %d\r\n", status);
}
filex_printf("create hhh ok, status = %d\r\n", status);


status = fx_file_create(nand_disk, "hhh/1.txt");
if (status != FX_SUCCESS)
{
	filex_printf("file create fail, status = %d\r\n", status);
}
filex_printf("create hhh\\1.txt ok, status = %d\r\n", status);


status = fx_file_create(nand_disk, "test/1.txt");
if (status != FX_SUCCESS)
{
	filex_printf("file create fail, status = %d\r\n", status);
}
filex_printf("create test\\1.txt, status = %d\r\n", status);


status = fx_file_create(nand_disk, "test/2.txt");
if (status != FX_SUCCESS)
{
	filex_printf("create test\\2.txt, status = %d\r\n", status);
}
filex_printf("create test\\2.txt ok, status = %d\r\n", status);


status = fx_directory_create(nand_disk, "test/test1");
if (status != FX_SUCCESS)
{
	filex_printf("create test\\test1 fail, status = %d\r\n", status);
}
filex_printf("create test\\test1 ok, status = %d\r\n", status);


status = fx_file_create(nand_disk, "test/test1/1.txt");
if (status != FX_SUCCESS)
{
	filex_printf("create test\\test1\\1.txt fail, status = %d\r\n", status);
}
filex_printf("create test\\test1\\1.txt ok, status = %d\r\n", status);

status = fx_media_flush(nand_disk);
if (status != FX_SUCCESS)
{
	filex_printf("file flush fail, status = %d\r\n", status);
}
filex_printf("file flush ok, status = %d\r\n", status);

Yesterday I found that it is OK in the same thread, but it does not work if it is divided into two threads. The stacks of the two threads are the same size, and the stack overflow is not checked. No other threads are running. I am using freertos. Try to print nand disk to see if this has changed

No optimization options are turned on, use MDK development environment

Did you mean you are running FileX standalone mode with FreeRTOS? If FX_STANDALONE_ENABLE is defined, FX_SINGLE_THREAD will be enabled automatically and thus only one thread can access FileX. If you are using FileX on multiple threads, then mutex is required for all FileX APIs. If you didn't define FX_STANDALONE_ENABLE, then define FX_PROTECT to mutex related service from FreeRTOS to protect all FileX APIs. See https://github.com/azure-rtos/filex/blob/0882b60072f458d9e8ed277d77cacf3d2a4f5eea/ports/generic/inc/fx_port.h#L125.

We define FX_STANDALONE_ENABLE, and also use the freertos mutex, and we initialize in one thread, and use it in another thread. There is no conflict or critical area access problems.

I saw this statement Yesterday I found that it is OK in the same thread, but it does not work if it is divided into two threads. and There is no conflict or critical area access problems.. I'm not sure if you have problems on two threads or you only need one thread?