There are several limitations that is part of the FAT file system that cannot be altered without breaking compatability with FAT. There is also the issue that long file name entries take up more space than short filename entries. On a file system with short file names only, each file or directory takes up 1 entry. With long file name support, it depends on the length of the filename but it takes around 2 + (strlen(filename)/5).
For the root directory of a FAT12 or FAT16 file system, the limit depends on what was decided when the device was formatted. It is often safe to assume that you may store up to 128 entries.
For the root directory of a FAT32 file system or any other directory on FAT12, FAT16 or FAT32 you can store up to around 65533 entries.
For a file system without long name support, this means that you in theory can have up to around 65533 files and directories within a directory.
For a file system with long name support, it is harder to calculate but if you use filenames of a length between 15-20 characters you can store around 10000 files and directories.
However, we strongly advise against storing that many files in a single directory. The FAT file system stores files as a single list that has to be traversed to find the file which become very slow unless you have a big cache. Instead store your data in subdirectories and aim to keep around 10-200 entries in each directory.
If you are storing one log file per day you might store them in subdirectories based on dates:
/
/logs/
/logs/2012/10/
/logs/2012/11/
/logs/2012/12/
/logs/2013/01/
/logs/2013/02/
If you are storing data you may want to use some prefix of the file to create a directory structure:
/
/sensordata/
/sensordata/13/
/sensordata/13/13344.dat
/sensordata/13/13812.dat
/sensordata/43/
/sensordata/43/43928.dat
/sensordata/59/
/sensordata/59/59728.dat
Direktlänk hit