User`s manual

154 digi.com File Systems
10.2.4 FAT Operations
There are some basic groups of operations involved in using the Dynamic C FAT library. These are
described at length in the following sections.
Section 10.2.4.1 “Format and Partition the Device”
Default Partitioning
Creating Multiple FAT Partitions
Preserving Existing Partitions
Section 10.2.4.2 “File and Directory Operations”
Open and Close Operations
Read and Write Operations
Going to a Specified Position in a File
Creating Files and Subdirectories
Reading Directories
Deleting Files and Directories
10.2.4.1 Format and Partition the Device
The flash device must be formatted before its first use. Formatting it after its first use may destroy infor-
mation previously placed on it.
10.2.4.1.1 Default Partitioning
As a convenience, Samples/FileSystem/Fmt_Device.c is provided to format the flash device.
This program can format individual FAT 12/16 partitions, or can format all FAT 12/16 partitions found on
a device. If no FAT 12/16 partitions are found, it offers the option of erasing the entire device and format-
ting it with a single FAT 16 partition. Be aware that this will destroy any data on the device, including that
contained on FAT 32 partitions. This is an easy way to format new media that may contain an empty
FAT32 partition spanning the entire device, such as a new SD or XD card.
After the device has been formatted with Fmt_Device.c, an application that wants to use the FAT file
system just has to call the function fat_Init() (replaced in FAT version 2.01) or
fat_AutoMount(). If you are calling fat_AutoMount() refer to Section 10.2.2.1 for an example
of its use. Note that if you call fat_AutoMount() using the configuration flag FDDF_DEV_FORMAT,
you may not need to run Fmt_Device.c.
10.2.4.1.2 Creating Multiple Partitions
To create multiple partitions on the flash device use the sample program FAT_Write_MBR.c, which will
allow you to easily create as many as four partitions. This program does require that the device be “erased”
before being run. This can be done with the appropriate sample program: sdflash_inspect.c,
sflash_inspect.c or nflash_inspect.c. You only need to clear the first three pages on SD
cards or serial flash, or the first page on NAND flash or XD cards. Once this is done, run
FAT_Write_MBR and it will display the total size of the device in MegaBytes and allow you to specify the
size of each partition until all the space is used. If you specify an amount larger than the space remaining,
then all remaining space will be used for that partition. Once all space is specified, it will ask approval to
write the new partition structure. This utility does not format the partitions, it merely creates their defini-
tions. Run Fmt_device.c afterwards and use the 0 or 1 option to format the full device and all parti-