eclipse-threadx / filex

Eclipse ThreadX - FileX is a high-performance, FAT-compatible file system that’s fully integrated with Eclipse ThreadX RTOS
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/filex/index.md
MIT License
27 stars 22 forks source link

Incompatibility when using large capacity disks (4T SSD) #12

Open lisc5324 opened 2 years ago

lisc5324 commented 2 years ago

I use the GPT partition tool to partition the disk and format the file system with exFAT. Use Filex (no system mode) on the zynq xc7z045(ARM Cortex-A9 32bit) development board. An error is always reported. Such as a function _fx_utility_logical_sector_read:

图片

Has anyone patched it.

nflandin commented 1 month ago

This does appear to be a bug due to an overflow, as ULONG max is 4294967295, which would correspond to 21990023255040 bytes if there was a 512-byte sector size. I am not sure why fx_media_total_sectors (a ULONG64) is cast to ULONG, as there is no comment explaining it; perhaps this was done to speed up the comparison. I suspect this was a simple mistake, as fx_media_total_sectors is cast to ULONG64 in a number of other places, and is not cast at all when the exact same comparison is made in fx_utility_sector_write (lines 318 & 388).

The simplest solution (and the one I believe to be best) for this would be to simply eliminate the cast. Another solution (to allow for large drives without unnecessarily compromising performance for smaller media) would be to allow a ULONG64 comparison when exFAT is enabled:

`#ifdef FX_ENABLE_EXFAT

    if ((logical_sector + sectors - 1) > media_ptr -> fx_media_total_sectors)

else

    if ((logical_sector + sectors - 1) > (ULONG)media_ptr -> fx_media_total_sectors)

endif`

A workaround would be to increase sector size, and the exFAT max of 4096 bytes/sector would result in a 17592186040320 byte limit. The issue with this is that it limits you to what are basically FAT32 partitions.