
In this month’s Ask Larry column, I would like to touch upon the topic of FAT, and no, it doesn’t have anything to do with diets. I am talking about File Allocation Tables to be exact, and with the increased need of more storage, the FAT filing systems has become more important in today’s embedded systems. I have included two of the most common questions and answers that I think will cover some of the basics of the FAT filing system.
Dear Larry,
I’m using an SD card and I formatted on a Windows Vista PC. I then stored a file called “Mybigfileofstuff.backup”. My RCM4300 can’t see the file or the partition. Do you have any advice?
John L.
Hello John,
Windows Vista uses the NT file system or NTFS which the Rabbit will not be able to read. Plug the card into the Rabbit and format it with the FMT_DEVICE.C program in the C:\DCRABBIT_X.XX\Samples\Filesystem\FAT directory. The Rabbit will format the device using FAT16. Fortunately, both the Rabbit and Windows can read FAT16 so once you have formatted the SD card you should be able to move data back and forth very easily.
One thing to note is that FAT16 doesn't support long file names or extensions like "html" and "zhtml".
File names supported by FAT16:
- 12345678.abc
- Filename.txt
- Webpage1.htm
File names not supported by FAT16:
- 12345678.abcd
- Verylongfilename.longextension
- Webpage2.html
- Webpage3.zhtml
- Larry C.
Dear Larry,
I’m completely lost in trying to use the FAT library. Do you have any examples that can help get me started?
Paul M.
Hello Paul,
Take a look at the FAT_SHELL.C program in the C:\DCRABBIT_X.XX\Samples\Filesystem\FAT directory. It provides a decent example of how most of the FAT functions work. There are some general rules when working with FAT that you need to keep in mind:
Listen to the FAT functions Luke!
When you call a function from the FAT library, it will provide you with a return value that indicates whether the function was successful. You should check that value and print an error if the function didn’t work.
When you call a function from the FAT library, it will provide you with a return value that indicates whether the function was successful. You should check that value and print an error if the function didn’t work.
rc = fat_AutoMount(FDDF_MOUNT_DEV_ALL | FDDF_MOUNT_PART_ALL);
if (rc)
{
//BIG ERROR MESSAGE HERE!!
printf("\nFAT AutoMount ERROR!! (%d)\n", rc);
}
Handy Tip: You will find a description of all the generic error codes in the ERRNO.LIB file.
Directories and Files are equally protected under the law
A file in the FAT filesystem uses a FAT file data structure for all the bookkeeping. What isn’t immediately obvious is that a directory also uses the same data structure. Treat a directory much like you would a file and you should be ok.
What goes up must come down
When you use the FAT library it is important that what you close your files and unmount the filesystem when you are done. Your program should follow roughly these steps:
- Mount the FAT partition
- Open or create a file or directory
- Do something to the file or directory
- Close the file or directory
- Unmount the FAT partition
Notice how it is important to unmount the partition? That ensures that when you have finished writing, the FAT cache is actually written to the flash memory. The cache is used to minimize the number of writes to flash and because flash has a limited number of writes. If you don’t unmount the partition, you can’t guarantee that you have cleaned out your cache and you might lose data.
If you follow these basic guidelines and look over the samples your Rabbit should be FAT and happy in no time!
- Larry C.
Larry Cicchinelli is Rabbit’s Technical Support Manager. He has 30 years of embedded experience, and is considered one of the foremost authorities on Rabbit products. Larry and his staff offer comprehensive technical support to Rabbit customers.
Submit your questions for Larry via email at
AskLarry@rabbit.com
Read more Ask Larry Answers