User`s manual

166 digi.com File Systems
The FAT type (FAT12 or FAT16) is determined by the count of clusters on the partition. The “12” and “16”
refer to the number of bits used to hold the cluster number. The FAT type is calculated using information
found in the BPB. Information from a BPB on a mounted partition is stored in the partition structure (of
type fat_part) populated by fat_AutoMount().
Partitions greater than or equal to 2 MB will be FAT16. Smaller partitions will be FAT12. To save code
space, you can compile out support for either FAT type. Find the lines
#define FAT_FAT12 // comment out to disable FAT12 support
#define FAT_FAT16 // comment out to disable FAT16 support
in LIB/../FAT.LIB, make your change, and then recompile your application.
10.2.5.3.2 FAT
The file allocation table is the structure that gives the FAT file system its name. The FAT stores informa-
tion about cluster assignments. A cluster is either assigned to a file, is available for use, or is marked as
bad. A second copy of the FAT immediately follows the first.
10.2.5.3.3 Root Directory
The root directory has a predefined location and size. It has 512 entries of 32 bytes each. An entry in the
root directory is either empty or contains a file or subdirectory name (in 8.3 format), file size, date and
time of last revision and the starting cluster number for the file or subdirectory.
10.2.5.3.4 Data Area
The data area takes up most of the partition. It contains file data and subdirectories. Note that the data area
of a partition must, by convention, start at cluster 2.
10.2.5.3.5 Creating Multiple FAT Partitions
FAT version 2.13 introduces FAT_Write_MBR.c, a utility that simplifies the creation of multiple parti-
tions. It is distributed with FAT version 2.13. It is also compatible with FAT versions 2.01, 2.05 and 2.10. If
you have one of these earlier versions of the FAT and would like a copy of FAT_Write_MBR.c, please
contact Technical Support at www.digi.com/support/. See Section 10.2.4.1.2 for information on
running this utility.
Without the use of FAT_Write_MBR.c, creating multiple FAT partitions on the flash device requires a
little more effort than the default partitioning. If the flash device does not contain an MBR, i.e., the device
is not formatted, both fat_Init() and fat_AutoMount() return an error code (-EUNFORMAT)
indicating this fact. So the next task is to write the MBR to the device. This is done with a call to
fat_FormatDevice(). Since we want more than one partition on the flash device,
fat_FormatDevice() must be called with a mode parameter of zero.
Before calling fat_FormatDevice(), partition specific information must be set in the mbr_part
entries for each partition you are creating. The following code shows possible information for partition 0
where MY_PARTITION_SIZE is equal to the size of the desired partition in bytes, 512 is the flash sector
size, and dev points to the mbr_part structure.