eclipse-threadx/filex

searching in directory fails when cluster too small

Closed this issue · 7 comments

I am formatting my media with:

                status = fx_media_format(&ram_disk,
                _fx_ram_driver,               // Driver entry
                ram_disk_memory,              // RAM disk memory pointer
                media_memory,                 // Media buffer pointer
                sizeof(media_memory),         // Media buffer size
                "MY_RAM_DISK",                // Volume Name
                1,                            // Number of FATs
                16,                           // Directory Entries
                0,                            // Hidden sectors
                2000,                          // Total sectors
                80,                          // Sector size
                1,                            // Sectors per cluster
                1,                            // Heads
                1);                           // Sectors per track

I succeed format and create directory/file in the root directory. also creation of file inside the subdirectory succeed, but opening this file fails with FX_NOT_FOUND.

changing sector size to 100 or changing Sectors per cluster to 2 solves the issue. changing sector size into 64 makes the file creation fails with status FX_SECTOR_INVALID

attached example file based on yours example.demo_filex.txt

I am using the general port.

system vars: 1: FFFF0607, 2: 1008010, 3: A03E8

Could you set the sector size to 512 which is a typical value for SD disk?

Well, it is not the case of my HW so I don't want to use such sector size.
I understand we really have here a bug with little sectors?

We didn't verify such little value. From both FAT and exFAT spec, the value of bytes per sector must be expressed as log2(N). Valid values range from 512 to 4096. Could you give more details of your hardware?

currently I can't give more details on my HW and I don't understand which details you need more (this is unique HW).

Can't I assume even that let say sector size of 64 bytes and two sectors per cluster will work good anytime? (currently it looks like working good, you can change the values in the test file I attached beforehand and see).

In your code it looks like each value between 1-4K is OK
https://github.com/azure-rtos/filex/blob/0882b60072f458d9e8ed277d77cacf3d2a4f5eea/common/src/fx_media_format.c#L138-L140

by the way, I don't know from where you taking the spec, but according wikipedia:

The minimum allowed value for non-bootable FAT12/FAT16 volumes with up to 65535 logical sectors is 32 bytes, or 64 bytes for more than 65535 logical sectors

Floppy drives and controllers use physical sector sizes of 128, 256, 512 and 1024 bytes (e.g., PC/AX).

Thanks for pointing this out! We will improve the user guide to clarify the limitation on the value of bytes_per_sector.