FreeRTOS+FAT: sector size smaller than 512 possible?

Hello,

we are currently evaluating the use of FreeRTOS+FAT as a file system for an application where very small files, i.e. between 16 and 256 bytes, are stored in an EEPROM memory.

Since the memory is very limited and the files are very small, if the usual sector size is 512 bytes, the memory would be wasted in an unacceptable way. So my first question is: Can FreeRTOS+FAT work with a sector size smaller than 512 bytes, say 64 bytes?

I assume for my question that FreeRTOS+FAT always stores only one file and not multiple files in one sector. So, if I want to store two 100 byte files, two separate 512 sectors will be occupied instead of just one sector, which would waste memory. Is this correct?

Our total memory is 56 KBytes. The intention is to divide it into partitions of 8 KBytes. So my second question is: Can FreeRTOS+FAT handle such small memory sizes?

Thank you.

The FAT file system itself has assumptions about a minimum sector size, and is only really define for sectors that are powers of two, and at least 512.

My question in your case is do you really need a “file system” or are you just storing a fixed number of fixed size data chunks? A “File System” may be what you are used to thinking of from experience with big machines, but small stores often use a simpler filing method.

A second issue is what is the sector size of the flash itself (what is the smallest block that you can erase at a time). Making a file system try to use a memory with a smaller logical allocation unit than its physical erase size gets complicated.

We want to store, delete and modify a variable number of data chunks of variable size between 16 and 256 bytes. The chunks are to be addressed by unique identifiers and be randomly accessible. Thus, the behavior is roughly equivalent to that of a file system, including the issue of memory fragmentation.

The underlying storage medium is not Flash, but EEPROM. This allows byte-wise reading and writing. To answer your question, the smallest sector size that can be read or written at once is 1 byte.

Can you confirm my assumption that in FAT only one file is ever stored in a single sector and not multiple files?

An 8 kByte memory partition likely is too small to create a FAT system due to the overhead of the FAT system (things like the Boot Record, FAT tables, and the Root Directory.

A FAT file can only store a single file with a sector, and in fact, within a “Allocation Cluster” which may be multiple sectors (a power of 2) in length.

From your description, I would just use an ad-hoc structure with minimal overhead, and not a structured system like FAT. The biggest design question becomes do you make it somewhat block oriented to avoid fragmentation issues, or just make it a heap and accept the dangers of fragmentation.

1 Like

Have you looked at littlefs?